@Test void testEmptyKeys() throws IOException { ConsulConfig config = defaultConfig(); ConsulConfigGateway mockGateway = mock(ConsulConfigGateway.class); ConsulConfigSourceProvider sut = new ConsulConfigSourceProvider(config, mockGateway); Iterable<ConfigSource> configSources = sut.getConfigSources(null); assertThat(configSources).isEmpty(); verify(mockGateway, never()).getValue(anyString()); }
@Override public Iterable<ConfigSource> getConfigSources(ClassLoader cl) { Map<String, ValueType> keys = config.keysAsMap(); if (keys.isEmpty()) { log.debug("No keys were configured for config source lookup"); return Collections.emptyList(); } List<ConfigSource> result = new ArrayList<>(keys.size()); for (Map.Entry<String, ValueType> entry : keys.entrySet()) { String fullKey = config.prefix.isPresent() ? config.prefix.get() + "/" + entry.getKey() : entry.getKey(); log.debug("Attempting to look up value of key '" + fullKey + "' from Consul."); try { Optional<Response> optionalResponse = consulConfigGateway.getValue(fullKey); if (optionalResponse.isPresent()) { result.add( responseConfigSourceUtil.toConfigSource(optionalResponse.get(), entry.getValue(), config.prefix)); } else { String message = "Key '" + fullKey + "' not found in Consul."; if (config.failOnMissingKey) { throw new RuntimeException(message); } else { log.info(message); } } log.debug("Done reading value of key '" + fullKey + "'"); } catch (IOException e) { throw new UncheckedIOException("An error occurred while attempting to fetch configuration from Consul.", e); } } return result; }
ConsulConfigSourceProvider implements ConfigSourceProvider { @Override public Iterable<ConfigSource> getConfigSources(ClassLoader cl) { Map<String, ValueType> keys = config.keysAsMap(); if (keys.isEmpty()) { log.debug("No keys were configured for config source lookup"); return Collections.emptyList(); } List<ConfigSource> result = new ArrayList<>(keys.size()); for (Map.Entry<String, ValueType> entry : keys.entrySet()) { String fullKey = config.prefix.isPresent() ? config.prefix.get() + "/" + entry.getKey() : entry.getKey(); log.debug("Attempting to look up value of key '" + fullKey + "' from Consul."); try { Optional<Response> optionalResponse = consulConfigGateway.getValue(fullKey); if (optionalResponse.isPresent()) { result.add( responseConfigSourceUtil.toConfigSource(optionalResponse.get(), entry.getValue(), config.prefix)); } else { String message = "Key '" + fullKey + "' not found in Consul."; if (config.failOnMissingKey) { throw new RuntimeException(message); } else { log.info(message); } } log.debug("Done reading value of key '" + fullKey + "'"); } catch (IOException e) { throw new UncheckedIOException("An error occurred while attempting to fetch configuration from Consul.", e); } } return result; } }
ConsulConfigSourceProvider implements ConfigSourceProvider { @Override public Iterable<ConfigSource> getConfigSources(ClassLoader cl) { Map<String, ValueType> keys = config.keysAsMap(); if (keys.isEmpty()) { log.debug("No keys were configured for config source lookup"); return Collections.emptyList(); } List<ConfigSource> result = new ArrayList<>(keys.size()); for (Map.Entry<String, ValueType> entry : keys.entrySet()) { String fullKey = config.prefix.isPresent() ? config.prefix.get() + "/" + entry.getKey() : entry.getKey(); log.debug("Attempting to look up value of key '" + fullKey + "' from Consul."); try { Optional<Response> optionalResponse = consulConfigGateway.getValue(fullKey); if (optionalResponse.isPresent()) { result.add( responseConfigSourceUtil.toConfigSource(optionalResponse.get(), entry.getValue(), config.prefix)); } else { String message = "Key '" + fullKey + "' not found in Consul."; if (config.failOnMissingKey) { throw new RuntimeException(message); } else { log.info(message); } } log.debug("Done reading value of key '" + fullKey + "'"); } catch (IOException e) { throw new UncheckedIOException("An error occurred while attempting to fetch configuration from Consul.", e); } } return result; } ConsulConfigSourceProvider(ConsulConfig config);   ConsulConfigSourceProvider(ConsulConfig config, ConsulConfigGateway consulConfigGateway); private  ConsulConfigSourceProvider(ConsulConfig config, ConsulConfigGateway consulConfigGateway,
            ResponseConfigSourceUtil responseConfigSourceUtil); }
