Search in sources :

Example 1 with AbstractConfiguration

use of org.apache.commons.configuration2.AbstractConfiguration in project hugegraph-common by hugegraph.

the class HugeConfigTest method testHugeConfigWithOverride.

@Test
public void testHugeConfigWithOverride() throws Exception {
    Configuration conf = new PropertiesConfiguration();
    Assert.assertEquals(DisabledListDelimiterHandler.INSTANCE, ((AbstractConfiguration) conf).getListDelimiterHandler());
    HugeConfig config = new HugeConfig(conf);
    Assert.assertEquals("text1-value", config.get(TestSubOptions.text1));
    Assert.assertEquals("text2-value-override", config.get(TestSubOptions.text2));
    Assert.assertEquals("textsub-value", config.get(TestSubOptions.textsub));
}
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 2 with AbstractConfiguration

use of org.apache.commons.configuration2.AbstractConfiguration in project invesdwin-context by invesdwin.

the class FileProperties method createDelegate.

@Override
protected AbstractConfiguration createDelegate() {
    final FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class);
    builder.setAutoSave(true);
    try {
        if (!file.exists()) {
            Files.touch(file);
        }
        final PropertiesConfiguration conf = builder.configure(new Parameters().fileBased().setFile(file)).getConfiguration();
        return conf;
    } catch (final ConfigurationException | IOException 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) IOException(java.io.IOException) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration)

Example 3 with AbstractConfiguration

use of org.apache.commons.configuration2.AbstractConfiguration in project invesdwin-context by invesdwin.

the class SystemProperties method createDelegate.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected AbstractConfiguration createDelegate() {
    // CHECKSTYLE:OFF Properties
    final MapConfiguration delegate = new MapConfiguration((Map) System.getProperties());
    // CHECKSTYLE:ON
    delegate.setThrowExceptionOnMissing(true);
    return delegate;
}
Also used : MapConfiguration(org.apache.commons.configuration2.MapConfiguration)

Example 4 with AbstractConfiguration

use of org.apache.commons.configuration2.AbstractConfiguration in project commons-configuration by apache.

the class TestConfigurationLogger method testAbstractConfigurationSetLoggerNull.

/**
 * Tests that the logger can be disabled by setting it to null.
 */
@Test
public void testAbstractConfigurationSetLoggerNull() {
    final AbstractConfiguration config = new BaseConfiguration();
    config.setLogger(new ConfigurationLogger(getClass()));
    config.setLogger(null);
    assertThat("Logger not disabled", 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 5 with AbstractConfiguration

use of org.apache.commons.configuration2.AbstractConfiguration in project commons-configuration by apache.

the class TestAppletConfiguration method getConfiguration.

@Override
protected AbstractConfiguration getConfiguration() {
    final AbstractConfiguration config;
    final Properties parameters = new Properties();
    parameters.setProperty("key1", "value1");
    parameters.setProperty("key2", "value2");
    parameters.setProperty("list", "value1, value2");
    parameters.setProperty("listesc", "value1\\,value2");
    if (supportsApplet) {
        final Applet applet = new Applet() {

            /**
             * Serial version UID.
             */
            private static final long serialVersionUID = 1L;

            @Override
            public String getParameter(final String key) {
                return parameters.getProperty(key);
            }

            @Override
            public String[][] getParameterInfo() {
                return new String[][] { { "key1", "String", "" }, { "key2", "String", "" }, { "list", "String[]", "" }, { "listesc", "String", "" } };
            }
        };
        config = new AppletConfiguration(applet);
    } else {
        config = new MapConfiguration(parameters);
    }
    config.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
    return config;
}
Also used : TestAbstractConfiguration(org.apache.commons.configuration2.TestAbstractConfiguration) AbstractConfiguration(org.apache.commons.configuration2.AbstractConfiguration) DefaultListDelimiterHandler(org.apache.commons.configuration2.convert.DefaultListDelimiterHandler) Applet(java.applet.Applet) MapConfiguration(org.apache.commons.configuration2.MapConfiguration) Properties(java.util.Properties)

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