use of org.apache.metron.common.configuration.FieldTransformer in project metron by apache.
the class StellarTransformationTest method testConfigAll.
@Test
public void testConfigAll() throws Exception {
SensorParserConfig c = SensorParserConfig.fromBytes(Bytes.toBytes(configAll));
JSONObject input = new JSONObject();
input.put("source.type", "test");
for (FieldTransformer handler : c.getFieldTransformations()) {
handler.transformAndUpdate(input, Context.EMPTY_CONTEXT());
}
assertEquals(2, input.size());
assertTrue(input.containsKey("new_field"));
assertEquals("test", input.get("new_field"));
}
use of org.apache.metron.common.configuration.FieldTransformer in project metron by apache.
the class RemoveTransformationTest method testConditionalRemove.
@Test
public void testConditionalRemove() throws Exception {
SensorParserConfig c = SensorParserConfig.fromBytes(Bytes.toBytes(removeConditionalConfig));
FieldTransformer handler = Iterables.getFirst(c.getFieldTransformations(), null);
{
JSONObject input = new JSONObject(new HashMap<String, Object>() {
{
put("field1", "foo");
}
});
handler.transformAndUpdate(input, Context.EMPTY_CONTEXT());
// no removal happened because field2 does not exist
assertTrue(input.containsKey("field1"));
assertFalse(input.containsKey("field2"));
}
{
JSONObject input = new JSONObject(new HashMap<String, Object>() {
{
put("field1", "foo");
put("field2", "bar");
}
});
handler.transformAndUpdate(input, Context.EMPTY_CONTEXT());
// no removal happened because field2 != bar
assertTrue(input.containsKey("field1"));
assertTrue(input.containsKey("field2"));
}
{
JSONObject input = new JSONObject(new HashMap<String, Object>() {
{
put("field1", "bar");
put("field2", "foo");
}
});
// removal of field1 happens because field2 exists and is 'bar'
handler.transformAndUpdate(input, Context.EMPTY_CONTEXT());
assertFalse(input.containsKey("field1"));
assertTrue(input.containsKey("field2"));
}
}
use of org.apache.metron.common.configuration.FieldTransformer in project metron by apache.
the class RemoveTransformationTest method testUnconditionalRemove.
@Test
public void testUnconditionalRemove() throws Exception {
SensorParserConfig c = SensorParserConfig.fromBytes(Bytes.toBytes(removeUnconditionalConfig));
FieldTransformer handler = Iterables.getFirst(c.getFieldTransformations(), null);
JSONObject input = new JSONObject(new HashMap<String, Object>() {
{
put("field1", "foo");
}
});
handler.transformAndUpdate(input, Context.EMPTY_CONTEXT());
assertFalse(input.containsKey("field1"));
}
use of org.apache.metron.common.configuration.FieldTransformer in project metron by apache.
the class SelectTransformationTest method testPreserveSystemFields.
@Test
public void testPreserveSystemFields() 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("timestamp", 12345);
put("original_string", "foo,bar");
put("source.type", "test");
put("field1", "foo");
put("field2", "bar");
}
});
handler.transformAndUpdate(input, Context.EMPTY_CONTEXT());
assertTrue(input.containsKey("timestamp"));
assertTrue(input.containsKey("original_string"));
assertTrue(input.containsKey("source.type"));
assertTrue(input.containsKey("field1"));
assertFalse(input.containsKey("field2"));
assertEquals(4, input.size());
}
use of org.apache.metron.common.configuration.FieldTransformer in project metron by apache.
the class RegexSelectTransformationTest method transform.
private String transform(String in, String config) throws Exception {
SensorParserConfig c = SensorParserConfig.fromBytes(Bytes.toBytes(config));
FieldTransformer handler = Iterables.getFirst(c.getFieldTransformations(), null);
JSONObject input = new JSONObject(new HashMap<String, Object>() {
{
put("in_field", in);
// this is added to ensure that it looks like something approaching a real message
put("dummy_field", "dummy");
}
});
handler.transformAndUpdate(input, Context.EMPTY_CONTEXT());
return (String) input.get("out_field");
}
Aggregations