Search in sources :

Example 1 with SensorParserGroup

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

Example 2 with SensorParserGroup

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());
}
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 3 with SensorParserGroup

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

Example 4 with SensorParserGroup

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

Example 5 with SensorParserGroup

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

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