@Test public void constructSearchJson() { String instanceId = "c5471b1d-bc03-4e35-b11e-ac89db67a3a1"; String searchJson = provider.constructSearchJSON(instanceId); String expectedResult = "{" + "\"query\":{" + "\"term\":{" + "\"instanceId\":\"c5471b1d-bc03-4e35-b11e-ac89db67a3a1\"" + "}" + "}," + "\"aggs\":{" + "\"firstPingDate\":{" + "\"min\":{" + "\"field\":\"_timestamp\"" + "}" + "}," + "\"serverTime\":{" + "\"min\":{" + "\"script\":\"time()\"" + "}" + "}" + "}" + "}"; assertEquals(expectedResult, searchJson); }
protected String constructSearchJSON(String instanceId) { Map<String, Object> jsonMap = new HashMap<>(); jsonMap.put("query", Collections.singletonMap("term", Collections.singletonMap("instanceId", instanceId))); Map<String, Object> aggsMap = new HashMap<>(); aggsMap.put(PROPERTY_SERVER_TIME, Collections.singletonMap(PROPERTY_MIN, Collections.singletonMap("script", "time()"))); aggsMap.put(PROPERTY_FIRST_PING_DATE, Collections.singletonMap(PROPERTY_MIN, Collections.singletonMap("field", "_timestamp"))); jsonMap.put("aggs", aggsMap); return JSONObject.fromObject(jsonMap).toString(); }
DatePingDataProvider implements PingDataProvider { protected String constructSearchJSON(String instanceId) { Map<String, Object> jsonMap = new HashMap<>(); jsonMap.put("query", Collections.singletonMap("term", Collections.singletonMap("instanceId", instanceId))); Map<String, Object> aggsMap = new HashMap<>(); aggsMap.put(PROPERTY_SERVER_TIME, Collections.singletonMap(PROPERTY_MIN, Collections.singletonMap("script", "time()"))); aggsMap.put(PROPERTY_FIRST_PING_DATE, Collections.singletonMap(PROPERTY_MIN, Collections.singletonMap("field", "_timestamp"))); jsonMap.put("aggs", aggsMap); return JSONObject.fromObject(jsonMap).toString(); } }
DatePingDataProvider implements PingDataProvider { protected String constructSearchJSON(String instanceId) { Map<String, Object> jsonMap = new HashMap<>(); jsonMap.put("query", Collections.singletonMap("term", Collections.singletonMap("instanceId", instanceId))); Map<String, Object> aggsMap = new HashMap<>(); aggsMap.put(PROPERTY_SERVER_TIME, Collections.singletonMap(PROPERTY_MIN, Collections.singletonMap("script", "time()"))); aggsMap.put(PROPERTY_FIRST_PING_DATE, Collections.singletonMap(PROPERTY_MIN, Collections.singletonMap("field", "_timestamp"))); jsonMap.put("aggs", aggsMap); return JSONObject.fromObject(jsonMap).toString(); }  }
DatePingDataProvider implements PingDataProvider { protected String constructSearchJSON(String instanceId) { Map<String, Object> jsonMap = new HashMap<>(); jsonMap.put("query", Collections.singletonMap("term", Collections.singletonMap("instanceId", instanceId))); Map<String, Object> aggsMap = new HashMap<>(); aggsMap.put(PROPERTY_SERVER_TIME, Collections.singletonMap(PROPERTY_MIN, Collections.singletonMap("script", "time()"))); aggsMap.put(PROPERTY_FIRST_PING_DATE, Collections.singletonMap(PROPERTY_MIN, Collections.singletonMap("field", "_timestamp"))); jsonMap.put("aggs", aggsMap); return JSONObject.fromObject(jsonMap).toString(); }  @Override Map<String, Object> provideMapping(); @Override Map<String, Object> provideData(); }
DatePingDataProvider implements PingDataProvider { protected String constructSearchJSON(String instanceId) { Map<String, Object> jsonMap = new HashMap<>(); jsonMap.put("query", Collections.singletonMap("term", Collections.singletonMap("instanceId", instanceId))); Map<String, Object> aggsMap = new HashMap<>(); aggsMap.put(PROPERTY_SERVER_TIME, Collections.singletonMap(PROPERTY_MIN, Collections.singletonMap("script", "time()"))); aggsMap.put(PROPERTY_FIRST_PING_DATE, Collections.singletonMap(PROPERTY_MIN, Collections.singletonMap("field", "_timestamp"))); jsonMap.put("aggs", aggsMap); return JSONObject.fromObject(jsonMap).toString(); }  @Override Map<String, Object> provideMapping(); @Override Map<String, Object> provideData();  }