1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.module.blossom.preexecution; |
35 |
|
|
36 |
|
import static org.junit.Assert.assertFalse; |
37 |
|
import static org.junit.Assert.assertTrue; |
38 |
|
import static org.junit.Assert.fail; |
39 |
|
|
40 |
|
import info.magnolia.context.MgnlContext; |
41 |
|
import info.magnolia.jcr.RuntimeRepositoryException; |
42 |
|
import info.magnolia.test.MgnlTestCase; |
43 |
|
import info.magnolia.test.mock.MockWebContext; |
44 |
|
import info.magnolia.test.mock.jcr.MockNode; |
45 |
|
|
46 |
|
import javax.jcr.Node; |
47 |
|
import javax.jcr.RepositoryException; |
48 |
|
|
49 |
|
import org.junit.Test; |
50 |
|
import org.mockito.Mockito; |
51 |
|
import org.springframework.mock.web.MockHttpServletRequest; |
52 |
|
|
53 |
|
|
54 |
|
@link |
55 |
|
|
56 |
|
@since |
57 |
|
|
|
|
| 97.1% |
Uncovered Elements: 1 (34) |
Complexity: 5 |
Complexity Density: 0.17 |
|
58 |
|
public class PreexecutionUtilsTest extends MgnlTestCase { |
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
60 |
1 |
@Test... |
61 |
|
public void testIsPreexecutingReturnsFalseWhenPreexecutionContextIsNotSet() { |
62 |
|
|
63 |
|
|
64 |
1 |
MockWebContext webContext = (MockWebContext) MgnlContext.getInstance(); |
65 |
1 |
webContext.setRequest(new MockHttpServletRequest()); |
66 |
|
|
67 |
|
|
68 |
1 |
assertFalse(PreexecutionUtils.isPreexecuting()); |
69 |
|
} |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
71 |
1 |
@Test... |
72 |
|
public void testIsPreexecutingReturnsFalseWhenPreexecutighOtherNode() { |
73 |
|
|
74 |
|
|
75 |
1 |
MockWebContext webContext = (MockWebContext) MgnlContext.getInstance(); |
76 |
1 |
webContext.setRequest(new MockHttpServletRequest()); |
77 |
1 |
MockNode currentContentNode = new MockNode(); |
78 |
1 |
currentContentNode.setIdentifier("some-other-uuid"); |
79 |
1 |
webContext.getAggregationState().setCurrentContentNode(currentContentNode); |
80 |
1 |
PreexecutionContext preexecutionContext = new PreexecutionContext("uuid"); |
81 |
1 |
PreexecutionContextHolder.put(webContext.getRequest(), preexecutionContext); |
82 |
|
|
83 |
|
|
84 |
1 |
assertFalse(PreexecutionUtils.isPreexecuting()); |
85 |
|
} |
86 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
87 |
1 |
@Test... |
88 |
|
public void testIsPreexecutingReturnsTrueWhenPreexecutingCurrentNode() { |
89 |
|
|
90 |
|
|
91 |
1 |
MockWebContext webContext = (MockWebContext) MgnlContext.getInstance(); |
92 |
1 |
webContext.setRequest(new MockHttpServletRequest()); |
93 |
1 |
MockNode currentContentNode = new MockNode(); |
94 |
1 |
currentContentNode.setIdentifier("uuid"); |
95 |
1 |
webContext.getAggregationState().setCurrentContentNode(currentContentNode); |
96 |
1 |
PreexecutionContext preexecutionContext = new PreexecutionContext("uuid"); |
97 |
1 |
PreexecutionContextHolder.put(webContext.getRequest(), preexecutionContext); |
98 |
|
|
99 |
|
|
100 |
1 |
assertTrue(PreexecutionUtils.isPreexecuting()); |
101 |
|
} |
102 |
|
|
|
|
| 90.9% |
Uncovered Elements: 1 (11) |
Complexity: 2 |
Complexity Density: 0.18 |
1PASS
|
|
103 |
1 |
@Test... |
104 |
|
public void testRepositoryExceptionIsWrappedInRuntimeRepositoryException() throws RepositoryException { |
105 |
|
|
106 |
|
|
107 |
1 |
MockWebContext webContext = (MockWebContext) MgnlContext.getInstance(); |
108 |
1 |
webContext.setRequest(new MockHttpServletRequest()); |
109 |
1 |
Node currentContentNode = Mockito.mock(Node.class); |
110 |
1 |
Mockito.when(currentContentNode.getIdentifier()).thenThrow(new RepositoryException("")); |
111 |
1 |
webContext.getAggregationState().setCurrentContentNode(currentContentNode); |
112 |
1 |
PreexecutionContext preexecutionContext = new PreexecutionContext("uuid"); |
113 |
1 |
PreexecutionContextHolder.put(webContext.getRequest(), preexecutionContext); |
114 |
|
|
115 |
|
|
116 |
1 |
try { |
117 |
1 |
PreexecutionUtils.isPreexecuting(); |
118 |
0 |
fail(); |
119 |
|
} catch (RuntimeRepositoryException e) { |
120 |
|
|
121 |
1 |
assertTrue(e.getCause() instanceof RepositoryException); |
122 |
|
} |
123 |
|
} |
124 |
|
} |