SensorEnrichmentConfigServiceImpl implements SensorEnrichmentConfigService { @Override public boolean delete(String name) throws RestException { try { client.delete().forPath(ConfigurationType.ENRICHMENT.getZookeeperRoot() + "/" + name); } catch (KeeperException.NoNodeException e) { return false; } catch (Exception e) { throw new RestException(e); } return true; } @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 deleteShouldProperlyCatchNoNodeExceptionAndReturnFalse() throws Exception { DeleteBuilder builder = mock(DeleteBuilder.class); when(curatorFramework.delete()).thenReturn(builder); when(builder.forPath(ConfigurationType.ENRICHMENT.getZookeeperRoot() + "/bro")).thenThrow(KeeperException.NoNodeException.class); assertFalse(sensorEnrichmentConfigService.delete("bro")); }
@Test public void deleteShouldProperlyCatchNonNoNodeExceptionAndThrowRestException() throws Exception { DeleteBuilder builder = mock(DeleteBuilder.class); when(curatorFramework.delete()).thenReturn(builder); when(builder.forPath(ConfigurationType.ENRICHMENT.getZookeeperRoot() + "/bro")).thenThrow(Exception.class); assertThrows(RestException.class, () -> sensorEnrichmentConfigService.delete("bro")); }
@Test public void deleteShouldReturnTrueWhenClientSuccessfullyCallsDelete() throws Exception { DeleteBuilder builder = mock(DeleteBuilder.class); when(curatorFramework.delete()).thenReturn(builder); doNothing().when(builder).forPath(ConfigurationType.ENRICHMENT.getZookeeperRoot() + "/bro"); assertTrue(sensorEnrichmentConfigService.delete("bro")); verify(curatorFramework).delete(); }