private Config getConfig(final Map<String, String> config) { final Map<String, String> configTweaks = Maps.newHashMap(); for (TweakedModule tweakedModule : tweakedModules) { configTweaks.putAll(tweakedModule.getServiceConfigTweaks()); } return Config.getOverriddenConfig(baseConfig, new MapConfiguration(config), new MapConfiguration(configKeys)); }
final Config serviceConfig = Config.getOverriddenConfig(baseConfig, new MapConfiguration(serviceConfigTweaks));
final Config serviceConfig = Config.getOverriddenConfig(serviceBaseConfig, new MapConfiguration(serviceConfigTweaks), new MapConfiguration(entry.getValue().getServiceConfigTweaks()));
final Config testCaseConfig = Config.getOverriddenConfig(baseConfig, new MapConfiguration(testCaseConfigTweaks), new MapConfiguration(configKeys)); final Module module = new Module() { @Override
@Test public void testEmptyConfigOverride() { // Fails in ness-cache <= 2.1.0 Config.getOverriddenConfig(Config.getEmptyConfig(), new MapConfiguration(Collections.<String, String>emptyMap())); } }
@Test public void testOverride() { Assert.assertThat(cfg, is(notNullValue())); PropertiesConfiguration pc = new PropertiesConfiguration(); pc.setProperty("prefix.of.three.string-null-value", "NULL"); pc.setProperty("prefix.of.three.string-value", "another test value"); Config c2 = Config.getOverriddenConfig(cfg, pc); final Configuration config = c2.getConfiguration("prefix.of.three"); Assert.assertThat(config, is(notNullValue())); final String s_cfg1 = config.getString("string-null-value"); Assert.assertThat(s_cfg1, is("NULL")); final String s_cfg2 = config.getString("string-value"); Assert.assertThat(s_cfg2, is("another test value")); }
@Test public void testSystemStillWins() { Assert.assertThat(cfg, is(notNullValue())); PropertiesConfiguration pc = new PropertiesConfiguration(); pc.setProperty("prefix.of.three.string-null-value", "NULL"); pc.setProperty("prefix.of.three.string-value", "another test value"); PropertiesSaver ps = new PropertiesSaver("prefix.of.three.string-value"); try { System.setProperty("prefix.of.three.string-value", "system-value"); Config c2 = Config.getOverriddenConfig(cfg, pc); final Configuration config = c2.getConfiguration("prefix.of.three"); Assert.assertThat(config, is(notNullValue())); final String s_cfg2 = config.getString("string-value"); Assert.assertThat(s_cfg2, is("system-value")); } finally { ps.apply(); } } }