use of org.xwiki.instance.InstanceIdManager in project xwiki-platform by xwiki.
the class DatePingDataProviderTest method provideData.
@Test
public void provideData() throws Exception {
InstanceId id = new InstanceId(UUID.randomUUID().toString());
InstanceIdManager idManager = this.mocker.getInstance(InstanceIdManager.class);
when(idManager.getInstanceId()).thenReturn(id);
JestClient client = mock(JestClient.class);
SearchResult searchResult = new SearchResult(new Gson());
String resultString = "{\n" + " \"took\": 4,\n" + " \"timed_out\": false,\n" + " \"_shards\": {\n" + " \"total\": 5,\n" + " \"successful\": 5,\n" + " \"failed\": 0\n" + " },\n" + " \"hits\": {\n" + " \"total\": 2,\n" + " \"max_score\": 0,\n" + " \"hits\": []\n" + " },\n" + " \"aggregations\": {\n" + " \"firstPingDate\": {\n" + " \"value\": 1392854400000\n" + " },\n" + " \"serverTime\": {\n" + " \"value\": 1393200000000\n" + " }\n" + " }\n" + "}";
searchResult.setJsonString(resultString);
searchResult.setJsonObject(new JsonParser().parse(resultString).getAsJsonObject());
searchResult.setSucceeded(true);
when(client.execute(any(Search.class))).thenReturn(searchResult);
JestClientManager jestManager = this.mocker.getInstance(JestClientManager.class);
when(jestManager.getClient()).thenReturn(client);
Map<String, Object> data = this.mocker.getComponentUnderTest().provideData();
assertEquals(2, data.size());
assertEquals(4L, data.get("sinceDays"));
assertEquals(1392854400000L, data.get("firstPingDate"));
}
use of org.xwiki.instance.InstanceIdManager in project xwiki-platform by xwiki.
the class DistributionPingDataProviderTest method provideData.
@Test
public void provideData() throws Exception {
InstanceId id = new InstanceId(UUID.randomUUID().toString());
InstanceIdManager idManager = this.mocker.getInstance(InstanceIdManager.class);
when(idManager.getInstanceId()).thenReturn(id);
ExtensionId environmentExtensionId = new ExtensionId("environmentextensionid", "2.0");
CoreExtension environmentExtension = mock(CoreExtension.class);
when(environmentExtension.getId()).thenReturn(environmentExtensionId);
CoreExtensionRepository CoreExtensionRepository = this.mocker.getInstance(CoreExtensionRepository.class);
when(CoreExtensionRepository.getEnvironmentExtension()).thenReturn(environmentExtension);
Map<String, Object> data = this.mocker.getComponentUnderTest().provideData();
assertEquals(3, data.size());
assertEquals("environmentextensionid", data.get("distributionId"));
assertEquals("2.0", data.get("distributionVersion"));
assertEquals(id.getInstanceId(), data.get("instanceId"));
}
Aggregations