use of org.apache.metron.common.configuration.SensorParserGroup in project metron by apache.
the class SensorParserGroupServiceImplTest method shouldSaveNewGroup.
@Test
public void shouldSaveNewGroup() throws Exception {
when(cache.get(ParserConfigurations.class)).thenReturn(new ParserConfigurations());
when(sensorParserConfigService.findOne("bro")).thenReturn(new SensorParserConfig());
SensorParserGroup sensorParserGroup = new SensorParserGroup();
sensorParserGroup.setName("group1");
sensorParserGroup.setDescription("description 1");
sensorParserGroup.setSensors(Collections.singleton("bro"));
Map<String, Object> expectedGlobalConfig = new HashMap<>();
Collection<SensorParserGroup> expectedGroup = Collections.singleton(sensorParserGroup);
expectedGlobalConfig.put(PARSER_GROUPS_CONF, expectedGroup);
assertEquals(sensorParserGroup, sensorParserGroupService.save(sensorParserGroup));
verify(globalConfigService, times(1)).save(expectedGlobalConfig);
verifyNoMoreInteractions(globalConfigService);
}
use of org.apache.metron.common.configuration.SensorParserGroup in project metron by apache.
the class SensorParserGroupServiceImplTest method saveShouldThrowExceptionOnMissingSensor.
@Test
public void saveShouldThrowExceptionOnMissingSensor() {
when(cache.get(ParserConfigurations.class)).thenReturn(new ParserConfigurations());
RestException e = assertThrows(RestException.class, () -> sensorParserGroupService.save(new SensorParserGroup()));
assertEquals("A parser group must contain sensors", e.getMessage());
}
use of org.apache.metron.common.configuration.SensorParserGroup in project metron by apache.
the class SensorParserGroupServiceImplTest method shouldFindSensorParserGroup.
@Test
public void shouldFindSensorParserGroup() {
ParserConfigurations parserConfigurations = mock(ParserConfigurations.class);
SensorParserGroup group1 = new SensorParserGroup();
group1.setName("group1");
group1.setDescription("group1 description");
group1.setSensors(Collections.singleton("group1Sensor"));
SensorParserGroup group2 = new SensorParserGroup();
group2.setName("group2");
group2.setDescription("group2 description");
group2.setSensors(Collections.singleton("group2Sensor"));
when(parserConfigurations.getSensorParserGroups()).thenReturn(new HashMap<String, SensorParserGroup>() {
{
put("group1", group1);
put("group2", group2);
}
});
when(cache.get(ParserConfigurations.class)).thenReturn(parserConfigurations);
assertEquals(group2, sensorParserGroupService.findOne("group2"));
}
use of org.apache.metron.common.configuration.SensorParserGroup in project metron by apache.
the class SensorParserGroupServiceImplTest method shouldDeleteSensorParserGroup.
@Test
public void shouldDeleteSensorParserGroup() throws Exception {
ParserConfigurations parserConfigurations = mock(ParserConfigurations.class);
SensorParserGroup group1 = new SensorParserGroup();
group1.setName("group1");
group1.setDescription("group1 description");
group1.setSensors(Collections.singleton("group1Sensor"));
when(parserConfigurations.getSensorParserGroups()).thenReturn(new HashMap<String, SensorParserGroup>() {
{
put("group1", group1);
}
});
when(cache.get(ParserConfigurations.class)).thenReturn(parserConfigurations);
Map<String, Object> expectedGlobalConfig = new HashMap<>();
expectedGlobalConfig.put(PARSER_GROUPS_CONF, new HashSet<>());
assertTrue(sensorParserGroupService.delete("group1"));
assertFalse(sensorParserGroupService.delete("group2"));
verify(globalConfigService, times(1)).save(expectedGlobalConfig);
verifyNoMoreInteractions(globalConfigService);
}
use of org.apache.metron.common.configuration.SensorParserGroup in project metron by apache.
the class StormAdminServiceImplTest method startParserTopologyByGroupShouldProperlyReturnSuccessTopologyResponse.
@Test
public void startParserTopologyByGroupShouldProperlyReturnSuccessTopologyResponse() throws Exception {
SensorParserGroup group = new SensorParserGroup();
group.setName("group");
group.setSensors(new HashSet<String>() {
{
add("bro");
add("snort");
}
});
when(sensorParserGroupService.findOne("group")).thenReturn(group);
when(stormCLIClientWrapper.startParserTopology("bro,snort")).thenReturn(0);
when(globalConfigService.get()).thenReturn(new HashMap<String, Object>());
when(sensorParserConfigService.findOne("bro")).thenReturn(new SensorParserConfig());
when(sensorParserConfigService.findOne("snort")).thenReturn(new SensorParserConfig());
TopologyResponse expected = new TopologyResponse();
expected.setSuccessMessage(TopologyStatusCode.STARTED.toString());
TopologyResponse actual = stormAdminService.startParserTopology("group");
assertEquals(expected, actual);
assertEquals(expected.hashCode(), actual.hashCode());
}
Aggregations