1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.uiextension; |
21 |
|
|
22 |
|
import org.junit.Assert; |
23 |
|
import org.junit.Before; |
24 |
|
import org.junit.Rule; |
25 |
|
import org.junit.Test; |
26 |
|
import org.xwiki.component.wiki.internal.bridge.ContentParser; |
27 |
|
import org.xwiki.context.Execution; |
28 |
|
import org.xwiki.context.ExecutionContext; |
29 |
|
import org.xwiki.model.reference.DocumentReference; |
30 |
|
import org.xwiki.rendering.block.Block; |
31 |
|
import org.xwiki.rendering.block.XDOM; |
32 |
|
import org.xwiki.rendering.internal.transformation.MutableRenderingContext; |
33 |
|
import org.xwiki.rendering.syntax.Syntax; |
34 |
|
import org.xwiki.rendering.transformation.RenderingContext; |
35 |
|
import org.xwiki.rendering.transformation.Transformation; |
36 |
|
import org.xwiki.test.mockito.MockitoComponentManagerRule; |
37 |
|
import org.xwiki.uiextension.internal.WikiUIExtensionRenderer; |
38 |
|
|
39 |
|
import com.xpn.xwiki.XWiki; |
40 |
|
import com.xpn.xwiki.XWikiContext; |
41 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
42 |
|
|
43 |
|
import static org.mockito.Mockito.mock; |
44 |
|
import static org.mockito.Mockito.when; |
45 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (23) |
Complexity: 2 |
Complexity Density: 0.1 |
|
46 |
|
public class WikiUIExtensionRendererTest |
47 |
|
{ |
48 |
|
private Execution execution; |
49 |
|
|
50 |
|
private RenderingContext renderingContext; |
51 |
|
|
52 |
|
private ContentParser contentParser; |
53 |
|
|
54 |
|
private XDOM xdom; |
55 |
|
|
56 |
|
private static final DocumentReference DOC_REF = new DocumentReference("xwiki", "XWiki", "MyUIExtension"); |
57 |
|
|
58 |
|
@Rule |
59 |
|
public MockitoComponentManagerRule cm = new MockitoComponentManagerRule(); |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
61 |
1 |
@Before... |
62 |
|
public void setUp() throws Exception |
63 |
|
{ |
64 |
1 |
execution = cm.registerMockComponent(Execution.class); |
65 |
1 |
ExecutionContext executionContext = mock(ExecutionContext.class); |
66 |
1 |
renderingContext = mock(MutableRenderingContext.class); |
67 |
1 |
cm.registerComponent(RenderingContext.class, renderingContext); |
68 |
1 |
cm.registerMockComponent(Transformation.class, "macro"); |
69 |
1 |
contentParser = cm.registerMockComponent(ContentParser.class); |
70 |
1 |
when(execution.getContext()).thenReturn(executionContext); |
71 |
1 |
xdom = mock(XDOM.class); |
72 |
|
} |
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
74 |
1 |
@Test... |
75 |
|
public void executeWithEmptyContent() throws Exception |
76 |
|
{ |
77 |
1 |
XWikiContext xcontext = mock(XWikiContext.class); |
78 |
1 |
XWikiDocument xdoc = mock(XWikiDocument.class); |
79 |
1 |
XWiki xwiki = mock(XWiki.class); |
80 |
|
|
81 |
1 |
when(contentParser.parse("", Syntax.XWIKI_2_1, DOC_REF)).thenReturn(xdom); |
82 |
1 |
when(xdom.clone()).thenReturn(xdom); |
83 |
1 |
when(execution.getContext().getProperty("xwikicontext")).thenReturn(xcontext); |
84 |
1 |
when(xcontext.getWiki()).thenReturn(xwiki); |
85 |
1 |
when(xwiki.getDocument(DOC_REF, xcontext)).thenReturn(xdoc); |
86 |
1 |
when(xcontext.getWiki().getDocument(DOC_REF, xcontext)).thenReturn(xdoc); |
87 |
1 |
when(xdoc.getSyntax()).thenReturn(Syntax.XWIKI_2_1); |
88 |
|
|
89 |
1 |
WikiUIExtensionRenderer renderer = new WikiUIExtensionRenderer("roleHint", "", DOC_REF, cm); |
90 |
|
|
91 |
1 |
Block block = renderer.execute(); |
92 |
1 |
Assert.assertEquals(0, block.getChildren().size()); |
93 |
|
} |
94 |
|
} |