use of org.apache.metron.common.configuration.SensorParserGroup 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);
}
use of org.apache.metron.common.configuration.SensorParserGroup 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.SensorParserGroup in project metron by apache.
the class SensorParserGroupServiceImplTest method saveShouldThrowExceptionOnMissingConfig.
@Test
public void saveShouldThrowExceptionOnMissingConfig() {
when(cache.get(ParserConfigurations.class)).thenReturn(new ParserConfigurations());
SensorParserGroup sensorParserGroup = new SensorParserGroup();
sensorParserGroup.setSensors(Collections.singleton("bro"));
RestException e = assertThrows(RestException.class, () -> sensorParserGroupService.save(sensorParserGroup));
assertEquals("Could not find config for sensor bro", e.getMessage());
}
use of org.apache.metron.common.configuration.SensorParserGroup in project metron by apache.
the class StormStatusServiceImplTest method getTopologyStatusByGroupShouldReturnTopologyStatus.
@Test
public void getTopologyStatusByGroupShouldReturnTopologyStatus() throws Exception {
final TopologyStatus topologyStatus = new TopologyStatus();
topologyStatus.setStatus(TopologyStatusCode.STARTED);
topologyStatus.setName("bro__snort");
topologyStatus.setId("bro_snort_id");
final TopologySummary topologySummary = new TopologySummary();
topologySummary.setTopologies(new TopologyStatus[] { topologyStatus });
SensorParserGroup group = new SensorParserGroup();
group.setName("group");
group.setSensors(new HashSet<String>() {
{
add("bro");
add("snort");
}
});
when(sensorParserGroupService.findOne("group")).thenReturn(group);
when(environment.getProperty(STORM_UI_SPRING_PROPERTY)).thenReturn(HTTP_STORM_UI);
when(restTemplate.getForObject(HTTP_STORM_UI + TOPOLOGY_SUMMARY_URL, TopologySummary.class)).thenReturn(topologySummary);
when(restTemplate.getForObject(HTTP_STORM_UI + TOPOLOGY_URL + "/bro_snort_id", TopologyStatus.class)).thenReturn(topologyStatus);
TopologyStatus expected = new TopologyStatus();
expected.setStatus(TopologyStatusCode.STARTED);
expected.setName("bro__snort");
expected.setId("bro_snort_id");
TopologyStatus actual = stormStatusService.getTopologyStatus("group");
assertEquals(expected, actual);
assertEquals(expected.hashCode(), actual.hashCode());
}
use of org.apache.metron.common.configuration.SensorParserGroup in project metron by apache.
the class SensorParserGroupControllerIntegrationTest method testFindOne.
@Test
public void testFindOne() throws Exception {
SensorParserGroup group1 = JSONUtils.INSTANCE.load(group1BroSquid, SensorParserGroup.class);
this.sensorParserGroupService.save(group1);
TestUtils.assertEventually(() -> assertEquals(group1, this.sensorParserGroupService.findOne("group1")));
this.mockMvc.perform(get(sensorParserGroupUrl + "/group1").with(httpBasic(user, password))).andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$.*", hasSize(numFields.get()))).andExpect(jsonPath("$.name").value("group1")).andExpect(jsonPath("$.description").value("group1 description")).andExpect(jsonPath("$.sensors[0]").value("squid")).andExpect(jsonPath("$.sensors[1]").value("bro"));
this.mockMvc.perform(get(sensorParserGroupUrl + "/missingGroup").with(httpBasic(user, password))).andExpect(status().isNotFound());
}
Aggregations