SensorEnrichmentConfigServiceImpl implements SensorEnrichmentConfigService { @Override public SensorEnrichmentConfig save(String name, SensorEnrichmentConfig sensorEnrichmentConfig) throws RestException { try { ConfigurationsUtils.writeSensorEnrichmentConfigToZookeeper(name, objectMapper.writeValueAsString(sensorEnrichmentConfig).getBytes( StandardCharsets.UTF_8), client); } catch (Exception e) { throw new RestException(e); } return sensorEnrichmentConfig; } @Autowired  SensorEnrichmentConfigServiceImpl(final ObjectMapper objectMapper,
        final CuratorFramework client, final ConfigurationsCache cache,
        final HBaseClient hBaseClient); @Override SensorEnrichmentConfig save(String name, SensorEnrichmentConfig sensorEnrichmentConfig); @Override SensorEnrichmentConfig findOne(String name); @Override Map<String, SensorEnrichmentConfig> getAll(); @Override List<String> getAllTypes(); @Override boolean delete(String name); @Override List<String> getAvailableEnrichments(); @Override List<String> getAvailableThreatTriageAggregators();  }
@Test public void saveShouldWrapExceptionInRestException() throws Exception { SetDataBuilder setDataBuilder = mock(SetDataBuilder.class); when(setDataBuilder.forPath(ConfigurationType.ENRICHMENT.getZookeeperRoot() + "/bro", broJson.getBytes( StandardCharsets.UTF_8))).thenThrow(Exception.class); when(curatorFramework.setData()).thenReturn(setDataBuilder); assertThrows(RestException.class, () -> sensorEnrichmentConfigService.save("bro", new SensorEnrichmentConfig())); }
@Test public void saveShouldReturnSameConfigThatIsPassedOnSuccessfulSave() throws Exception { final SensorEnrichmentConfig sensorEnrichmentConfig = getTestSensorEnrichmentConfig(); when(objectMapper.writeValueAsString(sensorEnrichmentConfig)).thenReturn(broJson); SetDataBuilder setDataBuilder = mock(SetDataBuilder.class); when(setDataBuilder.forPath(ConfigurationType.ENRICHMENT.getZookeeperRoot() + "/bro", broJson.getBytes(StandardCharsets.UTF_8))).thenReturn(new Stat()); when(curatorFramework.setData()).thenReturn(setDataBuilder); assertEquals(sensorEnrichmentConfig, sensorEnrichmentConfigService.save("bro", sensorEnrichmentConfig)); verify(setDataBuilder).forPath(eq(ConfigurationType.ENRICHMENT.getZookeeperRoot() + "/bro"), eq(broJson.getBytes(StandardCharsets.UTF_8))); }