use of org.apache.metron.common.configuration.SensorParserConfig in project metron by apache.
the class SelectTransformationTest method testMulitpleFieldReturned.
@Test
public void testMulitpleFieldReturned() throws Exception {
SensorParserConfig sensorConfig = SensorParserConfig.fromBytes(Bytes.toBytes(selectMultiFieldConfig));
FieldTransformer handler = Iterables.getFirst(sensorConfig.getFieldTransformations(), null);
JSONObject input = new JSONObject(new HashMap<String, Object>() {
{
put("field1", "foo");
put("field2", "bar");
put("field3", "bar2");
}
});
handler.transformAndUpdate(input, Context.EMPTY_CONTEXT());
Assert.assertTrue(input.containsKey("field1"));
Assert.assertTrue(input.containsKey("field2"));
Assert.assertFalse(input.containsKey("field3"));
Assert.assertEquals(2, input.size());
}
use of org.apache.metron.common.configuration.SensorParserConfig in project metron by apache.
the class StellarTransformationTest method testStellar_negative.
/**
* Ensures that if we try to transform with a field which does not exist, it does not
* 1. throw an exception
* 2. do any transformation.
*/
@Test
public void testStellar_negative() throws Exception {
SensorParserConfig c = SensorParserConfig.fromBytes(Bytes.toBytes(stellarConfig));
FieldTransformer handler = Iterables.getFirst(c.getFieldTransformations(), null);
// no input fields => no transformation
JSONObject input = new JSONObject(new HashMap<String, Object>() {
{
}
});
handler.transformAndUpdate(input, Context.EMPTY_CONTEXT());
Assert.assertFalse(input.containsKey("utc_timestamp"));
Assert.assertTrue(input.isEmpty());
}
use of org.apache.metron.common.configuration.SensorParserConfig in project metron by apache.
the class StellarTransformationTest method testStellarSpecialCharacters.
@Test
public void testStellarSpecialCharacters() throws Exception {
SensorParserConfig c = SensorParserConfig.fromBytes(Bytes.toBytes(stellarConfigEspecial));
FieldTransformer handler = Iterables.getFirst(c.getFieldTransformations(), null);
JSONObject input = new JSONObject(new HashMap<String, Object>() {
{
put("timestamp", "2016-01-05 17:02:30");
}
});
handler.transformAndUpdate(input, Context.EMPTY_CONTEXT());
long expected = 1452013350000L;
Assert.assertEquals(expected, input.get("utc_timestamp"));
Assert.assertTrue(input.containsKey("timestamp"));
Assert.assertTrue(input.containsKey("newStellarField"));
}
use of org.apache.metron.common.configuration.SensorParserConfig in project metron by apache.
the class StellarTransformationTest method testStellarNumericDomain.
@Test
public void testStellarNumericDomain() throws Exception {
/*
Despite the domain being weird, URL_TO_HOST should allow it to pass through.
However, because it does NOT form a proper domain (no TLD), DOMAIN_REMOVE_SUBDOMAINS returns
null indicating that the input is semantically incorrect.
*/
SensorParserConfig c = SensorParserConfig.fromBytes(Bytes.toBytes(configNumericDomain));
FieldTransformer handler = Iterables.getFirst(c.getFieldTransformations(), null);
JSONObject input = new JSONObject();
handler.transformAndUpdate(input, Context.EMPTY_CONTEXT());
Assert.assertTrue(input.containsKey("full_hostname"));
Assert.assertEquals("1234567890123456789012345678901234567890123456789012345678901234567890", input.get("full_hostname"));
Assert.assertFalse(input.containsKey("domain_without_subdomains"));
}
use of org.apache.metron.common.configuration.SensorParserConfig in project metron by apache.
the class StellarTransformationTest method testStellarBadConfig.
@Test(expected = IllegalStateException.class)
public void testStellarBadConfig() throws Exception {
SensorParserConfig c = SensorParserConfig.fromBytes(Bytes.toBytes(badConfig));
FieldTransformer handler = Iterables.getFirst(c.getFieldTransformations(), null);
JSONObject input = new JSONObject();
try {
handler.transformAndUpdate(input, Context.EMPTY_CONTEXT());
} catch (IllegalStateException ex) {
Assert.assertTrue(ex.getMessage().contains("URL_TO_HOST"));
Assert.assertTrue(ex.getMessage().contains("123"));
throw ex;
}
}
Aggregations