Search in sources :

Example 11 with CacheKey

use of org.apache.metron.enrichment.cache.CacheKey in project metron by apache.

the class HostFromPropertiesFileAdapterTest method testEnrich.

@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);
}
Also used : JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap) JSONArray(org.json.simple.JSONArray) Iterator(java.util.Iterator) CacheKey(org.apache.metron.enrichment.cache.CacheKey) Test(org.junit.jupiter.api.Test)

Example 12 with CacheKey

use of org.apache.metron.enrichment.cache.CacheKey in project metron by apache.

the class HostFromJSONListAdapterTest method testEnrichNonString.

@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);
}
Also used : JSONObject(org.json.simple.JSONObject) CacheKey(org.apache.metron.enrichment.cache.CacheKey) Test(org.junit.jupiter.api.Test)

Example 13 with CacheKey

use of org.apache.metron.enrichment.cache.CacheKey in project metron by apache.

the class GeoAdapterTest method testEnrichNonString.

@Test
public void testEnrichNonString() {
    JSONObject actualMessage = geo.enrich(new CacheKey("dummy", 10L, null));
    assertEquals(new JSONObject(), actualMessage);
}
Also used : JSONObject(org.json.simple.JSONObject) CacheKey(org.apache.metron.enrichment.cache.CacheKey) Test(org.junit.jupiter.api.Test)

Example 14 with CacheKey

use of org.apache.metron.enrichment.cache.CacheKey in project metron by apache.

the class SimpleHBaseAdapterTest method testMultiColumnFamilies.

@Test
public void testMultiColumnFamilies() throws Exception {
    SimpleHBaseAdapter sha = new SimpleHBaseAdapter();
    sha.lookup = lookup;
    SensorEnrichmentConfig broSc = JSONUtils.INSTANCE.load(sourceConfigWithCFStr, SensorEnrichmentConfig.class);
    JSONObject actualMessage = sha.enrich(new CacheKey("test", "test", broSc));
    assertEquals(actualMessage, new JSONObject());
    actualMessage = sha.enrich(new CacheKey("ip_dst_addr", "10.0.2.4", broSc));
    assertNotNull(actualMessage);
    assertEquals(new JSONObject(ImmutableMap.of("cf1.key", "value")), actualMessage);
}
Also used : JSONObject(org.json.simple.JSONObject) SensorEnrichmentConfig(org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig) CacheKey(org.apache.metron.enrichment.cache.CacheKey) Test(org.junit.jupiter.api.Test)

Example 15 with CacheKey

use of org.apache.metron.enrichment.cache.CacheKey in project metron by apache.

the class SimpleHBaseAdapterTest method testEnrichNonStringValue.

@Test
public void testEnrichNonStringValue() throws Exception {
    SimpleHBaseAdapter sha = new SimpleHBaseAdapter();
    sha.lookup = lookup;
    SensorEnrichmentConfig broSc = JSONUtils.INSTANCE.load(sourceConfigStr, SensorEnrichmentConfig.class);
    JSONObject actualMessage = sha.enrich(new CacheKey("test", "test", broSc));
    assertEquals(actualMessage, new JSONObject());
    actualMessage = sha.enrich(new CacheKey("ip_dst_addr", 10L, broSc));
    assertEquals(actualMessage, new JSONObject());
}
Also used : JSONObject(org.json.simple.JSONObject) SensorEnrichmentConfig(org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig) CacheKey(org.apache.metron.enrichment.cache.CacheKey) Test(org.junit.jupiter.api.Test)

Aggregations

CacheKey (org.apache.metron.enrichment.cache.CacheKey)15 JSONObject (org.json.simple.JSONObject)14 Test (org.junit.jupiter.api.Test)12 SensorEnrichmentConfig (org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig)8 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)2 MetronError (org.apache.metron.common.error.MetronError)2 CacheStats (com.github.benmanes.caffeine.cache.stats.CacheStats)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 AbstractMap (java.util.AbstractMap)1 ArrayList (java.util.ArrayList)1 EnumMap (java.util.EnumMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 StellarAdapter (org.apache.metron.enrichment.adapters.stellar.StellarAdapter)1 Enrichment (org.apache.metron.enrichment.configuration.Enrichment)1