HostFromJSONListAdapter extends AbstractHostAdapter { @SuppressWarnings("unchecked") @Override public JSONObject enrich(CacheKey k) { String metadata = k.coerceValue(String.class); if(!_known_hosts.containsKey(metadata)) return new JSONObject(); JSONObject enrichment = new JSONObject(); String prefix = "known_info."; JSONObject knownInfo = _known_hosts.get(metadata); for(Object key: knownInfo.keySet()) { enrichment.put(prefix + key, knownInfo.get(key)); } return enrichment; } HostFromJSONListAdapter(String jsonList); @Override String getOutputPrefix(CacheKey value); @Override boolean initializeAdapter(Map<String, Object> config); @Override void updateAdapter(Map<String, Object> config); @Override void logAccess(CacheKey value); @SuppressWarnings("unchecked") @Override JSONObject enrich(CacheKey k);  }
@Test public void testEnrich() { HostFromJSONListAdapter hja = new HostFromJSONListAdapter(expectedKnownHostsString); JSONObject actualMessage = hja.enrich(new CacheKey("dummy", ip, null)); assertNotNull(actualMessage); assertEquals(expectedMessage, actualMessage); actualMessage = hja.enrich(new CacheKey("dummy", ip1, null)); JSONObject emptyJson = new JSONObject(); assertEquals(emptyJson, actualMessage); }
@Test public void testEnrichNonString() { HostFromJSONListAdapter hja = new HostFromJSONListAdapter(expectedKnownHostsString); JSONObject actualMessage = hja.enrich(new CacheKey("dummy", ip, null)); assertNotNull(actualMessage); assertEquals(expectedMessage, actualMessage); actualMessage = hja.enrich(new CacheKey("dummy", 10L, null)); JSONObject emptyJson = new JSONObject(); assertEquals(emptyJson, actualMessage); }