1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.store

File TransactionExceptionTest.java

 

Code metrics

0
23
8
1
123
86
8
0.35
2.88
8
1

Classes

Class Line # Actions
TransactionExceptionTest 33 23 0% 8 0
1.0100%
 

Contributing tests

This file is covered by 3 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.store;
21   
22    import java.util.ArrayList;
23   
24    import org.junit.Assert;
25    import org.junit.Test;
26   
27    /**
28    * Tests for TransactionException
29    *
30    * @version $Id: 17f05d4e96b2db2f470e862a35de57c35185c7cd $
31    * @since 3.0M2
32    */
 
33    public class TransactionExceptionTest
34    {
35    private static final String SIMPLE_TEST_OUT =
36    "Caused by:\n"
37    + "java.lang.Exception\n"
38    + "\t" + "One exception.\n"
39    + "java.lang.RuntimeException\n"
40    + "\t" + "Number 2\n"
41    + "java.lang.OutOfMemoryError\n"
42    + "\t" + "Ut oh\n";
43   
44    private static final String COMPOUND_TEST_OUT =
45    "Caused by:\n"
46    + "java.lang.Exception\n"
47    + "\t" + "something bad happened.\n"
48    + "org.xwiki.store.TransactionException\n"
49    + "\t" + "Caused by:\n"
50    + "\t" + "java.lang.Exception\n"
51    + "\t" + "\t" + "One exception.\n"
52    + "\t" + "java.lang.RuntimeException\n"
53    + "\t" + "\t" + "Number 2\n"
54    + "\t" + "java.lang.OutOfMemoryError\n"
55    + "\t" + "\t" + "Ut oh\n"
56    + "\t" + "\n"
57    + "java.lang.Error\n"
58    + "\t" + "SEGFAULT!\n";
59   
60    private static final String NONRECOVERABLE_TEST_OUT =
61    "Caused by:\n"
62    + "java.lang.Exception\n"
63    + "\t" + "something bad happened.\n"
64    + "org.xwiki.store.TransactionException\n"
65    + "\t" + "This means there is db corruption\n"
66    + "\t" + "Caused by:\n"
67    + "\t" + "java.lang.Error\n"
68    + "\t" + "\t" + "Corruption!!\n"
69    + "\t" + "\n"
70    + "java.lang.Error\n"
71    + "\t" + "SEGFAULT!\n";
72   
73    /**
74    * Make sure the messages from the underlying throwables are preserved.
75    */
 
76  1 toggle @Test
77    public void simpleExceptionTest()
78    {
79  1 TransactionException te = this.getException();
80  1 Assert.assertFalse(te.isNonRecoverable());
81  1 Assert.assertEquals("Wrong number of exceptions reported", 3, te.exceptionCount());
82  1 Assert.assertEquals("The wrong exception message was given", SIMPLE_TEST_OUT, te.getMessage());
83    }
84   
 
85  1 toggle @Test
86    public void compoundExceptionTest()
87    {
 
88  1 toggle TransactionException te = new TransactionException(new ArrayList<Throwable>() {{
89  1 add(new Exception("something bad happened."));
90  1 add(getException());
91  1 add(new Error("SEGFAULT!"));
92    }});
93  1 Assert.assertFalse(te.isNonRecoverable());
94  1 Assert.assertEquals("Wrong number of exceptions reported", 5, te.exceptionCount());
95  1 Assert.assertEquals("The wrong exception message was given", COMPOUND_TEST_OUT, te.getMessage());
96    }
97   
 
98  1 toggle @Test
99    public void nonRecoverableTest()
100    {
 
101  1 toggle TransactionException te = new TransactionException(new ArrayList<Throwable>() {{
102  1 add(new Exception("something bad happened."));
103  1 add(new TransactionException("This means there is db corruption",
 
104  1 toggle new ArrayList<Throwable>() {{
105  1 add(new Error("Corruption!!"));
106    }}, true));
107  1 add(new Error("SEGFAULT!"));
108    }});
109  1 Assert.assertTrue(te.isNonRecoverable());
110  1 Assert.assertEquals("Wrong number of exceptions reported", 3, te.exceptionCount());
111  1 Assert.assertEquals("The wrong exception message was given",
112    NONRECOVERABLE_TEST_OUT, te.getMessage());
113    }
114   
 
115  2 toggle private TransactionException getException()
116    {
 
117  2 toggle return new TransactionException(new ArrayList<Throwable>() {{
118  2 add(new Exception("One exception."));
119  2 add(new RuntimeException("Number 2"));
120  2 add(new OutOfMemoryError("Ut oh"));
121    }});
122    }
123    }