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.JestClientManager; |
28 |
|
import org.xwiki.activeinstalls.internal.client.data.DatePingDataProvider; |
29 |
|
import org.xwiki.instance.InstanceId; |
30 |
|
import org.xwiki.instance.InstanceIdManager; |
31 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
32 |
|
|
33 |
|
import com.google.gson.Gson; |
34 |
|
import com.google.gson.JsonParser; |
35 |
|
|
36 |
|
import io.searchbox.client.JestClient; |
37 |
|
import io.searchbox.core.Search; |
38 |
|
import io.searchbox.core.SearchResult; |
39 |
|
|
40 |
|
import static org.junit.Assert.assertEquals; |
41 |
|
import static org.mockito.ArgumentMatchers.any; |
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 (26) |
Complexity: 2 |
Complexity Density: 0.08 |
|
51 |
|
public class DatePingDataProviderTest |
52 |
|
{ |
53 |
|
@Rule |
54 |
|
public MockitoComponentMockingRule<DatePingDataProvider> mocker = |
55 |
|
new MockitoComponentMockingRule<>(DatePingDataProvider.class); |
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
57 |
1 |
@Test... |
58 |
|
public void provideMapping() throws Exception |
59 |
|
{ |
60 |
1 |
Map<String, Object> mapping = this.mocker.getComponentUnderTest().provideMapping(); |
61 |
1 |
assertEquals(2, mapping.size()); |
62 |
|
|
63 |
1 |
Map<String, Object> propertiesMapping = (Map<String, Object>) mapping.get("sinceDays"); |
64 |
1 |
assertEquals(1, propertiesMapping.size()); |
65 |
1 |
assertEquals("long", propertiesMapping.get("type")); |
66 |
|
|
67 |
1 |
propertiesMapping = (Map<String, Object>) mapping.get("firstPingDate"); |
68 |
1 |
assertEquals(1, propertiesMapping.size()); |
69 |
1 |
assertEquals("date", propertiesMapping.get("type")); |
70 |
|
} |
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
72 |
1 |
@Test... |
73 |
|
public void provideData() throws Exception |
74 |
|
{ |
75 |
1 |
InstanceId id = new InstanceId(UUID.randomUUID().toString()); |
76 |
1 |
InstanceIdManager idManager = this.mocker.getInstance(InstanceIdManager.class); |
77 |
1 |
when(idManager.getInstanceId()).thenReturn(id); |
78 |
|
|
79 |
1 |
JestClient client = mock(JestClient.class); |
80 |
1 |
SearchResult searchResult = new SearchResult(new Gson()); |
81 |
1 |
String resultString = "{\n" + |
82 |
|
" \"took\": 4,\n" + |
83 |
|
" \"timed_out\": false,\n" + |
84 |
|
" \"_shards\": {\n" + |
85 |
|
" \"total\": 5,\n" + |
86 |
|
" \"successful\": 5,\n" + |
87 |
|
" \"failed\": 0\n" + |
88 |
|
" },\n" + |
89 |
|
" \"hits\": {\n" + |
90 |
|
" \"total\": 2,\n" + |
91 |
|
" \"max_score\": 0,\n" + |
92 |
|
" \"hits\": []\n" + |
93 |
|
" },\n" + |
94 |
|
" \"aggregations\": {\n" + |
95 |
|
" \"firstPingDate\": {\n" + |
96 |
|
" \"value\": 1392854400000\n" + |
97 |
|
" },\n" + |
98 |
|
" \"serverTime\": {\n" + |
99 |
|
" \"value\": 1393200000000\n" + |
100 |
|
" }\n" + |
101 |
|
" }\n" + |
102 |
|
"}"; |
103 |
1 |
searchResult.setJsonString(resultString); |
104 |
1 |
searchResult.setJsonObject(new JsonParser().parse(resultString).getAsJsonObject()); |
105 |
1 |
searchResult.setSucceeded(true); |
106 |
1 |
when(client.execute(any(Search.class))).thenReturn(searchResult); |
107 |
|
|
108 |
1 |
JestClientManager jestManager = this.mocker.getInstance(JestClientManager.class); |
109 |
1 |
when(jestManager.getClient()).thenReturn(client); |
110 |
|
|
111 |
1 |
Map<String, Object> data = this.mocker.getComponentUnderTest().provideData(); |
112 |
1 |
assertEquals(2, data.size()); |
113 |
1 |
assertEquals(4L, data.get("sinceDays")); |
114 |
1 |
assertEquals(1392854400000L, data.get("firstPingDate")); |
115 |
|
} |
116 |
|
} |