1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.activeinstalls.internal.client; |
21 |
|
|
22 |
|
import java.util.Arrays; |
23 |
|
import java.util.Collections; |
24 |
|
import java.util.Map; |
25 |
|
|
26 |
|
import org.junit.Rule; |
27 |
|
import org.junit.Test; |
28 |
|
import org.xwiki.activeinstalls.internal.client.data.ExtensionPingDataProvider; |
29 |
|
import org.xwiki.extension.ExtensionId; |
30 |
|
import org.xwiki.extension.InstalledExtension; |
31 |
|
import org.xwiki.extension.repository.InstalledExtensionRepository; |
32 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
33 |
|
|
34 |
|
import net.sf.json.JSONArray; |
35 |
|
import net.sf.json.JSONObject; |
36 |
|
|
37 |
|
import static org.junit.Assert.assertArrayEquals; |
38 |
|
import static org.junit.Assert.assertEquals; |
39 |
|
import static org.mockito.Mockito.mock; |
40 |
|
import static org.mockito.Mockito.when; |
41 |
|
|
42 |
|
|
43 |
|
@link |
44 |
|
|
45 |
|
@version |
46 |
|
@since |
47 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (38) |
Complexity: 2 |
Complexity Density: 0.06 |
|
48 |
|
public class ExtensionPingDataProviderTest |
49 |
|
{ |
50 |
|
@Rule |
51 |
|
public MockitoComponentMockingRule<ExtensionPingDataProvider> mocker = |
52 |
|
new MockitoComponentMockingRule<>(ExtensionPingDataProvider.class); |
53 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
54 |
1 |
@Test... |
55 |
|
public void provideMapping() throws Exception |
56 |
|
{ |
57 |
1 |
Map<String, Object> mapping = this.mocker.getComponentUnderTest().provideMapping(); |
58 |
1 |
assertEquals(1, mapping.size()); |
59 |
|
|
60 |
1 |
Map<String, Object> extensionsMapping = (Map<String, Object>) mapping.get("extensions"); |
61 |
1 |
assertEquals(1, extensionsMapping.size()); |
62 |
|
|
63 |
1 |
Map<String, Object> propertiesMapping = (Map<String, Object>) extensionsMapping.get("properties"); |
64 |
1 |
assertEquals(3, propertiesMapping.size()); |
65 |
|
|
66 |
1 |
Map<String, Object> propertyMapping = (Map<String, Object>) propertiesMapping.get("id"); |
67 |
1 |
assertEquals(2, propertyMapping.size()); |
68 |
1 |
assertEquals("not_analyzed", propertyMapping.get("index")); |
69 |
1 |
assertEquals("string", propertyMapping.get("type")); |
70 |
|
|
71 |
1 |
propertyMapping = (Map<String, Object>) propertiesMapping.get("version"); |
72 |
1 |
assertEquals(2, propertyMapping.size()); |
73 |
1 |
assertEquals("not_analyzed", propertyMapping.get("index")); |
74 |
1 |
assertEquals("string", propertyMapping.get("type")); |
75 |
|
|
76 |
1 |
propertyMapping = (Map<String, Object>) propertiesMapping.get("features"); |
77 |
1 |
assertEquals(2, propertyMapping.size()); |
78 |
1 |
assertEquals("not_analyzed", propertyMapping.get("index")); |
79 |
1 |
assertEquals("string", propertyMapping.get("type")); |
80 |
|
} |
81 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
82 |
1 |
@Test... |
83 |
|
public void provideData() throws Exception |
84 |
|
{ |
85 |
1 |
ExtensionId extensionId = new ExtensionId("extensionid", "1.0"); |
86 |
1 |
InstalledExtension extension = mock(InstalledExtension.class); |
87 |
1 |
when(extension.getId()).thenReturn(extensionId); |
88 |
1 |
when(extension.getFeatures()).thenReturn(Arrays.asList("feature1", "feature2")); |
89 |
|
|
90 |
1 |
InstalledExtensionRepository repository = this.mocker.getInstance(InstalledExtensionRepository.class); |
91 |
1 |
when(repository.getInstalledExtensions()).thenReturn(Collections.singletonList(extension)); |
92 |
|
|
93 |
1 |
Map<String, Object> data = this.mocker.getComponentUnderTest().provideData(); |
94 |
1 |
assertEquals(1, data.size()); |
95 |
1 |
JSONObject[] extensions = (JSONObject[]) data.get("extensions"); |
96 |
1 |
assertEquals(1, extensions.length); |
97 |
1 |
JSONObject propertiesData = extensions[0]; |
98 |
1 |
assertEquals(3, propertiesData.size()); |
99 |
1 |
assertEquals("extensionid", propertiesData.get("id")); |
100 |
1 |
assertEquals("1.0", propertiesData.get("version")); |
101 |
1 |
JSONArray features = (JSONArray) propertiesData.get("features"); |
102 |
1 |
assertEquals(2, features.size()); |
103 |
1 |
assertEquals("feature1", features.get(0)); |
104 |
1 |
assertEquals("feature2", features.get(1)); |
105 |
|
} |
106 |
|
} |