ConfigurationLogger { public void logConfiguration(ConfigurationRegistry configuration) { logger.info("# stagemonitor configuration, listing non-default values:"); boolean hasOnlyDefaultOptions = true; for (List<ConfigurationOption<?>> options : configuration.getConfigurationOptionsByCategory().values()) { for (ConfigurationOption<?> option : options) { if (!option.isDefault()) { hasOnlyDefaultOptions = false; logger.info("{}: {} (source: {})", option.getKey(), prepareOptionValueForLog(option), option.getNameOfCurrentConfigurationSource()); if (option.getTags().contains("deprecated")) { logger.warn("Detected usage of deprecated configuration option '{}'. " + "This option might be removed in the future. " + "Please refer to the documentation about alternatives.", option.getKey()); } if (!option.getKey().equals(option.getUsedKey())) { logger.warn("Detected usage of an old configuration key: '{}'. Please use '{}' instead.", option.getUsedKey(), option.getKey()); } } } } if (hasOnlyDefaultOptions) { logger.warn("stagemonitor has not been configured. Have a look at " + "https: "and " + "https: "for further instructions"); } } ConfigurationLogger();  ConfigurationLogger(Logger logger); void logConfiguration(ConfigurationRegistry configuration);  }
@Test public void testDeprecatedOption() throws Exception { class Provider extends ConfigurationOptionProvider { private ConfigurationOption<String> deprecatedOption = ConfigurationOption.stringOption() .key("foo") .tags("deprecated") .buildRequired(); } final ConfigurationRegistry configurationRegistry = ConfigurationRegistry.builder() .addOptionProvider(new Provider()) .addConfigSource(new SimpleSource().add("foo", "bar")) .build(); configurationLogger.logConfiguration(configurationRegistry); verify(logger).warn(contains("Detected usage of deprecated configuration option '{}'"), eq("foo")); }
@Test public void testAliasKey() throws Exception { class Provider extends ConfigurationOptionProvider { private ConfigurationOption<String> aliasOption = ConfigurationOption.stringOption() .key("foo") .aliasKeys("foo.old") .buildRequired(); } final ConfigurationRegistry configurationRegistry = ConfigurationRegistry.builder() .addOptionProvider(new Provider()) .addConfigSource(new SimpleSource().add("foo.old", "bar")) .build(); configurationLogger.logConfiguration(configurationRegistry); verify(logger).warn(eq("Detected usage of an old configuration key: '{}'. " + "Please use '{}' instead."), eq("foo.old"), eq("foo")); }
@Test public void testLogSensitive() throws Exception { class Provider extends ConfigurationOptionProvider { private ConfigurationOption<String> sensitiveOption = ConfigurationOption.stringOption() .key("foo") .sensitive() .buildRequired(); } final ConfigurationRegistry configurationRegistry = ConfigurationRegistry.builder() .addOptionProvider(new Provider()) .addConfigSource(new SimpleSource("source").add("foo", "secret")) .build(); configurationLogger.logConfiguration(configurationRegistry); verify(logger).info(startsWith("# stagemonitor configuration")); verify(logger).info(eq("{}: {} (source: {})"), eq("foo"), eq("XXXX"), eq("source")); }
@Test public void testLogUrlWithBasicAuth() throws Exception { class Provider extends ConfigurationOptionProvider { private ConfigurationOption<List<URL>> urlBasicAuthOption = ConfigurationOption.urlsOption() .key("foo") .buildRequired(); } final ConfigurationRegistry configurationRegistry = ConfigurationRegistry.builder() .addOptionProvider(new Provider()) .addConfigSource(new SimpleSource("source").add("foo", "http: .build(); configurationLogger.logConfiguration(configurationRegistry); verify(logger).info(startsWith("# stagemonitor configuration")); verify(logger).info(eq("{}: {} (source: {})"), eq("foo"), eq("http: }