Search in sources :

Example 21 with AbstractConfiguration

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);
    });
}
Also used : MapConfiguration(org.apache.commons.configuration2.MapConfiguration) AbstractConfiguration(org.apache.commons.configuration2.AbstractConfiguration) Configuration(org.apache.commons.configuration2.Configuration) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) HugeConfig(com.baidu.hugegraph.config.HugeConfig) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 22 with AbstractConfiguration

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);
    }
}
Also used : FileBasedConfigurationBuilder(org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder) Parameters(org.apache.commons.configuration2.builder.fluent.Parameters) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration)

Example 23 with AbstractConfiguration

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));
}
Also used : AbstractConfiguration(org.apache.commons.configuration2.AbstractConfiguration) BaseConfiguration(org.apache.commons.configuration2.BaseConfiguration) NoOpLog(org.apache.commons.logging.impl.NoOpLog) Test(org.junit.Test)

Example 24 with AbstractConfiguration

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));
}
Also used : AbstractConfiguration(org.apache.commons.configuration2.AbstractConfiguration) BaseConfiguration(org.apache.commons.configuration2.BaseConfiguration) Test(org.junit.Test)

Example 25 with AbstractConfiguration

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;
}
Also used : DefaultListDelimiterHandler(org.apache.commons.configuration2.convert.DefaultListDelimiterHandler) HttpServlet(javax.servlet.http.HttpServlet) MockServletContext(com.mockobjects.servlet.MockServletContext) ServletContext(javax.servlet.ServletContext) MockServletConfig(com.mockobjects.servlet.MockServletConfig) HttpServlet(javax.servlet.http.HttpServlet) Servlet(javax.servlet.Servlet) Properties(java.util.Properties) MockServletContext(com.mockobjects.servlet.MockServletContext)

Aggregations

Test (org.junit.Test)19 DefaultListDelimiterHandler (org.apache.commons.configuration2.convert.DefaultListDelimiterHandler)13 AbstractConfiguration (org.apache.commons.configuration2.AbstractConfiguration)8 MapConfiguration (org.apache.commons.configuration2.MapConfiguration)6 ConfigurationInterpolator (org.apache.commons.configuration2.interpol.ConfigurationInterpolator)5 Lookup (org.apache.commons.configuration2.interpol.Lookup)5 Properties (java.util.Properties)4 BaseConfiguration (org.apache.commons.configuration2.BaseConfiguration)4 Configuration (org.apache.commons.configuration2.Configuration)4 PropertiesConfiguration (org.apache.commons.configuration2.PropertiesConfiguration)4 ListDelimiterHandler (org.apache.commons.configuration2.convert.ListDelimiterHandler)4 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)4 HugeConfig (com.baidu.hugegraph.config.HugeConfig)2 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)2 MockServletConfig (com.mockobjects.servlet.MockServletConfig)2 HashMap (java.util.HashMap)2 Servlet (javax.servlet.Servlet)2 HttpServlet (javax.servlet.http.HttpServlet)2 CompositeConfiguration (org.apache.commons.configuration2.CompositeConfiguration)2 TestAbstractConfiguration (org.apache.commons.configuration2.TestAbstractConfiguration)2