1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.rendering.internal.executor; |
21 |
|
|
22 |
|
import java.util.Collections; |
23 |
|
|
24 |
|
import org.junit.Rule; |
25 |
|
import org.junit.Test; |
26 |
|
import org.xwiki.model.reference.DocumentReference; |
27 |
|
import org.xwiki.rendering.block.XDOM; |
28 |
|
import org.xwiki.rendering.executor.ContentExecutorException; |
29 |
|
import org.xwiki.rendering.parser.ContentParser; |
30 |
|
import org.xwiki.rendering.syntax.Syntax; |
31 |
|
import org.xwiki.rendering.transformation.MacroTransformationContext; |
32 |
|
import org.xwiki.rendering.transformation.Transformation; |
33 |
|
import org.xwiki.rendering.transformation.TransformationContext; |
34 |
|
import org.xwiki.rendering.transformation.TransformationException; |
35 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
36 |
|
|
37 |
|
import static org.mockito.Mockito.*; |
38 |
|
import static org.junit.Assert.*; |
39 |
|
|
40 |
|
|
41 |
|
@link |
42 |
|
|
43 |
|
@version |
44 |
|
@since |
45 |
|
|
|
|
| 96.7% |
Uncovered Elements: 1 (30) |
Complexity: 4 |
Complexity Density: 0.15 |
|
46 |
|
public class MacroContentExecutorTest |
47 |
|
{ |
48 |
|
@Rule |
49 |
|
public final MockitoComponentMockingRule<MacroContentExecutor> mocker = |
50 |
|
new MockitoComponentMockingRule<>(MacroContentExecutor.class); |
51 |
|
|
52 |
|
private static final DocumentReference DOCUMENT_REFERENCE = new DocumentReference("wiki", "space", "page"); |
53 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
54 |
1 |
@Test... |
55 |
|
public void executeWithNoSource() throws Exception |
56 |
|
{ |
57 |
1 |
XDOM parsedBlocks = new XDOM(Collections.emptyList()); |
58 |
1 |
ContentParser contentParser = this.mocker.getInstance(ContentParser.class); |
59 |
1 |
when(contentParser.parse("", Syntax.PLAIN_1_0)).thenReturn(parsedBlocks); |
60 |
|
|
61 |
1 |
TransformationContext transformationContext = new TransformationContext(); |
62 |
1 |
MacroTransformationContext context = new MacroTransformationContext(transformationContext); |
63 |
|
|
64 |
1 |
this.mocker.getComponentUnderTest().execute("", Syntax.PLAIN_1_0, context); |
65 |
|
|
66 |
|
|
67 |
1 |
Transformation macroTransformation = this.mocker.getInstance(Transformation.class, "macro"); |
68 |
1 |
verify(macroTransformation).transform(parsedBlocks, transformationContext); |
69 |
|
} |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
71 |
1 |
@Test... |
72 |
|
public void executeWithSource() throws Exception |
73 |
|
{ |
74 |
1 |
XDOM parsedBlocks = new XDOM(Collections.emptyList()); |
75 |
1 |
ContentParser contentParser = this.mocker.getInstance(ContentParser.class); |
76 |
1 |
when(contentParser.parse("", Syntax.PLAIN_1_0, DOCUMENT_REFERENCE)).thenReturn(parsedBlocks); |
77 |
|
|
78 |
1 |
TransformationContext transformationContext = new TransformationContext(); |
79 |
1 |
MacroTransformationContext context = new MacroTransformationContext(transformationContext); |
80 |
|
|
81 |
1 |
this.mocker.getComponentUnderTest().execute("", Syntax.PLAIN_1_0, DOCUMENT_REFERENCE, context); |
82 |
|
|
83 |
|
|
84 |
1 |
Transformation macroTransformation = this.mocker.getInstance(Transformation.class, "macro"); |
85 |
1 |
verify(macroTransformation).transform(parsedBlocks, transformationContext); |
86 |
|
} |
87 |
|
|
|
|
| 90.9% |
Uncovered Elements: 1 (11) |
Complexity: 2 |
Complexity Density: 0.18 |
1PASS
|
|
88 |
1 |
@Test... |
89 |
|
public void executeWhenTransformationException() throws Exception |
90 |
|
{ |
91 |
1 |
XDOM parsedBlocks = new XDOM(Collections.emptyList()); |
92 |
1 |
ContentParser contentParser = this.mocker.getInstance(ContentParser.class); |
93 |
1 |
when(contentParser.parse("", Syntax.PLAIN_1_0)).thenReturn(parsedBlocks); |
94 |
|
|
95 |
1 |
TransformationContext transformationContext = new TransformationContext(); |
96 |
1 |
MacroTransformationContext context = new MacroTransformationContext(transformationContext); |
97 |
|
|
98 |
1 |
Transformation macroTransformation = this.mocker.getInstance(Transformation.class, "macro"); |
99 |
1 |
doThrow(new TransformationException("error")) |
100 |
|
.when(macroTransformation).transform(parsedBlocks, transformationContext); |
101 |
|
|
102 |
1 |
try { |
103 |
1 |
this.mocker.getComponentUnderTest().execute("", Syntax.PLAIN_1_0, context); |
104 |
0 |
fail("Should have raised a ContentExecutorException"); |
105 |
|
} catch (ContentExecutorException expected) { |
106 |
1 |
assertEquals("Failed to execute content", expected.getMessage()); |
107 |
|
} |
108 |
|
} |
109 |
|
} |