1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.wiki.internal.descriptor.document; |
21 |
|
|
22 |
|
import static org.junit.Assert.assertEquals; |
23 |
|
import static org.mockito.ArgumentMatchers.any; |
24 |
|
import static org.mockito.ArgumentMatchers.eq; |
25 |
|
import static org.mockito.Mockito.mock; |
26 |
|
import static org.mockito.Mockito.when; |
27 |
|
|
28 |
|
import javax.inject.Provider; |
29 |
|
|
30 |
|
import org.junit.Before; |
31 |
|
import org.junit.Rule; |
32 |
|
import org.junit.Test; |
33 |
|
import org.xwiki.model.reference.DocumentReference; |
34 |
|
import org.xwiki.model.reference.DocumentReferenceResolver; |
35 |
|
import org.xwiki.query.QueryManager; |
36 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
37 |
|
import org.xwiki.wiki.descriptor.WikiDescriptorManager; |
38 |
|
|
39 |
|
import com.xpn.xwiki.XWiki; |
40 |
|
import com.xpn.xwiki.XWikiContext; |
41 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
42 |
|
|
43 |
|
|
44 |
|
@link |
45 |
|
|
46 |
|
@version |
47 |
|
@since |
48 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (26) |
Complexity: 4 |
Complexity Density: 0.18 |
|
49 |
|
public class DefaultWikiDescriptorDocumentHelperTest |
50 |
|
{ |
51 |
|
@Rule |
52 |
|
public org.xwiki.test.mockito.MockitoComponentMockingRule<DefaultWikiDescriptorDocumentHelper> mocker = |
53 |
|
new MockitoComponentMockingRule<>(DefaultWikiDescriptorDocumentHelper.class); |
54 |
|
|
55 |
|
private WikiDescriptorManager wikiDescriptorManager; |
56 |
|
|
57 |
|
private Provider<XWikiContext> xcontextProvider; |
58 |
|
|
59 |
|
private QueryManager queryManager; |
60 |
|
|
61 |
|
private DocumentReferenceResolver<String> documentReferenceResolver; |
62 |
|
|
63 |
|
private XWikiContext context; |
64 |
|
|
65 |
|
private XWiki xwiki; |
66 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
67 |
3 |
@Before... |
68 |
|
public void setUp() throws Exception |
69 |
|
{ |
70 |
3 |
wikiDescriptorManager = mocker.registerMockComponent(WikiDescriptorManager.class); |
71 |
3 |
when(wikiDescriptorManager.getMainWikiId()).thenReturn("xwiki"); |
72 |
|
|
73 |
3 |
xcontextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER); |
74 |
3 |
context = mock(XWikiContext.class); |
75 |
3 |
when(xcontextProvider.get()).thenReturn(context); |
76 |
3 |
xwiki = mock(XWiki.class); |
77 |
3 |
when(context.getWiki()).thenReturn(xwiki); |
78 |
|
|
79 |
3 |
queryManager = mocker.getInstance(QueryManager.class); |
80 |
3 |
documentReferenceResolver = mocker.getInstance(DocumentReferenceResolver.TYPE_STRING, "current"); |
81 |
|
} |
82 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
83 |
1 |
@Test... |
84 |
|
public void getDocumentReferenceFromId() throws Exception |
85 |
|
{ |
86 |
1 |
DocumentReference docRef = new DocumentReference("xwiki", XWiki.SYSTEM_SPACE, "XWikiServerWikiid1"); |
87 |
1 |
assertEquals(docRef, this.mocker.getComponentUnderTest().getDocumentReferenceFromId("wikiid1")); |
88 |
|
} |
89 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
90 |
1 |
@Test... |
91 |
|
public void getDocumentFromWikiId() throws Exception |
92 |
|
{ |
93 |
1 |
DocumentReference docRef = new DocumentReference("xwiki", XWiki.SYSTEM_SPACE, "XWikiServerWikiid1"); |
94 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
95 |
1 |
when(xwiki.getDocument(eq(docRef), any(XWikiContext.class))).thenReturn(document); |
96 |
|
|
97 |
1 |
XWikiDocument returnedDocument = this.mocker.getComponentUnderTest().getDocumentFromWikiId("wikiid1"); |
98 |
1 |
assertEquals(returnedDocument, document); |
99 |
|
} |
100 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
101 |
1 |
@Test... |
102 |
|
public void getWikiIdFromDocumentFullname() throws Exception |
103 |
|
{ |
104 |
1 |
String result = mocker.getComponentUnderTest().getWikiIdFromDocumentFullname("XWiki.XWikiServerSubwiki"); |
105 |
1 |
assertEquals("subwiki", result); |
106 |
|
|
107 |
1 |
result = mocker.getComponentUnderTest().getWikiIdFromDocumentFullname("XWiki.XWikiServerXWikiServer"); |
108 |
1 |
assertEquals("xwikiserver", result); |
109 |
|
|
110 |
1 |
result = mocker.getComponentUnderTest().getWikiIdFromDocumentFullname("XWiki.XWikiServerAbbc"); |
111 |
1 |
assertEquals("abbc", result); |
112 |
|
} |
113 |
|
|
114 |
|
} |