1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.extension.repository.core; |
21 |
|
|
22 |
|
import org.junit.Assert; |
23 |
|
import org.junit.Before; |
24 |
|
import org.junit.Rule; |
25 |
|
import org.junit.Test; |
26 |
|
import org.xwiki.environment.Environment; |
27 |
|
import org.xwiki.extension.Extension; |
28 |
|
import org.xwiki.extension.ExtensionId; |
29 |
|
import org.xwiki.extension.ResolveException; |
30 |
|
import org.xwiki.extension.repository.CoreExtensionRepository; |
31 |
|
import org.xwiki.extension.repository.result.IterableResult; |
32 |
|
import org.xwiki.extension.repository.search.SearchException; |
33 |
|
import org.xwiki.extension.test.ConfigurableDefaultCoreExtensionRepository; |
34 |
|
import org.xwiki.extension.version.internal.DefaultVersion; |
35 |
|
import org.xwiki.test.annotation.AllComponents; |
36 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
37 |
|
|
38 |
|
import static org.junit.Assert.assertEquals; |
39 |
|
|
40 |
|
@AllComponents |
|
|
| 93.1% |
Uncovered Elements: 2 (29) |
Complexity: 7 |
Complexity Density: 0.29 |
|
41 |
|
public class DefaultCoreExtensionRepositoryTest |
42 |
|
{ |
43 |
|
@Rule |
44 |
|
public MockitoComponentMockingRule<CoreExtensionRepository> mocker = |
45 |
|
new MockitoComponentMockingRule<CoreExtensionRepository>(ConfigurableDefaultCoreExtensionRepository.class); |
46 |
|
|
47 |
|
private ConfigurableDefaultCoreExtensionRepository coreExtensionRepository; |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
52 |
1 |
@Test... |
53 |
|
public void testInit() |
54 |
|
{ |
55 |
1 |
Assert.assertTrue(this.coreExtensionRepository.countExtensions() > 0); |
56 |
|
} |
57 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
58 |
4 |
@Before... |
59 |
|
public void before() throws Exception |
60 |
|
{ |
61 |
4 |
this.mocker.registerMockComponent(Environment.class); |
62 |
|
|
63 |
4 |
this.coreExtensionRepository = |
64 |
|
(ConfigurableDefaultCoreExtensionRepository) this.mocker.getInstance(CoreExtensionRepository.class); |
65 |
|
} |
66 |
|
|
67 |
|
|
68 |
|
@link |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
70 |
1 |
@Test... |
71 |
|
public void testGetCoreExtension() |
72 |
|
{ |
73 |
1 |
Assert.assertNull(this.coreExtensionRepository.getCoreExtension("unexistingextension")); |
74 |
|
|
75 |
1 |
this.coreExtensionRepository.addExtensions("existingextension", new DefaultVersion("version")); |
76 |
|
|
77 |
1 |
Extension extension = this.coreExtensionRepository.getCoreExtension("existingextension"); |
78 |
|
|
79 |
1 |
Assert.assertNotNull(extension); |
80 |
1 |
Assert.assertEquals("existingextension", extension.getId().getId()); |
81 |
1 |
Assert.assertEquals("version", extension.getId().getVersion().getValue()); |
82 |
|
} |
83 |
|
|
84 |
|
|
85 |
|
@link |
86 |
|
|
|
|
| 81.8% |
Uncovered Elements: 2 (11) |
Complexity: 3 |
Complexity Density: 0.27 |
1PASS
|
|
87 |
1 |
@Test... |
88 |
|
public void testResolve() throws ResolveException |
89 |
|
{ |
90 |
1 |
try { |
91 |
1 |
this.coreExtensionRepository.resolve(new ExtensionId("unexistingextension", "version")); |
92 |
|
|
93 |
0 |
Assert.fail("Resolve should have failed"); |
94 |
|
} catch (ResolveException expected) { |
95 |
|
|
96 |
|
} |
97 |
|
|
98 |
1 |
this.coreExtensionRepository.addExtensions("existingextension", new DefaultVersion("version")); |
99 |
|
|
100 |
1 |
try { |
101 |
1 |
this.coreExtensionRepository.resolve(new ExtensionId("existingextension", "wrongversion")); |
102 |
|
|
103 |
0 |
Assert.fail("Resolve should have failed"); |
104 |
|
} catch (ResolveException expected) { |
105 |
|
|
106 |
|
} |
107 |
|
|
108 |
1 |
Extension extension = this.coreExtensionRepository.resolve(new ExtensionId("existingextension", "version")); |
109 |
|
|
110 |
1 |
Assert.assertNotNull(extension); |
111 |
1 |
Assert.assertEquals("existingextension", extension.getId().getId()); |
112 |
1 |
Assert.assertEquals("version", extension.getId().getVersion().getValue()); |
113 |
|
} |
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
@throws |
119 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
120 |
1 |
@Test... |
121 |
|
public void testSearchWithSeveralFeatures() throws SearchException |
122 |
|
{ |
123 |
1 |
this.coreExtensionRepository.addExtensions("extension", new DefaultVersion("version"), |
124 |
|
new ExtensionId("testfeature1"), new ExtensionId("testfeature2")); |
125 |
|
|
126 |
1 |
IterableResult<Extension> result = this.coreExtensionRepository.search("testfeature", 0, -1); |
127 |
|
|
128 |
1 |
assertEquals(1, result.getTotalHits()); |
129 |
1 |
assertEquals(1, result.getSize()); |
130 |
|
} |
131 |
|
} |