HostFromPropertiesFileAdapter extends AbstractHostAdapter { @SuppressWarnings("unchecked") @Override public JSONObject enrich(CacheKey metadata) { if(!_known_hosts.containsKey(metadata.getValue())) return new JSONObject(); JSONObject enrichment = new JSONObject(); enrichment.put("known_info", (JSONObject) _known_hosts.get(metadata.getValue())); return enrichment; } HostFromPropertiesFileAdapter(Map<String, JSONObject> known_hosts); @Override boolean initializeAdapter(Map<String, Object> config); @Override void updateAdapter(Map<String, Object> config); @Override String getOutputPrefix(CacheKey value); @Override void logAccess(CacheKey value); @SuppressWarnings("unchecked") @Override JSONObject enrich(CacheKey metadata);  }
@Test public void testEnrich() { Map<String, JSONObject> mapKnownHosts = new HashMap<>(); JSONArray jsonArray = (JSONArray) JSONValue.parse(expectedKnownHostsString); Iterator jsonArrayIterator = jsonArray.iterator(); while(jsonArrayIterator.hasNext()) { JSONObject jsonObject = (JSONObject) jsonArrayIterator.next(); String host = (String) jsonObject.remove("ip"); mapKnownHosts.put(host, jsonObject); } HostFromPropertiesFileAdapter hfa = new HostFromPropertiesFileAdapter(mapKnownHosts); JSONObject actualMessage = hfa.enrich(new CacheKey("dummy", ip, null)); assertNotNull(actualMessage); assertEquals(expectedMessage, actualMessage); actualMessage = hfa.enrich(new CacheKey("dummy", ip1, null)); JSONObject emptyJson = new JSONObject(); assertEquals(emptyJson, actualMessage); }