use of org.apache.metron.common.configuration.SensorParserConfig in project metron by apache.
the class SensorParserGroupServiceImplTest method saveShouldThrowExceptionOnSensorInAnotherGroup.
@Test
public void saveShouldThrowExceptionOnSensorInAnotherGroup() throws Exception {
SensorParserGroup existingGroup = new SensorParserGroup();
existingGroup.setName("existingGroup");
existingGroup.setSensors(Collections.singleton("bro"));
ParserConfigurations parserConfigurations = mock(ParserConfigurations.class);
when(parserConfigurations.getSensorParserGroups()).thenReturn(new HashMap<String, SensorParserGroup>() {
{
put("existingGroup", existingGroup);
}
});
when(cache.get(ParserConfigurations.class)).thenReturn(parserConfigurations);
when(sensorParserConfigService.findOne("bro")).thenReturn(new SensorParserConfig());
SensorParserGroup newGroup = new SensorParserGroup();
newGroup.setName("newGroup");
newGroup.setSensors(Collections.singleton("bro"));
RestException e = assertThrows(RestException.class, () -> sensorParserGroupService.save(newGroup));
assertEquals("Sensor bro is already in group existingGroup", e.getMessage());
}
use of org.apache.metron.common.configuration.SensorParserConfig in project metron by apache.
the class StormAdminServiceImplTest method startParserTopologyShouldProperlyReturnSuccessTopologyResponse.
@Test
public void startParserTopologyShouldProperlyReturnSuccessTopologyResponse() throws Exception {
when(stormCLIClientWrapper.startParserTopology("bro")).thenReturn(0);
when(globalConfigService.get()).thenReturn(new HashMap<String, Object>());
when(sensorParserConfigService.findOne("bro")).thenReturn(new SensorParserConfig());
TopologyResponse expected = new TopologyResponse();
expected.setSuccessMessage(TopologyStatusCode.STARTED.toString());
TopologyResponse actual = stormAdminService.startParserTopology("bro");
assertEquals(expected, actual);
assertEquals(expected.hashCode(), actual.hashCode());
}
use of org.apache.metron.common.configuration.SensorParserConfig in project metron by apache.
the class SensorParserConfigServiceImplTest method saveShouldWrapExceptionInRestException.
@Test
public void saveShouldWrapExceptionInRestException() throws Exception {
SetDataBuilder setDataBuilder = mock(SetDataBuilder.class);
when(setDataBuilder.forPath(ConfigurationType.PARSER.getZookeeperRoot() + "/bro", broJson.getBytes(StandardCharsets.UTF_8))).thenThrow(Exception.class);
when(curatorFramework.setData()).thenReturn(setDataBuilder);
final SensorParserConfig sensorParserConfig = new SensorParserConfig();
sensorParserConfig.setSensorTopic("bro");
assertThrows(RestException.class, () -> sensorParserConfigService.save("bro", sensorParserConfig));
}
use of org.apache.metron.common.configuration.SensorParserConfig in project metron by apache.
the class SensorParserConfigServiceImplTest method missingParserClassShouldThrowRestException.
@Test
public void missingParserClassShouldThrowRestException() {
final SensorParserConfig sensorParserConfig = new SensorParserConfig();
sensorParserConfig.setSensorTopic("squid");
ParseMessageRequest parseMessageRequest = new ParseMessageRequest();
parseMessageRequest.setSensorParserConfig(sensorParserConfig);
assertThrows(RestException.class, () -> sensorParserConfigService.parseMessage(parseMessageRequest));
}
use of org.apache.metron.common.configuration.SensorParserConfig in project metron by apache.
the class SensorParserConfigServiceImplTest method getTestSquidSensorParserConfig.
private SensorParserConfig getTestSquidSensorParserConfig() {
SensorParserConfig sensorParserConfig = new SensorParserConfig();
sensorParserConfig.setSensorTopic("squid");
sensorParserConfig.setParserClassName("org.apache.metron.parsers.GrokParser");
sensorParserConfig.setParserConfig(new HashMap<String, Object>() {
{
put("grokPath", "/patterns/squid");
put("patternLabel", "SQUID_DELIMITED");
put("timestampField", "timestamp");
}
});
return sensorParserConfig;
}
Aggregations