use of org.apache.metron.common.configuration.FieldTransformer 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;
assertEquals(expected, input.get("utc_timestamp"));
assertTrue(input.containsKey("timestamp"));
assertTrue(input.containsKey("newStellarField"));
}
use of org.apache.metron.common.configuration.FieldTransformer in project metron by apache.
the class StellarTransformationTest method testStellarBadConfig.
@Test
public void testStellarBadConfig() throws Exception {
SensorParserConfig c = SensorParserConfig.fromBytes(Bytes.toBytes(badConfig));
FieldTransformer handler = Iterables.getFirst(c.getFieldTransformations(), null);
JSONObject input = new JSONObject();
IllegalStateException ex = assertThrows(IllegalStateException.class, () -> handler.transformAndUpdate(input, Context.EMPTY_CONTEXT()));
assertTrue(ex.getMessage().contains("URL_TO_HOST"));
assertTrue(ex.getMessage().contains("123"));
}
use of org.apache.metron.common.configuration.FieldTransformer 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());
assertFalse(input.containsKey("utc_timestamp"));
assertTrue(input.isEmpty());
}
use of org.apache.metron.common.configuration.FieldTransformer 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());
assertTrue(input.containsKey("field1"));
assertTrue(input.containsKey("field2"));
assertFalse(input.containsKey("field3"));
assertEquals(2, input.size());
}
use of org.apache.metron.common.configuration.FieldTransformer in project metron by apache.
the class SelectTransformationTest method testSingleFieldReturned.
@Test
public void testSingleFieldReturned() throws Exception {
SensorParserConfig sensorConfig = SensorParserConfig.fromBytes(Bytes.toBytes(selectSingleFieldConfig));
FieldTransformer handler = Iterables.getFirst(sensorConfig.getFieldTransformations(), null);
JSONObject input = new JSONObject(new HashMap<String, Object>() {
{
put("field1", "foo");
put("field2", "bar");
}
});
handler.transformAndUpdate(input, Context.EMPTY_CONTEXT());
assertTrue(input.containsKey("field1"));
assertFalse(input.containsKey("field2"));
assertEquals(1, input.size());
}
Aggregations