1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.render; |
21 |
|
|
22 |
|
import org.apache.velocity.VelocityContext; |
23 |
|
import org.junit.Before; |
24 |
|
import org.junit.Rule; |
25 |
|
import org.junit.Test; |
26 |
|
import org.xwiki.component.manager.ComponentLookupException; |
27 |
|
import org.xwiki.localization.ContextualLocalizationManager; |
28 |
|
import org.xwiki.model.reference.DocumentReference; |
29 |
|
import org.xwiki.rendering.syntax.SyntaxFactory; |
30 |
|
import org.xwiki.script.internal.DefaultScriptContextManager; |
31 |
|
import org.xwiki.test.annotation.ComponentList; |
32 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
33 |
|
import org.xwiki.velocity.VelocityManager; |
34 |
|
import org.xwiki.velocity.internal.DefaultVelocityConfiguration; |
35 |
|
import org.xwiki.velocity.internal.VelocityExecutionContextInitializer; |
36 |
|
|
37 |
|
import com.xpn.xwiki.api.Document; |
38 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
39 |
|
import com.xpn.xwiki.test.MockitoOldcoreRule; |
40 |
|
|
41 |
|
import static org.junit.Assert.assertNotNull; |
42 |
|
import static org.junit.Assert.assertNotSame; |
43 |
|
import static org.junit.Assert.assertNull; |
44 |
|
import static org.junit.Assert.assertSame; |
45 |
|
|
46 |
|
|
47 |
|
@link |
48 |
|
|
49 |
|
@version |
50 |
|
|
51 |
|
@ComponentList(value = { DefaultScriptContextManager.class, XWikiScriptContextInitializer.class, |
52 |
|
DefaultVelocityConfiguration.class }) |
|
|
| 100% |
Uncovered Elements: 0 (29) |
Complexity: 2 |
Complexity Density: 0.07 |
|
53 |
|
public class DefaultVelocityManagerTest |
54 |
|
{ |
55 |
|
public MockitoComponentMockingRule<VelocityManager> mocker = |
56 |
|
new MockitoComponentMockingRule<VelocityManager>(DefaultVelocityManager.class); |
57 |
|
|
58 |
|
@Rule |
59 |
|
public MockitoOldcoreRule oldcore = new MockitoOldcoreRule(this.mocker); |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
61 |
1 |
@Before... |
62 |
|
public void before() throws Exception |
63 |
|
{ |
64 |
1 |
this.mocker.registerMockComponent(SyntaxFactory.class); |
65 |
1 |
this.mocker.registerMockComponent(ContextualLocalizationManager.class); |
66 |
|
|
67 |
1 |
this.oldcore.getExecutionContext().setProperty(VelocityExecutionContextInitializer.VELOCITY_CONTEXT_ID, |
68 |
|
new VelocityContext()); |
69 |
|
} |
70 |
|
|
71 |
|
|
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
73 |
1 |
@Test... |
74 |
|
public void getVelocityContext() throws ComponentLookupException |
75 |
|
{ |
76 |
1 |
VelocityContext context = this.mocker.getComponentUnderTest().getVelocityContext(); |
77 |
|
|
78 |
1 |
assertNull(context.get("doc")); |
79 |
1 |
assertNull(context.get("sdoc")); |
80 |
|
|
81 |
1 |
DocumentReference docReference = new DocumentReference("wiki", "space", "doc"); |
82 |
1 |
DocumentReference sdocReference = new DocumentReference("wiki", "space", "sdoc"); |
83 |
|
|
84 |
1 |
this.oldcore.getXWikiContext().setDoc(new XWikiDocument(docReference)); |
85 |
1 |
this.oldcore.getXWikiContext().put("sdoc", new XWikiDocument(sdocReference)); |
86 |
|
|
87 |
1 |
context = this.mocker.getComponentUnderTest().getVelocityContext(); |
88 |
|
|
89 |
1 |
Document doc = (Document) context.get("doc"); |
90 |
1 |
assertNotNull(doc); |
91 |
|
|
92 |
1 |
Document sdoc = (Document) context.get("sdoc"); |
93 |
1 |
assertNotNull(sdoc); |
94 |
|
|
95 |
|
|
96 |
1 |
context = this.mocker.getComponentUnderTest().getVelocityContext(); |
97 |
1 |
assertSame(doc, context.get("doc")); |
98 |
1 |
assertSame(sdoc, context.get("sdoc")); |
99 |
|
|
100 |
|
|
101 |
1 |
docReference = new DocumentReference("wiki", "space", "doc2"); |
102 |
1 |
sdocReference = new DocumentReference("wiki", "space", "sdoc2"); |
103 |
1 |
this.oldcore.getXWikiContext().setDoc(new XWikiDocument(docReference)); |
104 |
1 |
this.oldcore.getXWikiContext().put("sdoc", new XWikiDocument(sdocReference)); |
105 |
|
|
106 |
1 |
context = this.mocker.getComponentUnderTest().getVelocityContext(); |
107 |
1 |
assertNotNull(context.get("doc")); |
108 |
1 |
assertNotSame(doc, context.get("doc")); |
109 |
1 |
assertNotNull(context.get("sdoc")); |
110 |
1 |
assertNotSame(sdoc, context.get("sdoc")); |
111 |
|
} |
112 |
|
} |