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; |
21 |
|
|
22 |
|
import java.util.Arrays; |
23 |
|
|
24 |
|
import org.junit.Rule; |
25 |
|
import org.junit.Test; |
26 |
|
import org.mockito.invocation.InvocationOnMock; |
27 |
|
import org.mockito.stubbing.Answer; |
28 |
|
import org.xwiki.component.manager.ComponentLookupException; |
29 |
|
import org.xwiki.extension.ExtensionId; |
30 |
|
import org.xwiki.extension.job.InstallRequest; |
31 |
|
import org.xwiki.extension.job.internal.InstallJob; |
32 |
|
import org.xwiki.job.Job; |
33 |
|
import org.xwiki.job.Request; |
34 |
|
import org.xwiki.model.reference.DocumentReference; |
35 |
|
import org.xwiki.platform.wiki.creationjob.WikiCreationException; |
36 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
37 |
|
|
38 |
|
import static org.junit.Assert.assertEquals; |
39 |
|
import static org.junit.Assert.assertNotNull; |
40 |
|
import static org.junit.Assert.assertTrue; |
41 |
|
import static org.mockito.ArgumentMatchers.any; |
42 |
|
import static org.mockito.Mockito.doAnswer; |
43 |
|
import static org.mockito.Mockito.mock; |
44 |
|
import static org.mockito.Mockito.verify; |
45 |
|
|
46 |
|
|
47 |
|
@version |
48 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (23) |
Complexity: 4 |
Complexity Density: 0.2 |
|
49 |
|
public class ExtensionInstallerTest |
50 |
|
{ |
51 |
|
@Rule |
52 |
|
public MockitoComponentMockingRule<ExtensionInstaller> mocker = |
53 |
|
new MockitoComponentMockingRule<>(ExtensionInstaller.class); |
54 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
55 |
1 |
@Test... |
56 |
|
public void installExtension() throws Exception |
57 |
|
{ |
58 |
|
|
59 |
1 |
InstallJob installJob = mock(InstallJob.class); |
60 |
1 |
mocker.registerComponent(Job.class, InstallJob.JOBTYPE, installJob); |
61 |
1 |
final InstallRequest[] installRequest = {null}; |
62 |
|
|
63 |
1 |
doAnswer(new Answer() |
64 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
65 |
1 |
@Override... |
66 |
|
public Object answer(InvocationOnMock invocation) throws Throwable |
67 |
|
{ |
68 |
1 |
installRequest[0] = (InstallRequest) invocation.getArguments()[0]; |
69 |
1 |
return null; |
70 |
|
} |
71 |
|
}).when(installJob).initialize(any(Request.class)); |
72 |
|
|
73 |
|
|
74 |
1 |
mocker.getComponentUnderTest().installExtension("wikiId", new ExtensionId("extensionId", "version")); |
75 |
|
|
76 |
|
|
77 |
1 |
assertNotNull(installRequest[0]); |
78 |
1 |
assertEquals(Arrays.asList("wiki:wikiId"), installRequest[0].getNamespaces()); |
79 |
1 |
assertEquals(Arrays.asList("wikicreation", "install", "wikiId"), installRequest[0].getId()); |
80 |
1 |
assertEquals(Arrays.asList(new ExtensionId("extensionId", "version")), installRequest[0].getExtensions()); |
81 |
1 |
assertEquals(new DocumentReference("xwiki", "XWiki", "superadmin"), |
82 |
|
installRequest[0].getProperty("user.reference")); |
83 |
1 |
verify(installJob).run(); |
84 |
|
} |
85 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
1PASS
|
|
86 |
1 |
@Test... |
87 |
|
public void installExtensionWithException() throws Exception |
88 |
|
{ |
89 |
|
|
90 |
1 |
WikiCreationException caughtException = null; |
91 |
1 |
try { |
92 |
1 |
mocker.getComponentUnderTest().installExtension("wikiId", new ExtensionId("extensionId", "version")); |
93 |
|
} catch (WikiCreationException e) { |
94 |
1 |
caughtException = e; |
95 |
|
} |
96 |
|
|
97 |
|
|
98 |
1 |
assertNotNull(caughtException); |
99 |
1 |
assertEquals("Failed to install the extension [extensionId-version] on the wiki [wikiId].", |
100 |
|
caughtException.getMessage()); |
101 |
1 |
assertTrue(caughtException.getCause() instanceof ComponentLookupException); |
102 |
|
} |
103 |
|
} |