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.manager; |
21 |
|
|
22 |
|
import javax.inject.Provider; |
23 |
|
|
24 |
|
import org.junit.Before; |
25 |
|
import org.junit.Rule; |
26 |
|
import org.junit.Test; |
27 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
28 |
|
import org.xwiki.wiki.descriptor.WikiDescriptorManager; |
29 |
|
import org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor; |
30 |
|
import org.xwiki.wiki.internal.descriptor.document.WikiDescriptorDocumentHelper; |
31 |
|
import org.xwiki.wiki.manager.WikiManagerException; |
32 |
|
|
33 |
|
import com.xpn.xwiki.XWikiContext; |
34 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
35 |
|
import com.xpn.xwiki.store.XWikiStoreInterface; |
36 |
|
|
37 |
|
import static org.junit.Assert.assertTrue; |
38 |
|
import static org.mockito.ArgumentMatchers.any; |
39 |
|
import static org.mockito.ArgumentMatchers.eq; |
40 |
|
import static org.mockito.Mockito.mock; |
41 |
|
import static org.mockito.Mockito.verify; |
42 |
|
import static org.mockito.Mockito.when; |
43 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (25) |
Complexity: 4 |
Complexity Density: 0.18 |
|
44 |
|
public class DefaultWikiDeleterTest |
45 |
|
{ |
46 |
|
@Rule |
47 |
|
public MockitoComponentMockingRule<DefaultWikiDeleter> mocker = |
48 |
|
new MockitoComponentMockingRule(DefaultWikiDeleter.class); |
49 |
|
|
50 |
|
private WikiDescriptorManager wikiDescriptorManager; |
51 |
|
|
52 |
|
private Provider<XWikiContext> xcontextProvider; |
53 |
|
|
54 |
|
private WikiDescriptorDocumentHelper descriptorDocumentHelper; |
55 |
|
|
56 |
|
private XWikiContext xcontext; |
57 |
|
|
58 |
|
private com.xpn.xwiki.XWiki xwiki; |
59 |
|
|
60 |
|
private XWikiStoreInterface store; |
61 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
|
62 |
2 |
@Before... |
63 |
|
public void setUp() throws Exception |
64 |
|
{ |
65 |
|
|
66 |
2 |
wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class); |
67 |
2 |
xcontextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER); |
68 |
2 |
descriptorDocumentHelper = mocker.getInstance(WikiDescriptorDocumentHelper.class); |
69 |
|
|
70 |
|
|
71 |
2 |
xcontext = mock(XWikiContext.class); |
72 |
2 |
when(xcontextProvider.get()).thenReturn(xcontext); |
73 |
2 |
xwiki = mock(com.xpn.xwiki.XWiki.class); |
74 |
2 |
when(xcontext.getWiki()).thenReturn(xwiki); |
75 |
2 |
when(wikiDescriptorManager.getMainWikiId()).thenReturn("xwiki"); |
76 |
2 |
store = mock(XWikiStoreInterface.class); |
77 |
2 |
when(xwiki.getStore()).thenReturn(store); |
78 |
|
} |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
1PASS
|
|
80 |
1 |
@Test... |
81 |
|
public void deleteTheMainWiki() throws Exception |
82 |
|
{ |
83 |
1 |
boolean exceptionCaught = false; |
84 |
1 |
try { |
85 |
1 |
this.mocker.getComponentUnderTest().delete("xwiki"); |
86 |
|
} catch (WikiManagerException e) { |
87 |
1 |
exceptionCaught = true; |
88 |
|
} |
89 |
1 |
assertTrue(exceptionCaught); |
90 |
|
} |
91 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
92 |
1 |
@Test... |
93 |
|
public void deleteWiki() throws Exception |
94 |
|
{ |
95 |
|
|
96 |
1 |
DefaultWikiDescriptor descriptor = new DefaultWikiDescriptor("wikiid", "wikialias"); |
97 |
1 |
descriptor.addAlias("wikialias2"); |
98 |
1 |
XWikiDocument descriptorDocument = mock(XWikiDocument.class); |
99 |
1 |
when(descriptorDocumentHelper.getDocumentFromWikiId("wikiid")).thenReturn(descriptorDocument); |
100 |
|
|
101 |
|
|
102 |
1 |
this.mocker.getComponentUnderTest().delete("wikiid"); |
103 |
|
|
104 |
|
|
105 |
1 |
verify(store).deleteWiki(eq("wikiid"), any(XWikiContext.class)); |
106 |
|
|
107 |
1 |
verify(xwiki).deleteDocument(eq(descriptorDocument), any(XWikiContext.class)); |
108 |
|
} |
109 |
|
} |