GlobalConfigServiceImpl implements GlobalConfigService { @Override public Map<String, Object> get() throws RestException { Map<String, Object> globalConfig; try { EnrichmentConfigurations configs = cache.get( EnrichmentConfigurations.class); globalConfig = configs.getGlobalConfig(false); } catch (Exception e) { throw new RestException(e.getMessage(), e); } return globalConfig; } @Autowired  GlobalConfigServiceImpl(CuratorFramework client, ConfigurationsCache cache); void setCache(ConfigurationsCache cache); @Override Map<String, Object> save(Map<String, Object> globalConfig); @Override Map<String, Object> get(); @Override boolean delete();  }
@Test public void getShouldProperlyReturnGlobalConfig() throws Exception { final String config = "{\"k\":\"v\"}"; final Map<String, Object> configMap = new HashMap<String, Object>() {{ put("k", "v"); }}; EnrichmentConfigurations configs = new EnrichmentConfigurations(){ @Override public Map<String, Object> getConfigurations() { return ImmutableMap.of(ConfigurationType.GLOBAL.getTypeName(), configMap); } }; when(cache.get( eq(EnrichmentConfigurations.class))) .thenReturn(configs); assertEquals(configMap, globalConfigService.get()); }
@Test public void getShouldWrapNonNoNodeExceptionInRestException() throws Exception { GetDataBuilder getDataBuilder = mock(GetDataBuilder.class); when(getDataBuilder.forPath(ConfigurationType.GLOBAL.getZookeeperRoot())).thenThrow(Exception.class); when(curatorFramework.getData()).thenReturn(getDataBuilder); assertThrows(RestException.class, () -> globalConfigService.get()); }