1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.rendering.macro.chart; |
21 |
|
|
22 |
|
import java.io.InputStreamReader; |
23 |
|
|
24 |
|
import org.junit.runner.RunWith; |
25 |
|
import org.mockito.Mockito; |
26 |
|
import org.xwiki.bridge.DocumentAccessBridge; |
27 |
|
import org.xwiki.bridge.DocumentModelBridge; |
28 |
|
import org.xwiki.display.internal.DocumentDisplayer; |
29 |
|
import org.xwiki.display.internal.DocumentDisplayerParameters; |
30 |
|
import org.xwiki.model.ModelContext; |
31 |
|
import org.xwiki.model.reference.DocumentReference; |
32 |
|
import org.xwiki.model.reference.DocumentReferenceResolver; |
33 |
|
import org.xwiki.model.reference.SpaceReferenceResolver; |
34 |
|
import org.xwiki.model.reference.WikiReference; |
35 |
|
import org.xwiki.rendering.block.XDOM; |
36 |
|
import org.xwiki.rendering.parser.Parser; |
37 |
|
import org.xwiki.rendering.syntax.Syntax; |
38 |
|
import org.xwiki.rendering.test.integration.RenderingTestSuite; |
39 |
|
import org.xwiki.security.authorization.AuthorizationManager; |
40 |
|
import org.xwiki.security.authorization.Right; |
41 |
|
import org.xwiki.test.annotation.AllComponents; |
42 |
|
import org.xwiki.test.mockito.MockitoComponentManager; |
43 |
|
|
44 |
|
import static org.mockito.Mockito.any; |
45 |
|
import static org.mockito.Mockito.eq; |
46 |
|
import static org.mockito.Mockito.when; |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
@link |
51 |
|
|
52 |
|
@version |
53 |
|
@since |
54 |
|
|
55 |
|
@RunWith(RenderingTestSuite.class) |
56 |
|
@AllComponents |
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 1 |
Complexity Density: 0.05 |
|
57 |
|
public class IntegrationTests |
58 |
|
{ |
59 |
|
private final static String WIKI_CONTENT_FILE = "wiki.txt"; |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 1 |
Complexity Density: 0.05 |
|
61 |
8 |
@RenderingTestSuite.Initialized... |
62 |
|
public void initialize(MockitoComponentManager componentManager) throws Exception |
63 |
|
{ |
64 |
8 |
ModelContext modelContext = componentManager.registerMockComponent(ModelContext.class); |
65 |
8 |
when(modelContext.getCurrentEntityReference()).thenReturn(new WikiReference("currentWiki")); |
66 |
|
|
67 |
|
|
68 |
8 |
DocumentAccessBridge dab = componentManager.registerMockComponent(DocumentAccessBridge.class); |
69 |
8 |
DocumentReference documentReference = new DocumentReference("wiki", "space", "page"); |
70 |
8 |
DocumentReference currentDocumentReference = |
71 |
|
new DocumentReference("currentwiki", "currentspace", "currentpage"); |
72 |
8 |
DocumentModelBridge document = Mockito.mock(DocumentModelBridge.class); |
73 |
8 |
when(dab.getDocumentURL(new DocumentReference("currentWiki", "space", "page"), "temp", null, null)) |
74 |
|
.thenReturn("temppath"); |
75 |
8 |
when(dab.getCurrentDocumentReference()).thenReturn(currentDocumentReference); |
76 |
8 |
when(dab.exists(documentReference)).thenReturn(true); |
77 |
8 |
when(dab.getDocument(documentReference)).thenReturn(document); |
78 |
8 |
when(dab.getCurrentUserReference()).thenReturn(null); |
79 |
|
|
80 |
8 |
DocumentDisplayer displayer = componentManager.registerMockComponent(DocumentDisplayer.class); |
81 |
8 |
Parser parser = componentManager.getInstance(Parser.class, Syntax.XWIKI_2_0.toIdString()); |
82 |
8 |
final XDOM xdom = parser.parse(new InputStreamReader( |
83 |
|
getClass().getClassLoader().getResourceAsStream(WIKI_CONTENT_FILE))); |
84 |
8 |
when(displayer.display(eq(document), any(DocumentDisplayerParameters.class))).thenReturn(xdom); |
85 |
|
|
86 |
8 |
AuthorizationManager authorizationManager = componentManager.registerMockComponent(AuthorizationManager.class); |
87 |
8 |
when(authorizationManager.hasAccess(Right.VIEW, null, documentReference)).thenReturn(true); |
88 |
|
|
89 |
8 |
componentManager.registerMockComponent(DocumentReferenceResolver.TYPE_STRING, "current"); |
90 |
8 |
componentManager.registerMockComponent(SpaceReferenceResolver.TYPE_STRING, "current"); |
91 |
|
} |
92 |
|
} |