1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.extension.internal; |
21 |
|
|
22 |
|
import org.junit.Before; |
23 |
|
import org.junit.Rule; |
24 |
|
import org.junit.Test; |
25 |
|
import org.xwiki.extension.ExtensionDependency; |
26 |
|
import org.xwiki.extension.ExtensionId; |
27 |
|
import org.xwiki.extension.ExtensionManager; |
28 |
|
import org.xwiki.extension.InstalledExtension; |
29 |
|
import org.xwiki.extension.ResolveException; |
30 |
|
import org.xwiki.extension.repository.CoreExtensionRepository; |
31 |
|
import org.xwiki.extension.repository.ExtensionRepository; |
32 |
|
import org.xwiki.extension.repository.ExtensionRepositoryDescriptor; |
33 |
|
import org.xwiki.extension.repository.InstalledExtensionRepository; |
34 |
|
import org.xwiki.extension.repository.LocalExtensionRepository; |
35 |
|
import org.xwiki.extension.version.Version; |
36 |
|
import org.xwiki.extension.version.VersionConstraint; |
37 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
38 |
|
|
39 |
|
import static org.junit.Assert.assertNull; |
40 |
|
import static org.junit.Assert.assertSame; |
41 |
|
import static org.mockito.Mockito.doThrow; |
42 |
|
import static org.mockito.Mockito.mock; |
43 |
|
import static org.mockito.Mockito.when; |
44 |
|
|
45 |
|
|
46 |
|
@link |
47 |
|
|
48 |
|
@version |
49 |
|
@since |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (38) |
Complexity: 5 |
Complexity Density: 0.15 |
|
51 |
|
public class DefaultExtensionManagerTest |
52 |
|
{ |
53 |
|
@Rule |
54 |
|
public final MockitoComponentMockingRule<ExtensionManager> mocker = |
55 |
|
new MockitoComponentMockingRule<ExtensionManager>(DefaultExtensionManager.class); |
56 |
|
|
57 |
|
private CoreExtensionRepository coreExtensionRepository; |
58 |
|
|
59 |
|
private LocalExtensionRepository localExtensionRepository; |
60 |
|
|
61 |
|
private InstalledExtensionRepository installedExtensionRepository; |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
63 |
3 |
@Before... |
64 |
|
public void setUp() throws Exception |
65 |
|
{ |
66 |
3 |
this.coreExtensionRepository = this.mocker.getInstance(CoreExtensionRepository.class); |
67 |
3 |
mockExtensionRepositoryDescriptor(this.coreExtensionRepository, "core"); |
68 |
|
|
69 |
3 |
this.localExtensionRepository = this.mocker.getInstance(LocalExtensionRepository.class); |
70 |
3 |
mockExtensionRepositoryDescriptor(this.localExtensionRepository, "local"); |
71 |
|
|
72 |
3 |
this.installedExtensionRepository = this.mocker.getInstance(InstalledExtensionRepository.class); |
73 |
3 |
mockExtensionRepositoryDescriptor(this.installedExtensionRepository, "installed"); |
74 |
|
} |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
76 |
9 |
private ExtensionRepositoryDescriptor mockExtensionRepositoryDescriptor(ExtensionRepository repository, String id)... |
77 |
|
{ |
78 |
9 |
ExtensionRepositoryDescriptor descriptor = mock(ExtensionRepositoryDescriptor.class, id); |
79 |
9 |
when(repository.getDescriptor()).thenReturn(descriptor); |
80 |
9 |
when(descriptor.getId()).thenReturn(id); |
81 |
9 |
return descriptor; |
82 |
|
} |
83 |
|
|
84 |
|
|
85 |
|
@link |
86 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
87 |
1 |
@Test... |
88 |
|
public void resolveMissingExtensionDependencyOnNamespace() throws Exception |
89 |
|
{ |
90 |
1 |
ExtensionDependency extensionDependency = mock(ExtensionDependency.class); |
91 |
|
|
92 |
1 |
doThrow(ResolveException.class).when(this.coreExtensionRepository).resolve(extensionDependency); |
93 |
1 |
doThrow(ResolveException.class).when(this.localExtensionRepository).resolve(extensionDependency); |
94 |
|
|
95 |
1 |
assertNull(this.mocker.getComponentUnderTest().resolveExtension(extensionDependency, "wiki:math")); |
96 |
|
} |
97 |
|
|
98 |
|
|
99 |
|
@link |
100 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
101 |
1 |
@Test... |
102 |
|
public void resolveInstalledExtensionDependencyOnNamespace() throws Exception |
103 |
|
{ |
104 |
1 |
String namespace = "wiki:math"; |
105 |
1 |
String extensionId = "test:extension"; |
106 |
|
|
107 |
1 |
ExtensionDependency extensionDependency = mock(ExtensionDependency.class); |
108 |
1 |
doThrow(ResolveException.class).when(this.coreExtensionRepository).resolve(extensionDependency); |
109 |
|
|
110 |
1 |
InstalledExtension extension = mock(InstalledExtension.class); |
111 |
1 |
when(extensionDependency.getId()).thenReturn(extensionId); |
112 |
1 |
when(this.installedExtensionRepository.getInstalledExtension(extensionId, namespace)).thenReturn(extension); |
113 |
|
|
114 |
1 |
Version version = mock(Version.class); |
115 |
1 |
when(extension.getId()).thenReturn(new ExtensionId(extensionId, version)); |
116 |
|
|
117 |
1 |
VersionConstraint versionConstraint = mock(VersionConstraint.class); |
118 |
1 |
when(extensionDependency.getVersionConstraint()).thenReturn(versionConstraint); |
119 |
1 |
when(versionConstraint.containsVersion(version)).thenReturn(true); |
120 |
|
|
121 |
1 |
assertSame(extension, this.mocker.getComponentUnderTest().resolveExtension(extensionDependency, namespace)); |
122 |
|
} |
123 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
124 |
1 |
@Test... |
125 |
|
public void resolveInstalledExtensionId() throws Exception |
126 |
|
{ |
127 |
1 |
ExtensionId extensionId = new ExtensionId("extension", "version"); |
128 |
|
|
129 |
1 |
doThrow(ResolveException.class).when(this.coreExtensionRepository).resolve(extensionId); |
130 |
|
|
131 |
1 |
InstalledExtension extension = mock(InstalledExtension.class); |
132 |
1 |
when(this.installedExtensionRepository.resolve(extensionId)).thenReturn(extension); |
133 |
|
|
134 |
1 |
when(extension.getId()).thenReturn(extensionId); |
135 |
|
|
136 |
1 |
assertSame(extension, this.mocker.getComponentUnderTest().resolveExtension(extensionId)); |
137 |
|
} |
138 |
|
} |