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.provisioning; |
21 |
|
|
22 |
|
import java.util.Arrays; |
23 |
|
import java.util.List; |
24 |
|
|
25 |
|
import javax.inject.Provider; |
26 |
|
|
27 |
|
import org.junit.Before; |
28 |
|
import org.junit.Rule; |
29 |
|
import org.junit.Test; |
30 |
|
import org.mockito.InOrder; |
31 |
|
import org.slf4j.Logger; |
32 |
|
import org.xwiki.job.event.status.JobProgressManager; |
33 |
|
import org.xwiki.model.reference.DocumentReference; |
34 |
|
import org.xwiki.model.reference.DocumentReferenceResolver; |
35 |
|
import org.xwiki.model.reference.WikiReference; |
36 |
|
import org.xwiki.query.Query; |
37 |
|
import org.xwiki.query.QueryManager; |
38 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
39 |
|
|
40 |
|
import com.xpn.xwiki.XWikiContext; |
41 |
|
|
42 |
|
import static org.mockito.ArgumentMatchers.eq; |
43 |
|
import static org.mockito.Mockito.inOrder; |
44 |
|
import static org.mockito.Mockito.mock; |
45 |
|
import static org.mockito.Mockito.verify; |
46 |
|
import static org.mockito.Mockito.when; |
47 |
|
|
48 |
|
|
49 |
|
@version |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (41) |
Complexity: 2 |
Complexity Density: 0.05 |
|
51 |
|
public class DefaultWikiCopierTest |
52 |
|
{ |
53 |
|
@Rule |
54 |
|
public MockitoComponentMockingRule<DefaultWikiCopier> mocker = new MockitoComponentMockingRule( |
55 |
|
DefaultWikiCopier.class); |
56 |
|
|
57 |
|
private QueryManager queryManager; |
58 |
|
|
59 |
|
private Provider<XWikiContext> xcontextProvider; |
60 |
|
|
61 |
|
private DocumentReferenceResolver<String> documentReferenceResolver; |
62 |
|
|
63 |
|
private JobProgressManager progress; |
64 |
|
|
65 |
|
private Logger logger; |
66 |
|
|
67 |
|
private XWikiContext xcontext; |
68 |
|
|
69 |
|
private com.xpn.xwiki.XWiki xwiki; |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
71 |
1 |
@Before... |
72 |
|
public void setUp() throws Exception |
73 |
|
{ |
74 |
1 |
queryManager = mocker.getInstance(QueryManager.class); |
75 |
1 |
progress = mocker.getInstance(JobProgressManager.class); |
76 |
1 |
xcontextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER); |
77 |
1 |
xcontext = mock(XWikiContext.class); |
78 |
1 |
when(xcontextProvider.get()).thenReturn(xcontext); |
79 |
1 |
xwiki = mock(com.xpn.xwiki.XWiki.class); |
80 |
1 |
when(xcontext.getWiki()).thenReturn(xwiki); |
81 |
|
|
82 |
1 |
documentReferenceResolver = mocker.getInstance(DocumentReferenceResolver.TYPE_STRING, "current"); |
83 |
|
} |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (31) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
85 |
1 |
@Test... |
86 |
|
public void copyDocuments() throws Exception |
87 |
|
{ |
88 |
|
|
89 |
1 |
Query query = mock(Query.class); |
90 |
1 |
when(queryManager.createQuery("select distinct doc.fullName from Document as doc", Query.XWQL)).thenReturn( |
91 |
|
query); |
92 |
|
|
93 |
1 |
List<String> documentList = Arrays.asList("Space.Doc1", "Space.Doc2", "Space.Doc3"); |
94 |
1 |
when(query.<String>execute()).thenReturn(documentList); |
95 |
|
|
96 |
1 |
WikiReference fromWikiReference = new WikiReference("wikiA"); |
97 |
1 |
DocumentReference docRef1 = new DocumentReference("wikiA", "Space", "Doc1"); |
98 |
1 |
DocumentReference docRef2 = new DocumentReference("wikiA", "Space", "Doc2"); |
99 |
1 |
DocumentReference docRef3 = new DocumentReference("wikiA", "Space", "Doc3"); |
100 |
1 |
DocumentReference copydocRef1 = new DocumentReference("wikiB", "Space", "Doc1"); |
101 |
1 |
DocumentReference copydocRef2 = new DocumentReference("wikiB", "Space", "Doc2"); |
102 |
1 |
DocumentReference copydocRef3 = new DocumentReference("wikiB", "Space", "Doc3"); |
103 |
1 |
when(documentReferenceResolver.resolve(eq("Space.Doc1"), eq(fromWikiReference))).thenReturn(docRef1); |
104 |
1 |
when(documentReferenceResolver.resolve(eq("Space.Doc2"), eq(fromWikiReference))).thenReturn(docRef2); |
105 |
1 |
when(documentReferenceResolver.resolve(eq("Space.Doc3"), eq(fromWikiReference))).thenReturn(docRef3); |
106 |
|
|
107 |
|
|
108 |
1 |
mocker.getComponentUnderTest().copyDocuments("wikiA", "wikiB", false); |
109 |
|
|
110 |
|
|
111 |
1 |
verify(query).setWiki("wikiA"); |
112 |
1 |
InOrder inOrder = inOrder(progress, xwiki, mocker.getMockedLogger()); |
113 |
1 |
inOrder.verify(progress).pushLevelProgress(3, mocker.getComponentUnderTest()); |
114 |
|
|
115 |
1 |
inOrder.verify(progress).startStep(mocker.getComponentUnderTest()); |
116 |
1 |
inOrder.verify(mocker.getMockedLogger()).info("Copying document [{}] to [{}].", docRef1, copydocRef1); |
117 |
1 |
inOrder.verify(xwiki).copyDocument(docRef1, copydocRef1, null, true, true, xcontext); |
118 |
1 |
inOrder.verify(mocker.getMockedLogger()).info("Done copying document [{}] to [{}].", docRef1, copydocRef1); |
119 |
|
|
120 |
1 |
inOrder.verify(progress).startStep(mocker.getComponentUnderTest()); |
121 |
1 |
inOrder.verify(mocker.getMockedLogger()).info("Copying document [{}] to [{}].", docRef2, copydocRef2); |
122 |
1 |
inOrder.verify(xwiki).copyDocument(docRef2, copydocRef2, null, true, true, xcontext); |
123 |
1 |
inOrder.verify(mocker.getMockedLogger()).info("Done copying document [{}] to [{}].", docRef2, copydocRef2); |
124 |
|
|
125 |
1 |
inOrder.verify(progress).startStep(mocker.getComponentUnderTest()); |
126 |
1 |
inOrder.verify(mocker.getMockedLogger()).info("Copying document [{}] to [{}].", docRef3, copydocRef3); |
127 |
1 |
inOrder.verify(xwiki).copyDocument(docRef3, copydocRef3, null, true, true, xcontext); |
128 |
1 |
inOrder.verify(mocker.getMockedLogger()).info("Done copying document [{}] to [{}].", docRef3, copydocRef3); |
129 |
|
|
130 |
1 |
inOrder.verify(progress).popLevelProgress(mocker.getComponentUnderTest()); |
131 |
|
} |
132 |
|
} |