SensorParserConfigServiceImpl implements SensorParserConfigService { @Override public SensorParserConfig save(String name, SensorParserConfig sensorParserConfig) throws RestException { try { ConfigurationsUtils.writeSensorParserConfigToZookeeper(name, objectMapper.writeValueAsString(sensorParserConfig).getBytes(StandardCharsets.UTF_8), client); } catch (Exception e) { throw new RestException(e); } return sensorParserConfig; } @Autowired  SensorParserConfigServiceImpl(ObjectMapper objectMapper, CuratorFramework client,
      GrokService grokService, ConfigurationsCache cache); @Override SensorParserConfig save(String name, SensorParserConfig sensorParserConfig); @Override SensorParserConfig findOne(String name); @Override Map<String, SensorParserConfig> getAll(); @Override boolean delete(String name); @Override List<String> getAllTypes(); @Override Map<String, String> getAvailableParsers(); @Override Map<String, String> reloadAvailableParsers(); @Override JSONObject parseMessage(ParseMessageRequest parseMessageRequest);  }
@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)); }
@Test public void saveShouldReturnSameConfigThatIsPassedOnSuccessfulSave() throws Exception { final SensorParserConfig sensorParserConfig = getTestBroSensorParserConfig(); when(objectMapper.writeValueAsString(sensorParserConfig)).thenReturn(broJson); SetDataBuilder setDataBuilder = mock(SetDataBuilder.class); when(setDataBuilder.forPath(ConfigurationType.PARSER.getZookeeperRoot() + "/bro", broJson.getBytes(StandardCharsets.UTF_8))).thenReturn(new Stat()); when(curatorFramework.setData()).thenReturn(setDataBuilder); assertEquals(getTestBroSensorParserConfig(), sensorParserConfigService.save("bro", sensorParserConfig)); verify(setDataBuilder).forPath(eq(ConfigurationType.PARSER.getZookeeperRoot() + "/bro"), eq(broJson.getBytes(StandardCharsets.UTF_8))); }