SensorIndexingConfigServiceImpl implements SensorIndexingConfigService { @Override public Map<String, Object> save(String name, Map<String, Object> sensorIndexingConfig) throws RestException { try { ConfigurationsUtils.writeSensorIndexingConfigToZookeeper(name, objectMapper.writeValueAsString(sensorIndexingConfig).getBytes( StandardCharsets.UTF_8), client); } catch (Exception e) { throw new RestException(e); } return sensorIndexingConfig; } @Autowired  SensorIndexingConfigServiceImpl(ObjectMapper objectMapper, CuratorFramework client, ConfigurationsCache cache); @Override Map<String, Object> save(String name, Map<String, Object> sensorIndexingConfig); @Override Map<String, Object> findOne(String name); @Override Map<String, Map<String, Object>> getAll(); @Override List<String> getAllTypes(); @Override Iterable<String> getAllIndices(String writerName); @Override boolean delete(String name);  }
@Test public void saveShouldWrapExceptionInRestException() throws Exception { SetDataBuilder setDataBuilder = mock(SetDataBuilder.class); when(setDataBuilder.forPath(ConfigurationType.INDEXING.getZookeeperRoot() + "/bro", broJson.getBytes( StandardCharsets.UTF_8))).thenThrow(Exception.class); when(curatorFramework.setData()).thenReturn(setDataBuilder); assertThrows(RestException.class, () -> sensorIndexingConfigService.save("bro", new HashMap<>())); }
@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))); }