1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.platform.wiki.creationjob.internal.steps; |
21 |
|
|
22 |
|
import org.junit.Before; |
23 |
|
import org.junit.Rule; |
24 |
|
import org.junit.Test; |
25 |
|
import org.xwiki.platform.wiki.creationjob.WikiCreationException; |
26 |
|
import org.xwiki.platform.wiki.creationjob.WikiCreationRequest; |
27 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
28 |
|
import org.xwiki.wiki.manager.WikiManager; |
29 |
|
import org.xwiki.wiki.manager.WikiManagerException; |
30 |
|
|
31 |
|
import static org.junit.Assert.assertEquals; |
32 |
|
import static org.junit.Assert.assertNotNull; |
33 |
|
import static org.mockito.ArgumentMatchers.any; |
34 |
|
import static org.mockito.ArgumentMatchers.anyBoolean; |
35 |
|
import static org.mockito.Mockito.doThrow; |
36 |
|
import static org.mockito.Mockito.verify; |
37 |
|
|
38 |
|
|
39 |
|
@version |
40 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (28) |
Complexity: 5 |
Complexity Density: 0.21 |
|
41 |
|
public class CreateWikiStepTest |
42 |
|
{ |
43 |
|
@Rule |
44 |
|
public MockitoComponentMockingRule<CreateWikiStep> mocker = new MockitoComponentMockingRule<>(CreateWikiStep.class); |
45 |
|
|
46 |
|
private WikiManager wikiManager; |
47 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
48 |
3 |
@Before... |
49 |
|
public void setUp() throws Exception |
50 |
|
{ |
51 |
3 |
wikiManager = mocker.getInstance(WikiManager.class); |
52 |
|
} |
53 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
54 |
1 |
@Test... |
55 |
|
public void execute() throws Exception |
56 |
|
{ |
57 |
1 |
WikiCreationRequest request = new WikiCreationRequest(); |
58 |
1 |
request.setWikiId("wikiId"); |
59 |
1 |
request.setAlias("wikiAlias"); |
60 |
1 |
request.setFailOnExist(true); |
61 |
|
|
62 |
|
|
63 |
1 |
mocker.getComponentUnderTest().execute(request); |
64 |
|
|
65 |
|
|
66 |
1 |
verify(wikiManager).create("wikiId", "wikiAlias", true); |
67 |
|
|
68 |
|
|
69 |
1 |
request.setFailOnExist(false); |
70 |
1 |
mocker.getComponentUnderTest().execute(request); |
71 |
|
|
72 |
|
|
73 |
1 |
verify(wikiManager).create("wikiId", "wikiAlias", false); |
74 |
|
} |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 2 |
Complexity Density: 0.15 |
1PASS
|
|
76 |
1 |
@Test... |
77 |
|
public void executeWhenException() throws Exception |
78 |
|
{ |
79 |
1 |
WikiCreationRequest request = new WikiCreationRequest(); |
80 |
1 |
request.setWikiId("wikiId"); |
81 |
1 |
request.setAlias("wikiAlias"); |
82 |
1 |
request.setFailOnExist(true); |
83 |
|
|
84 |
1 |
Exception exception = new WikiManagerException("Execption in WikiManager."); |
85 |
1 |
doThrow(exception).when(wikiManager).create(any(), any(), anyBoolean()); |
86 |
|
|
87 |
|
|
88 |
1 |
WikiCreationException caughtException = null; |
89 |
1 |
try { |
90 |
1 |
mocker.getComponentUnderTest().execute(request); |
91 |
|
} catch (WikiCreationException e) { |
92 |
1 |
caughtException = e; |
93 |
|
} |
94 |
|
|
95 |
|
|
96 |
1 |
assertNotNull(caughtException); |
97 |
1 |
assertEquals("Failed to create the wiki [wikiId].", caughtException.getMessage()); |
98 |
1 |
assertEquals(exception, caughtException.getCause()); |
99 |
|
|
100 |
|
} |
101 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
102 |
1 |
@Test... |
103 |
|
public void getOrder() throws Exception |
104 |
|
{ |
105 |
1 |
assertEquals(1000, mocker.getComponentUnderTest().getOrder()); |
106 |
|
} |
107 |
|
} |