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());
assertFalse(input.containsKey("utc_timestamp"));
assertTrue(input.isEmpty());
}
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());
assertTrue(input.containsKey("field1"));
assertTrue(input.containsKey("field2"));
assertFalse(input.containsKey("field3"));
assertEquals(2, input.size());
}
use of org.apache.metron.common.configuration.SensorParserConfig 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());
}
use of org.apache.metron.common.configuration.SensorParserConfig in project metron by apache.
the class ParserFunctionsTest method testInitFromMap.
@Test
public void testInitFromMap() throws Exception {
Map<String, Object> configAsMap = (JSONObject) new JSONParser().parse(broParserConfig);
set("configAsMap", configAsMap);
StellarParserRunner runner = execute("PARSER_INIT('bro', configAsMap)", StellarParserRunner.class);
assertNotNull(runner);
SensorParserConfig actual = runner.getParserConfigurations().getSensorParserConfig("bro");
SensorParserConfig expected = SensorParserConfig.fromBytes(broParserConfig.getBytes(StandardCharsets.UTF_8));
assertEquals(expected, actual);
}
use of org.apache.metron.common.configuration.SensorParserConfig in project metron by apache.
the class SensorParserGroupServiceImplTest method shouldSaveExistingGroup.
@Test
public void shouldSaveExistingGroup() throws Exception {
SensorParserGroup oldGroup = new SensorParserGroup();
oldGroup.setName("oldGroup");
oldGroup.setDescription("old description");
oldGroup.setSensors(Collections.singleton("oldSensor"));
ParserConfigurations parserConfigurations = mock(ParserConfigurations.class);
when(cache.get(ParserConfigurations.class)).thenReturn(new ParserConfigurations());
when(parserConfigurations.getSensorParserGroups()).thenReturn(new HashMap<String, SensorParserGroup>() {
{
put("newSensor", oldGroup);
}
});
when(sensorParserConfigService.findOne("newSensor")).thenReturn(new SensorParserConfig());
SensorParserGroup newGroup = new SensorParserGroup();
newGroup.setName("newGroup");
newGroup.setDescription("new description");
newGroup.setSensors(Collections.singleton("newSensor"));
Map<String, Object> expectedGlobalConfig = new HashMap<>();
Collection<SensorParserGroup> expectedGroup = Collections.singleton(newGroup);
expectedGlobalConfig.put(PARSER_GROUPS_CONF, expectedGroup);
assertEquals(newGroup, sensorParserGroupService.save(newGroup));
verify(globalConfigService, times(1)).save(expectedGlobalConfig);
verifyNoMoreInteractions(globalConfigService);
}
Aggregations