Search in sources :

Example 1 with JestClientManager

use of org.xwiki.activeinstalls.internal.JestClientManager in project xwiki-platform by xwiki.

the class DefaultPingSenderTest method sendPing.

@Test
public void sendPing() throws Exception {
    JestClient client = mock(JestClient.class);
    DocumentResult indexResult = new DocumentResult(new Gson());
    indexResult.setSucceeded(true);
    when(client.execute(any(Index.class))).thenReturn(indexResult);
    JestClientManager jestManager = this.mocker.getInstance(JestClientManager.class);
    when(jestManager.getClient()).thenReturn(client);
    PingDataProvider pingDataProvider = this.mocker.registerMockComponent(PingDataProvider.class, "test");
    this.mocker.getComponentUnderTest().sendPing();
    // Verify that provideMapping() and provideData() are called
    verify(pingDataProvider).provideMapping();
    verify(pingDataProvider).provideData();
}
Also used : DocumentResult(io.searchbox.core.DocumentResult) Gson(com.google.gson.Gson) Index(io.searchbox.core.Index) JestClient(io.searchbox.client.JestClient) JestClientManager(org.xwiki.activeinstalls.internal.JestClientManager) Test(org.junit.Test)

Example 2 with JestClientManager

use of org.xwiki.activeinstalls.internal.JestClientManager 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"));
}
Also used : InstanceIdManager(org.xwiki.instance.InstanceIdManager) InstanceId(org.xwiki.instance.InstanceId) Search(io.searchbox.core.Search) Gson(com.google.gson.Gson) SearchResult(io.searchbox.core.SearchResult) JestClient(io.searchbox.client.JestClient) JestClientManager(org.xwiki.activeinstalls.internal.JestClientManager) JsonParser(com.google.gson.JsonParser) Test(org.junit.Test)

Aggregations

Gson (com.google.gson.Gson)2 JestClient (io.searchbox.client.JestClient)2 Test (org.junit.Test)2 JestClientManager (org.xwiki.activeinstalls.internal.JestClientManager)2 JsonParser (com.google.gson.JsonParser)1 DocumentResult (io.searchbox.core.DocumentResult)1 Index (io.searchbox.core.Index)1 Search (io.searchbox.core.Search)1 SearchResult (io.searchbox.core.SearchResult)1 InstanceId (org.xwiki.instance.InstanceId)1 InstanceIdManager (org.xwiki.instance.InstanceIdManager)1