use of org.apache.commons.configuration2.AbstractConfiguration in project hugegraph-common by hugegraph.
the class HugeConfigTest method testHugeConfig.
@Test
public void testHugeConfig() throws Exception {
Configuration conf = new PropertiesConfiguration();
Assert.assertEquals(DisabledListDelimiterHandler.INSTANCE, ((AbstractConfiguration) conf).getListDelimiterHandler());
HugeConfig config = new HugeConfig(conf);
Assert.assertEquals("text1-value", config.get(TestOptions.text1));
Assert.assertEquals("text2-value", config.get(TestOptions.text2));
Assert.assertEquals("CHOICE-1", config.get(TestOptions.text3));
Assert.assertEquals(1, (int) config.get(TestOptions.int1));
Assert.assertEquals(10, (int) config.get(TestOptions.int2));
Assert.assertEquals(10, (int) config.get(TestOptions.int3));
Assert.assertEquals(100L, (long) config.get(TestOptions.long1));
Assert.assertEquals(100.0f, config.get(TestOptions.float1), 0f);
Assert.assertEquals(100.0f, config.get(TestOptions.double1), 0d);
Assert.assertEquals(true, config.get(TestOptions.bool));
Assert.assertEquals(Object.class, config.get(TestOptions.clazz));
Assert.assertThrows(ConfigException.class, () -> {
config.setProperty(TestOptions.clazz.name(), "com.baidu.hugegraph.HugeGraph");
}, e -> {
Assert.assertTrue(e.getCause() instanceof ClassNotFoundException);
});
Assert.assertEquals(Arrays.asList("list-value1", "list-value2"), config.get(TestOptions.list));
Assert.assertEquals(ImmutableMap.of("key1", "value1", "key2", "value2"), config.getMap(TestOptions.map));
Assert.assertEquals(WeekDay.WEDNESDAY, config.get(TestOptions.weekday));
Assert.assertEquals(Arrays.asList(WeekDay.SATURDAY, WeekDay.SUNDAY), config.get(TestOptions.weekdays));
Assert.assertThrows(ConfigException.class, () -> {
new HugeConfig((Configuration) null);
});
}
use of org.apache.commons.configuration2.AbstractConfiguration in project invesdwin-context by invesdwin.
the class URLProperties method createDelegate.
@Override
protected AbstractConfiguration createDelegate() {
final FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class);
builder.setAutoSave(true);
try {
final PropertiesConfiguration conf = builder.configure(new Parameters().fileBased().setURL(url)).getConfiguration();
return conf;
} catch (final ConfigurationException e) {
throw new RuntimeException(e);
}
}
use of org.apache.commons.configuration2.AbstractConfiguration in project commons-configuration by apache.
the class TestConfigurationLogger method testAbstractConfigurationDefaultLogger.
/**
* Tests the logger set per default.
*/
@Test
public void testAbstractConfigurationDefaultLogger() {
final AbstractConfiguration config = new BaseConfiguration();
assertThat("Wrong default logger", config.getLogger().getLog(), instanceOf(NoOpLog.class));
}
use of org.apache.commons.configuration2.AbstractConfiguration in project commons-configuration by apache.
the class TestConfigurationLogger method testAbstractConfigurationSetLogger.
/**
* Tests whether the logger can be set.
*/
@Test
public void testAbstractConfigurationSetLogger() {
final ConfigurationLogger logger = new ConfigurationLogger(getClass());
final AbstractConfiguration config = new BaseConfiguration();
config.setLogger(logger);
assertThat("Logger not set", config.getLogger(), sameInstance(logger));
}
use of org.apache.commons.configuration2.AbstractConfiguration in project commons-configuration by apache.
the class TestServletContextConfiguration method getConfiguration.
@Override
protected AbstractConfiguration getConfiguration() {
final Properties parameters = new Properties();
parameters.setProperty("key1", "value1");
parameters.setProperty("key2", "value2");
parameters.setProperty("list", "value1, value2");
parameters.setProperty("listesc", "value1\\,value2");
// create a servlet context
final ServletContext context = new MockServletContext() {
@Override
public String getInitParameter(final String key) {
return parameters.getProperty(key);
}
@Override
public Enumeration<?> getInitParameterNames() {
return parameters.keys();
}
};
// create a servlet config
final MockServletConfig config = new MockServletConfig();
config.setServletContext(context);
// create a servlet
final Servlet servlet = new HttpServlet() {
/**
* Serial version UID.
*/
private static final long serialVersionUID = 1L;
@Override
public ServletConfig getServletConfig() {
return config;
}
};
final ServletContextConfiguration resultConfig = new ServletContextConfiguration(servlet);
resultConfig.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
return resultConfig;
}
Aggregations