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.Map; |
23 |
|
import java.util.UUID; |
24 |
|
|
25 |
|
import org.junit.Rule; |
26 |
|
import org.junit.Test; |
27 |
|
import org.xwiki.activeinstalls.internal.client.data.DistributionPingDataProvider; |
28 |
|
import org.xwiki.extension.CoreExtension; |
29 |
|
import org.xwiki.extension.ExtensionId; |
30 |
|
import org.xwiki.extension.repository.CoreExtensionRepository; |
31 |
|
import org.xwiki.instance.InstanceId; |
32 |
|
import org.xwiki.instance.InstanceIdManager; |
33 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
34 |
|
|
35 |
|
import static org.junit.Assert.assertEquals; |
36 |
|
import static org.mockito.Mockito.mock; |
37 |
|
import static org.mockito.Mockito.when; |
38 |
|
|
39 |
|
|
40 |
|
@link |
41 |
|
|
42 |
|
@version |
43 |
|
@since |
44 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (29) |
Complexity: 2 |
Complexity Density: 0.07 |
|
45 |
|
public class DistributionPingDataProviderTest |
46 |
|
{ |
47 |
|
@Rule |
48 |
|
public MockitoComponentMockingRule<DistributionPingDataProvider> mocker = |
49 |
|
new MockitoComponentMockingRule<>(DistributionPingDataProvider.class); |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
51 |
1 |
@Test... |
52 |
|
public void provideMapping() throws Exception |
53 |
|
{ |
54 |
1 |
Map<String, Object> mapping = this.mocker.getComponentUnderTest().provideMapping(); |
55 |
1 |
assertEquals(4, mapping.size()); |
56 |
|
|
57 |
1 |
Map<String, Object> propertiesMapping = (Map<String, Object>) mapping.get("distributionId"); |
58 |
1 |
assertEquals(2, propertiesMapping.size()); |
59 |
1 |
assertEquals("not_analyzed", propertiesMapping.get("index")); |
60 |
1 |
assertEquals("string", propertiesMapping.get("type")); |
61 |
|
|
62 |
1 |
propertiesMapping = (Map<String, Object>) mapping.get("distributionVersion"); |
63 |
1 |
assertEquals(2, propertiesMapping.size()); |
64 |
1 |
assertEquals("not_analyzed", propertiesMapping.get("index")); |
65 |
1 |
assertEquals("string", propertiesMapping.get("type")); |
66 |
|
|
67 |
1 |
propertiesMapping = (Map<String, Object>) mapping.get("instanceId"); |
68 |
1 |
assertEquals(2, propertiesMapping.size()); |
69 |
1 |
assertEquals("not_analyzed", propertiesMapping.get("index")); |
70 |
1 |
assertEquals("string", propertiesMapping.get("type")); |
71 |
|
} |
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
73 |
1 |
@Test... |
74 |
|
public void provideData() throws Exception |
75 |
|
{ |
76 |
1 |
InstanceId id = new InstanceId(UUID.randomUUID().toString()); |
77 |
1 |
InstanceIdManager idManager = this.mocker.getInstance(InstanceIdManager.class); |
78 |
1 |
when(idManager.getInstanceId()).thenReturn(id); |
79 |
|
|
80 |
1 |
ExtensionId environmentExtensionId = new ExtensionId("environmentextensionid", "2.0"); |
81 |
1 |
CoreExtension environmentExtension = mock(CoreExtension.class); |
82 |
1 |
when(environmentExtension.getId()).thenReturn(environmentExtensionId); |
83 |
1 |
CoreExtensionRepository CoreExtensionRepository = this.mocker.getInstance(CoreExtensionRepository.class); |
84 |
1 |
when(CoreExtensionRepository.getEnvironmentExtension()).thenReturn(environmentExtension); |
85 |
|
|
86 |
1 |
Map<String, Object> data = this.mocker.getComponentUnderTest().provideData(); |
87 |
1 |
assertEquals(3, data.size()); |
88 |
1 |
assertEquals("environmentextensionid", data.get("distributionId")); |
89 |
1 |
assertEquals("2.0", data.get("distributionVersion")); |
90 |
1 |
assertEquals(id.getInstanceId(), data.get("instanceId")); |
91 |
|
} |
92 |
|
} |