ConfigurationInspector { public SortedSet<ConfigRecord<?>> inspect(ConfigurationFactory configurationFactory) { ImmutableSortedSet.Builder<ConfigRecord<?>> builder = ImmutableSortedSet.naturalOrder(); for (ConfigurationIdentity<?> configurationIdentity : configurationFactory.getRegisteredConfigs()) { builder.add(ConfigRecord.createConfigRecord(configurationFactory, configurationIdentity)); } return builder.build(); }  SortedSet<ConfigRecord<?>> inspect(ConfigurationFactory configurationFactory);  }
@Test public void testSimpleConfig() { Map<String, String> properties = new TreeMap<>(); properties.put("string-value", "some value"); properties.put("boolean-value", "true"); inspect(properties, null, null, null, binder -> bindConfig(binder).bind(AnnotatedSetter.class)) .component("ConfigurationFactoryTest$AnnotatedSetter") .value("BooleanValue", "boolean-value", "false", "true", "") .value("StringValue", "string-value", "null", "some value", "") .end(); }
@Test public void testPrivateBinderConfig() { Map<String, String> properties = new TreeMap<>(); properties.put("string-value", "some value"); properties.put("boolean-value", "true"); inspect(properties, null, null, null, binder -> { PrivateBinder privateBinder = binder.newPrivateBinder(); bindConfig(privateBinder).bind(AnnotatedSetter.class); }) .component("ConfigurationFactoryTest$AnnotatedSetter") .value("BooleanValue", "boolean-value", "false", "true", "") .value("StringValue", "string-value", "null", "some value", "") .end(); }
@Test public void testConfigAwareProviderConfig() { Map<String, String> properties = new TreeMap<>(); properties.put("string-value", "some value"); properties.put("boolean-value", "true"); inspect(properties, null, null, null, binder -> binder.bind(Integer.class).toProvider(new ConfigurationAwareProvider<Integer>() { private ConfigurationFactory configurationFactory; @Override public void setConfigurationFactory(ConfigurationFactory configurationFactory) { this.configurationFactory = configurationFactory; } @Override public Integer get() { configurationFactory.build(AnnotatedSetter.class); return 3; } })) .component("") .value("BooleanValue", "boolean-value", "false", "true", "") .value("StringValue", "string-value", "null", "some value", "") .end(); }
@Test public void testPrefixedWithNotPrefixed() { Map<String, String> properties = new TreeMap<>(); properties.put("string-value", "some value"); properties.put("boolean-value", "true"); properties.put("prefix.string-value", "some other value"); properties.put("prefix.boolean-value", "false"); inspect(properties, null, null, null, binder -> { bindConfig(binder).bind(AnnotatedSetter.class); bindConfig(binder).bind(AnnotatedSetter.class).annotatedWith(Prefixed.class).prefixedWith("prefix"); }) .component("ConfigurationFactoryTest$AnnotatedSetter") .value("BooleanValue", "boolean-value", "false", "true", "") .value("StringValue", "string-value", "null", "some value", "") .component("@Prefixed", "ConfigurationFactoryTest$AnnotatedSetter") .value("BooleanValue", "prefix.boolean-value", "false", "false", "") .value("StringValue", "prefix.string-value", "null", "some other value", "") .end(); }
@Test public void testSimpleConfigWithModuleDefaults() { Map<String, String> properties = ImmutableMap.of( "string-value", "some value", "boolean-value", "false" ); Map<String, String> moduleDefaults = ImmutableMap.of( "string-value", "some default value", "boolean-value", "true" ); Map<String, ConfigurationDefaultingModule> moduleDefaultSource = ImmutableMap.of( "string-value", TEST_DEFAULTING_MODULE, "boolean-value", TEST_DEFAULTING_MODULE ); inspect(properties, null, moduleDefaults, moduleDefaultSource, binder -> bindConfig(binder).bind(AnnotatedSetter.class)) .component("ConfigurationFactoryTest$AnnotatedSetter") .value("BooleanValue", "boolean-value", "true", "false", "") .value("StringValue", "string-value", "some default value", "some value", "") .end(); }
@Test public void testSimpleConfigWithApplicationDefaults() { Map<String, String> properties = ImmutableMap.of( "string-value", "some value", "boolean-value", "false" ); Map<String, String> applicationDefaults = ImmutableMap.of( "string-value", "some default value", "boolean-value", "true" ); inspect(properties, applicationDefaults, null, null, binder -> bindConfig(binder).bind(AnnotatedSetter.class)) .component("ConfigurationFactoryTest$AnnotatedSetter") .value("BooleanValue", "boolean-value", "true", "false", "") .value("StringValue", "string-value", "some default value", "some value", "") .end(); }
@Test public void testSimpleConfigWithModuleAndApplicationDefaults() { Map<String, String> properties = ImmutableMap.of( "string-value", "some value", "boolean-value", "false" ); Map<String, String> applicationDefaults = ImmutableMap.of( "string-value", "some default value", "boolean-value", "true" ); Map<String, String> moduleDefaults = ImmutableMap.of( "string-value", "some module default value", "boolean-value", "true" ); Map<String, ConfigurationDefaultingModule> moduleDefaultSource = ImmutableMap.of( "string-value", TEST_DEFAULTING_MODULE, "boolean-value", TEST_DEFAULTING_MODULE ); inspect(properties, applicationDefaults, moduleDefaults, moduleDefaultSource, binder -> bindConfig(binder).bind(AnnotatedSetter.class)) .component("ConfigurationFactoryTest$AnnotatedSetter") .value("BooleanValue", "boolean-value", "true", "false", "") .value("StringValue", "string-value", "some default value", "some value", "") .end(); }
@Test public void testSecuritySensitiveConfig() { Map<String, String> properties = new TreeMap<>(); properties.put("value", "some value"); inspect(properties, null, null, null, binder -> bindConfig(binder).bind(SetterSensitiveClass.class)) .component("ConfigurationMetadataTest$SetterSensitiveClass") .value("Value", "value", "[REDACTED]", "[REDACTED]", "description") .end(); }
@Test public void testSecuritySensitiveConfigWithModuleDefaults() { Map<String, String> properties = ImmutableMap.of( "value", "some value" ); Map<String, String> moduleDefaults = ImmutableMap.of( "value", "some default value" ); Map<String, ConfigurationDefaultingModule> moduleDefaultSource = ImmutableMap.of( "value", TEST_DEFAULTING_MODULE ); inspect(properties, null, moduleDefaults, moduleDefaultSource, binder -> bindConfig(binder).bind(SetterSensitiveClass.class)) .component("ConfigurationMetadataTest$SetterSensitiveClass") .value("Value", "value", "[REDACTED]", "[REDACTED]", "description") .end(); }
@Test public void testSecuritySensitiveConfigWithApplicationDefaults() { Map<String, String> properties = ImmutableMap.of( "value", "some value" ); Map<String, String> applicationDefaults = ImmutableMap.of( "value", "some default value" ); inspect(properties, applicationDefaults, null, null, binder -> bindConfig(binder).bind(SetterSensitiveClass.class)) .component("ConfigurationMetadataTest$SetterSensitiveClass") .value("Value", "value", "[REDACTED]", "[REDACTED]", "description") .end(); }
@Test public void testSimpleMapConfig() { Map<String, String> properties = new TreeMap<>(); properties.put("map-a.a", "this is a"); properties.put("map-a.b", "this is b"); inspect(properties, null, null, null, binder -> bindConfig(binder).bind(LegacyMapConfigPresent.class)) .component("ConfigurationFactoryTest$LegacyMapConfigPresent") .value("MapA[a]", "map-a.a", "-- n/a --", "this is a", "") .value("MapA[b]", "map-a.b", "-- n/a --", "this is b", "") .value("MapB", "map-b", "-- n/a --", "-- empty --", "") .end(); }
@Test public void testConfigMapValueConfig() { Map<String, String> properties = new TreeMap<>(); properties.put("map-a.k1.string-value", "this is a"); properties.put("map-a.k1.string-b", "this is b"); properties.put("map-a.k2.string-value", "this is k2 a"); properties.put("map-a.k2.string-b", "this is k2 b"); inspect(properties, null, null, null, binder -> bindConfig(binder).bind(LegacyMapValueConfigPresent.class)) .component("ConfigurationFactoryTest$LegacyMapValueConfigPresent") .value("MapA[k1]StringA", "map-a.k1.string-a", "defaultA", "this is a", "") .value("MapA[k1]StringB", "map-a.k1.string-b", "defaultB", "this is b", "") .value("MapA[k2]StringA", "map-a.k2.string-a", "defaultA", "this is k2 a", "") .value("MapA[k2]StringB", "map-a.k2.string-b", "defaultB", "this is k2 b", "") .end(); }