Search in sources :

Example 11 with SetDataBuilder

use of org.apache.curator.framework.api.SetDataBuilder in project metron by apache.

the class GlobalConfigServiceImplTest method saveShouldReturnSameConfigThatIsPassedOnSuccessfulSave.

@Test
public void saveShouldReturnSameConfigThatIsPassedOnSuccessfulSave() throws Exception {
    SetDataBuilder setDataBuilder = mock(SetDataBuilder.class);
    when(setDataBuilder.forPath(ConfigurationType.GLOBAL.getZookeeperRoot(), "{ }".getBytes(StandardCharsets.UTF_8))).thenReturn(new Stat());
    when(curatorFramework.setData()).thenReturn(setDataBuilder);
    assertEquals(new HashMap<>(), globalConfigService.save(new HashMap<>()));
    verify(setDataBuilder).forPath(eq(ConfigurationType.GLOBAL.getZookeeperRoot()), eq("{ }".getBytes(StandardCharsets.UTF_8)));
}
Also used : SetDataBuilder(org.apache.curator.framework.api.SetDataBuilder) Stat(org.apache.zookeeper.data.Stat) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 12 with SetDataBuilder

use of org.apache.curator.framework.api.SetDataBuilder in project metron by apache.

the class GlobalConfigServiceImplTest method saveShouldWrapExceptionInRestException.

@Test
public void saveShouldWrapExceptionInRestException() throws Exception {
    SetDataBuilder setDataBuilder = mock(SetDataBuilder.class);
    when(setDataBuilder.forPath(ConfigurationType.GLOBAL.getZookeeperRoot(), "{ }".getBytes(StandardCharsets.UTF_8))).thenThrow(Exception.class);
    when(curatorFramework.setData()).thenReturn(setDataBuilder);
    assertThrows(RestException.class, () -> globalConfigService.save(new HashMap<>()));
}
Also used : SetDataBuilder(org.apache.curator.framework.api.SetDataBuilder) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 13 with SetDataBuilder

use of org.apache.curator.framework.api.SetDataBuilder in project metron by apache.

the class SensorIndexingConfigServiceImplTest method saveShouldReturnSameConfigThatIsPassedOnSuccessfulSave.

@Test
public void saveShouldReturnSameConfigThatIsPassedOnSuccessfulSave() throws Exception {
    final Map<String, Object> sensorIndexingConfig = getTestSensorIndexingConfig();
    when(objectMapper.writeValueAsString(sensorIndexingConfig)).thenReturn(broJson);
    SetDataBuilder setDataBuilder = mock(SetDataBuilder.class);
    when(setDataBuilder.forPath(ConfigurationType.INDEXING.getZookeeperRoot() + "/bro", broJson.getBytes(StandardCharsets.UTF_8))).thenReturn(new Stat());
    when(curatorFramework.setData()).thenReturn(setDataBuilder);
    assertEquals(sensorIndexingConfig, sensorIndexingConfigService.save("bro", sensorIndexingConfig));
    verify(setDataBuilder).forPath(eq(ConfigurationType.INDEXING.getZookeeperRoot() + "/bro"), eq(broJson.getBytes(StandardCharsets.UTF_8)));
}
Also used : SetDataBuilder(org.apache.curator.framework.api.SetDataBuilder) Stat(org.apache.zookeeper.data.Stat) Test(org.junit.jupiter.api.Test)

Example 14 with SetDataBuilder

use of org.apache.curator.framework.api.SetDataBuilder 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));
}
Also used : SetDataBuilder(org.apache.curator.framework.api.SetDataBuilder) SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig) Test(org.junit.jupiter.api.Test)

Aggregations

SetDataBuilder (org.apache.curator.framework.api.SetDataBuilder)14 Test (org.junit.jupiter.api.Test)8 ExistsBuilder (org.apache.curator.framework.api.ExistsBuilder)6 Stat (org.apache.zookeeper.data.Stat)6 BeforeTest (org.testng.annotations.BeforeTest)6 Test (org.testng.annotations.Test)6 CreateBuilder (org.apache.curator.framework.api.CreateBuilder)4 HashMap (java.util.HashMap)2 SensorParserConfig (org.apache.metron.common.configuration.SensorParserConfig)2 SensorEnrichmentConfig (org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig)2 ACL (org.apache.zookeeper.data.ACL)2 Id (org.apache.zookeeper.data.Id)2