ConsulConfigSourceProvider implements ConfigSourceProvider { @Override public Iterable<ConfigSource> getConfigSources(ClassLoader cl) { Map<String, ValueType> keys = config.keysAsMap(); if (keys.isEmpty()) { log.debug("No keys were configured for config source lookup"); return Collections.emptyList(); } List<ConfigSource> result = new ArrayList<>(keys.size()); for (Map.Entry<String, ValueType> entry : keys.entrySet()) { String fullKey = config.prefix.isPresent() ? config.prefix.get() + "/" + entry.getKey() : entry.getKey(); log.debug("Attempting to look up value of key '" + fullKey + "' from Consul."); try { Optional<Response> optionalResponse = consulConfigGateway.getValue(fullKey); if (optionalResponse.isPresent()) { result.add( responseConfigSourceUtil.toConfigSource(optionalResponse.get(), entry.getValue(), config.prefix)); } else { String message = "Key '" + fullKey + "' not found in Consul."; if (config.failOnMissingKey) { throw new RuntimeException(message); } else { log.info(message); } } log.debug("Done reading value of key '" + fullKey + "'"); } catch (IOException e) { throw new UncheckedIOException("An error occurred while attempting to fetch configuration from Consul.", e); } } return result; } ConsulConfigSourceProvider(ConsulConfig config);   ConsulConfigSourceProvider(ConsulConfig config, ConsulConfigGateway consulConfigGateway); private  ConsulConfigSourceProvider(ConsulConfig config, ConsulConfigGateway consulConfigGateway,
            ResponseConfigSourceUtil responseConfigSourceUtil); @Override Iterable<ConfigSource> getConfigSources(ClassLoader cl); }
ConsulConfigSourceProvider implements ConfigSourceProvider { @Override public Iterable<ConfigSource> getConfigSources(ClassLoader cl) { Map<String, ValueType> keys = config.keysAsMap(); if (keys.isEmpty()) { log.debug("No keys were configured for config source lookup"); return Collections.emptyList(); } List<ConfigSource> result = new ArrayList<>(keys.size()); for (Map.Entry<String, ValueType> entry : keys.entrySet()) { String fullKey = config.prefix.isPresent() ? config.prefix.get() + "/" + entry.getKey() : entry.getKey(); log.debug("Attempting to look up value of key '" + fullKey + "' from Consul."); try { Optional<Response> optionalResponse = consulConfigGateway.getValue(fullKey); if (optionalResponse.isPresent()) { result.add( responseConfigSourceUtil.toConfigSource(optionalResponse.get(), entry.getValue(), config.prefix)); } else { String message = "Key '" + fullKey + "' not found in Consul."; if (config.failOnMissingKey) { throw new RuntimeException(message); } else { log.info(message); } } log.debug("Done reading value of key '" + fullKey + "'"); } catch (IOException e) { throw new UncheckedIOException("An error occurred while attempting to fetch configuration from Consul.", e); } } return result; } ConsulConfigSourceProvider(ConsulConfig config);   ConsulConfigSourceProvider(ConsulConfig config, ConsulConfigGateway consulConfigGateway); private  ConsulConfigSourceProvider(ConsulConfig config, ConsulConfigGateway consulConfigGateway,
            ResponseConfigSourceUtil responseConfigSourceUtil); @Override Iterable<ConfigSource> getConfigSources(ClassLoader cl);  }