Search in sources :

Example 11 with SensorParserGroup

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);
}
Also used : ParserConfigurations(org.apache.metron.common.configuration.ParserConfigurations) SensorParserGroup(org.apache.metron.common.configuration.SensorParserGroup) SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig) Test(org.junit.jupiter.api.Test)

Example 12 with SensorParserGroup

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());
}
Also used : ParserConfigurations(org.apache.metron.common.configuration.ParserConfigurations) RestException(org.apache.metron.rest.RestException) SensorParserGroup(org.apache.metron.common.configuration.SensorParserGroup) SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig) Test(org.junit.jupiter.api.Test)

Example 13 with SensorParserGroup

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());
}
Also used : ParserConfigurations(org.apache.metron.common.configuration.ParserConfigurations) RestException(org.apache.metron.rest.RestException) SensorParserGroup(org.apache.metron.common.configuration.SensorParserGroup) Test(org.junit.jupiter.api.Test)

Example 14 with SensorParserGroup

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());
}
Also used : SensorParserGroup(org.apache.metron.common.configuration.SensorParserGroup) TopologySummary(org.apache.metron.rest.model.TopologySummary) TopologyStatus(org.apache.metron.rest.model.TopologyStatus) Test(org.junit.jupiter.api.Test)

Example 15 with SensorParserGroup

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());
}
Also used : SensorParserGroup(org.apache.metron.common.configuration.SensorParserGroup) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

SensorParserGroup (org.apache.metron.common.configuration.SensorParserGroup)18 Test (org.junit.jupiter.api.Test)14 ParserConfigurations (org.apache.metron.common.configuration.ParserConfigurations)9 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 SensorParserConfig (org.apache.metron.common.configuration.SensorParserConfig)4 RestException (org.apache.metron.rest.RestException)4 TopologyResponse (org.apache.metron.rest.model.TopologyResponse)2 TopologyStatus (org.apache.metron.rest.model.TopologyStatus)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 TopologySummary (org.apache.metron.rest.model.TopologySummary)1