public <T> T getBean(final String prefix, final Class<T> classType) { return getBean(prefix, classType, null); }
public static ConfigModule forTesting() { return new ConfigModule(Config.getEmptyConfig()); }
/** * Can be overridden in tests. */ public Config getConfig() { return Config.getConfig(); }
@Test public void testGlobalDisabledLocalEnabled() { final Config config = Config.getFixedConfig("ness.jms.enabled", "false", "ness.jms.user-friendship.enabled", "true"); final JmsConfig jmsConfig = config.getBean(JmsConfig.class, ImmutableMap.of("name", "user-friendship")); Assert.assertTrue(jmsConfig.isEnabled()); } }
@Test public void testConfig() { Config p = Config.getConfig("classpath:/test-config/hierarchy", "production"); Config t = Config.getConfig("classpath:/test-config/hierarchy", "test"); Assert.assertTrue(p.getConfiguration().getBoolean("production")); Assert.assertFalse(t.getConfiguration().getBoolean("production")); }
/** * @deprecated Use {@link ConfigModule#forTesting(String ... keyValuePairs)} */ @Deprecated public ConfigModule(final String ... keyValuePairs) { this(Config.getFixedConfig(keyValuePairs)); }
@Test public void testDefault() { final Config config = Config.getEmptyConfig(); final JmsConfig jmsConfig = config.getBean(JmsConfig.class); Assert.assertTrue(jmsConfig.isEnabled()); }
@Test public void loadStringValues2() { Assert.assertThat(cfg2, is(notNullValue())); final Configuration config = cfg2.getConfiguration(); Assert.assertThat(config, is(notNullValue())); final String s_cfg1 = config.getString("string-null-value"); Assert.assertThat(s_cfg1, is(nullValue())); final String s_cfg2 = config.getString("string-value"); Assert.assertThat(s_cfg2, is("the-test-value")); }
@Test public void testEmpty() { final Config emptyConfig = Config.getEmptyConfig(); Assert.assertNotNull(emptyConfig); Assert.assertFalse(emptyConfig.getConfiguration().getKeys().hasNext()); } }
@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")); }
final Config serviceConfig = Config.getOverriddenConfig(baseConfig, new MapConfiguration(serviceConfigTweaks));
@Test public void testDisabled() { final Config config = Config.getFixedConfig("ness.jms.enabled", "false"); final JmsConfig jmsConfig = config.getBean(JmsConfig.class); Assert.assertFalse(jmsConfig.isEnabled()); }
@Test public void testSuperConfig() { Config ts = Config.getConfig("classpath:/test-config/legacy", "test:test_super"); Configuration c = ts.getConfiguration(); Assert.assertEquals("yay", c.getString("hi")); Assert.assertEquals("frob", c.getString("yay")); }
public static ConfigModule forTesting(final String ... keyValuePairs) { return new ConfigModule(Config.getFixedConfig(keyValuePairs)); }
@Test public void loadBooleanValues2() { Assert.assertThat(cfg2, is(notNullValue())); final Configuration config = cfg2.getConfiguration(); Assert.assertThat(config, is(notNullValue())); final Boolean s_cfg1 = config.getBoolean("boolean-null-value", null); Assert.assertThat(s_cfg1, is(nullValue())); final boolean s_cfg2 = config.getBoolean("boolean-value"); Assert.assertThat(s_cfg2, is(true)); }
@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(); } } }
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)); }
public <T> T getBean(final Class<T> classType, final Map<String, String> replacements) { return getBean(null, classType, replacements); }
@Test public void testEnabled() { final Config config = Config.getFixedConfig("ness.jms.enabled", "true"); final JmsConfig jmsConfig = config.getBean(JmsConfig.class); Assert.assertTrue(jmsConfig.isEnabled()); }