org.apache.commons.configuration2.CombinedConfiguration Java Examples

The following examples show how to use org.apache.commons.configuration2.CombinedConfiguration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 7 votes vote down vote up
/**
 * Tests if the configuration was correctly created by the builder.
 *
 * @return the combined configuration obtained from the builder
 */
private CombinedConfiguration checkConfiguration()
        throws ConfigurationException
{
    final CombinedConfiguration compositeConfiguration =
            builder.getConfiguration();

    assertEquals("Number of configurations", 3,
            compositeConfiguration.getNumberOfConfigurations());
    assertEquals(PropertiesConfiguration.class, compositeConfiguration
            .getConfiguration(0).getClass());
    assertEquals(XMLPropertiesConfiguration.class, compositeConfiguration
            .getConfiguration(1).getClass());
    assertEquals(XMLConfiguration.class, compositeConfiguration
            .getConfiguration(2).getClass());

    // check the first configuration
    final PropertiesConfiguration pc =
            (PropertiesConfiguration) compositeConfiguration
                    .getConfiguration(0);
    assertNotNull("No properties configuration", pc);

    // check some properties
    checkProperties(compositeConfiguration);
    return compositeConfiguration;
}
 
Example #2
Source File: AliceRecognition.java    From carina with Apache License 2.0 6 votes vote down vote up
private AliceRecognition() {
    try {
        CombinedConfiguration config = new CombinedConfiguration(new MergeCombiner());
        config.addConfiguration(new SystemConfiguration());
        config.addConfiguration(new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class)
                .configure(new Parameters().properties().setFileName(ALICE_PROPERTIES)).getConfiguration());

        this.enabled = config.getBoolean(ALICE_ENABLED, false);
        String url = config.getString(ALICE_SERVICE_URL, null);
        String accessToken = config.getString(ALICE_ACCESS_TOKEN, null);
        String command = config.getString(ALICE_COMMAND, null);

        if (enabled && !StringUtils.isEmpty(url) && !StringUtils.isEmpty(accessToken)) {
            this.client = new AliceClient(url, command);
            this.client.setAuthToken(accessToken);
            this.enabled = this.client.isAvailable();
        }
    } catch (Exception e) {
        LOGGER.error("Unable to initialize Alice: " + e.getMessage(), e);
    }
}
 
Example #3
Source File: CombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new configuration using the specified builder and adds it
 * to the resulting combined configuration.
 *
 * @param ccResult the resulting combined configuration
 * @param decl the current {@code ConfigurationDeclaration}
 * @param builder the configuration builder
 * @throws ConfigurationException if an error occurs
 */
private void addChildConfiguration(final CombinedConfiguration ccResult,
        final ConfigurationDeclaration decl,
        final ConfigurationBuilder<? extends Configuration> builder)
        throws ConfigurationException
{
    try
    {
        ccResult.addConfiguration(
                builder.getConfiguration(),
                decl.getName(), decl.getAt());
    }
    catch (final ConfigurationException cex)
    {
        // ignore exceptions for optional configurations
        if (!decl.isOptional())
        {
            throw cex;
        }
    }
}
 
Example #4
Source File: TestReloadingCombinedConfigurationBuilderFileBased.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method for testing whether the builder's definition file can be
 * reloaded. This method expects that the test builder has been fully
 * initialized.
 *
 * @param defFile the path to the definition file
 * @throws IOException if an I/O error occurs
 * @throws ConfigurationException if a configuration-related error occurs
 * @throws InterruptedException if waiting is interrupted
 */
private void checkReloadDefinitionFile(final File defFile) throws IOException,
        ConfigurationException, InterruptedException
{
    final File src1 = writeReloadFile(null, 1, 0);
    final File src2 = writeReloadFile(null, 1, 1);
    writeDefinitionFile(defFile, src1);
    CombinedConfiguration config = builder.getConfiguration();
    assertEquals("Wrong initial value", 0, config.getInt(testProperty(1)));

    // No change definition file
    boolean reloaded = false;
    for (int attempts = 0; attempts < 50 && !reloaded; attempts++)
    {
        writeDefinitionFile(defFile, src2);
        reloaded = builder.getReloadingController().checkForReloading(null);
        if (!reloaded)
        {
            Thread.sleep(100);
        }
    }
    assertTrue("Need for reload not detected", reloaded);
    config = builder.getConfiguration();
    assertEquals("Wrong reloaded value", 1, config.getInt(testProperty(1)));
}
 
Example #5
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests a reset of the builder. The configuration instance should be
 * created anew.
 */
@Test
public void testResetBuilder() throws ConfigurationException
{
    final Map<String, Object> attrs = new HashMap<>();
    final BasicConfigurationBuilder<? extends HierarchicalConfiguration<ImmutableNode>> defBuilder =
            prepareSubBuilderTest(attrs);
    final CombinedConfiguration cc = builder.getConfiguration();
    final ConfigurationBuilder<? extends Configuration> subBuilder =
            builder.getNamedBuilder(BUILDER_NAME);
    defBuilder.reset();
    final CombinedConfiguration cc2 = builder.getConfiguration();
    assertNotSame("No new configuration instance", cc, cc2);
    final ConfigurationBuilder<? extends Configuration> subBuilder2 =
            builder.getNamedBuilder(BUILDER_NAME);
    assertNotSame("No new sub builder instance", subBuilder, subBuilder2);
}
 
Example #6
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that change listeners registered at sub builders are removed on a
 * reset.
 */
@Test
public void testRemoveSubBuilderListener() throws ConfigurationException
{
    final Map<String, Object> attrs = new HashMap<>();
    prepareSubBuilderTest(attrs);
    builder.getConfiguration();
    final BasicConfigurationBuilder<?> subBuilder =
            (BasicConfigurationBuilder<?>) builder
                    .getNamedBuilder(BUILDER_NAME);
    builder.reset();
    prepareSubBuilderTest(attrs);
    final CombinedConfiguration cc = builder.getConfiguration();
    final BasicConfigurationBuilder<?> subBuilder2 =
            (BasicConfigurationBuilder<?>) builder
                    .getNamedBuilder(BUILDER_NAME);
    assertNotSame("Got the same sub builder", subBuilder, subBuilder2);
    subBuilder.reset();
    assertSame("Configuration was reset", cc, builder.getConfiguration());
}
 
Example #7
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests whether attributes are correctly set on the combined configurations
 * for the override and additional sections.
 */
@Test
public void testCombinedConfigurationAttributes()
        throws ConfigurationException
{
    final File initFile =
            ConfigurationAssert
                    .getTestFile("testCCResultInitialization.xml");
    builder.configure(createParameters()
            .setFile(initFile));
    final CombinedConfiguration cc = builder.getConfiguration();
    checkCombinedConfigAttrs(cc);
    final CombinedConfiguration cc2 =
            (CombinedConfiguration) cc
                    .getConfiguration(CombinedConfigurationBuilder.ADDITIONAL_NAME);
    checkCombinedConfigAttrs(cc2);
}
 
Example #8
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests whether the list node definition was correctly processed.
 */
@Test
public void testCombinedConfigurationListNodes()
        throws ConfigurationException
{
    final File initFile =
            ConfigurationAssert
                    .getTestFile("testCCResultInitialization.xml");
    builder.configure(createParameters()
            .setFile(initFile));
    final CombinedConfiguration cc = builder.getConfiguration();
    Set<String> listNodes = cc.getNodeCombiner().getListNodes();
    assertEquals("Wrong number of list nodes", 2, listNodes.size());
    assertTrue("table node not a list node", listNodes.contains("table"));
    assertTrue("list node not a list node", listNodes.contains("list"));

    final CombinedConfiguration cca =
            (CombinedConfiguration) cc
                    .getConfiguration(CombinedConfigurationBuilder.ADDITIONAL_NAME);
    listNodes = cca.getNodeCombiner().getListNodes();
    assertTrue("Found list nodes for additional combiner",
            listNodes.isEmpty());
}
 
Example #9
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests whether a custom provider can be registered.
 */
@Test
public void testCustomBuilderProvider() throws ConfigurationException
{
    final String tagName = "myTestTag";
    final BaseHierarchicalConfiguration dataConf =
            new BaseHierarchicalConfiguration();
    dataConf.addProperty(tagName, Boolean.TRUE);
    final Map<String, Object> attrs = new HashMap<>();
    attrs.put("config-name", BUILDER_NAME);
    attrs.put("config-at", "tests");
    builder.configure(new CombinedBuilderParametersImpl()
            .setDefinitionBuilder(
                    createDefinitionBuilder(createDefinitionConfig(tagName,
                            attrs))).registerProvider(tagName,
                    decl -> new ConstantConfigurationBuilder(
                            dataConf)));
    final CombinedConfiguration cc = builder.getConfiguration();
    assertEquals("Configuration not added", dataConf,
            cc.getConfiguration(BUILDER_NAME));
    assertEquals("Property not set", Boolean.TRUE,
            cc.getProperty("tests." + tagName));
}
 
Example #10
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests whether environment properties can be added as a configuration
 * source.
 */
@Test
public void testEnvironmentProperties() throws ConfigurationException
{
    final File envFile =
            ConfigurationAssert.getTestFile("testCCEnvProperties.xml");
    builder.configure(createParameters().setFile(envFile));
    final CombinedConfiguration cc = builder.getConfiguration();
    assertFalse("Configuration is empty", cc.isEmpty());

    // The environment may contain settings with values that
    // are altered by interpolation. Disable this for direct access
    // to the String associated with the environment property name.
    cc.setInterpolator(null);

    // Test the environment is available through the configuration
    for (final Map.Entry<String, String> e : System.getenv().entrySet())
    {
        assertEquals("Wrong value for property: " + e.getKey(),
                e.getValue(), cc.getString(e.getKey()));
    }
}
 
Example #11
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests whether an entity resolver can be defined in the definition file.
 */
@Test
public void testCustomEntityResolver() throws ConfigurationException
{
    final File resolverFile =
            ConfigurationAssert.getTestFile("testCCEntityResolver.xml");
    builder.configure(createParameters()
            .setFile(resolverFile));
    final CombinedConfiguration cc = builder.getConfiguration();
    final XMLConfiguration xmlConf =
            (XMLConfiguration) cc.getConfiguration("xml");
    final EntityResolverWithPropertiesTestImpl resolver =
            (EntityResolverWithPropertiesTestImpl) xmlConf
                    .getEntityResolver();
    assertFalse("No lookups", resolver.getInterpolator().getLookups()
            .isEmpty());
}
 
Example #12
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests whether the resulting combined configuration can be customized.
 */
@Test
public void testCustomResultConfiguration() throws ConfigurationException
{
    final File testFile =
            ConfigurationAssert.getTestFile("testCCResultClass.xml");
    final ListDelimiterHandler listHandler = new DefaultListDelimiterHandler('.');
    builder.configure(new CombinedBuilderParametersImpl()
            .setDefinitionBuilderParameters(
                    new XMLBuilderParametersImpl().setFile(testFile))
            .setListDelimiterHandler(listHandler)
            .setThrowExceptionOnMissing(false));
    final CombinedConfiguration cc = builder.getConfiguration();
    assertTrue("Wrong configuration class: " + cc.getClass(),
            cc instanceof CombinedConfigurationTestImpl);
    assertTrue("Wrong exception flag", cc.isThrowExceptionOnMissing());
    assertEquals("Wrong list delimiter handler", listHandler,
            cc.getListDelimiterHandler());
}
 
Example #13
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests whether a configuration builder can itself be declared in a
 * configuration definition file.
 */
@Test
public void testConfigurationBuilderProvider()
        throws ConfigurationException
{
    final BaseHierarchicalConfiguration defConfig =
            new BaseHierarchicalConfiguration();
    defConfig.addProperty("override.configuration[@fileName]",
            TEST_FILE.getAbsolutePath());
    builder.configure(new CombinedBuilderParametersImpl()
            .setDefinitionBuilder(new ConstantConfigurationBuilder(
                    defConfig)));
    final CombinedConfiguration cc = builder.getConfiguration();
    assertEquals("Wrong number of configurations", 1,
            cc.getNumberOfConfigurations());
    checkProperties(cc);
}
 
Example #14
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests whether basic properties defined for the combined configuration are
 * inherited by a child combined configuration builder.
 */
@Test
public void testConfigurationBuilderProviderInheritBasicProperties()
        throws ConfigurationException
{
    final File testFile =
            ConfigurationAssert
                    .getTestFile("testCCCombinedChildBuilder.xml");
    final ListDelimiterHandler listHandler = new DefaultListDelimiterHandler('*');
    final ConfigurationDecoder decoder = EasyMock.createMock(ConfigurationDecoder.class);
    builder.configure(new CombinedBuilderParametersImpl()
            .setDefinitionBuilderParameters(
                    new XMLBuilderParametersImpl().setFile(testFile))
            .setListDelimiterHandler(listHandler)
            .setConfigurationDecoder(decoder));
    final CombinedConfiguration cc = builder.getConfiguration();
    final CombinedConfiguration cc2 =
            (CombinedConfiguration) cc.getConfiguration("subcc");
    assertFalse("Wrong exception flag", cc2.isThrowExceptionOnMissing());
    assertEquals("Wrong list delimiter handler", listHandler,
            cc2.getListDelimiterHandler());
    assertEquals("Wrong decoder", decoder, cc2.getConfigurationDecoder());
}
 
Example #15
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests whether variable substitution works across multiple child
 * configurations and also in the definition configuration.
 */
@Test
public void testInterpolationOverMultipleSources()
        throws ConfigurationException
{
    final File testFile =
            ConfigurationAssert.getTestFile("testInterpolationBuilder.xml");
    builder.configure(createParameters().setFile(testFile));
    final CombinedConfiguration combConfig = builder.getConfiguration();
    assertEquals("Wrong value", "abc-product",
            combConfig.getString("products.product.desc"));
    final XMLConfiguration xmlConfig =
            (XMLConfiguration) combConfig.getConfiguration("test");
    assertEquals("Wrong value from XML config", "abc-product",
            xmlConfig.getString("products/product/desc"));
    final HierarchicalConfiguration<ImmutableNode> subConfig =
            xmlConfig
                    .configurationAt("products/product[@name='abc']", true);
    assertEquals("Wrong value from sub config", "abc-product",
            subConfig.getString("desc"));
}
 
Example #16
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests whether a configuration created by a MultiFileConfigurationBuilder
 * has been initialized correctly.
 */
@Test
public void testMultiTenentConfigurationProperties()
        throws ConfigurationException
{
    final CombinedConfiguration config = createMultiFileConfig("testCCMultiTenent.xml");
    switchToMultiFile("1001");
    final HierarchicalConfiguration<?> multiConf =
            (HierarchicalConfiguration<?>) config
                    .getConfiguration("clientConfig");
    assertTrue(
            "Expression engine not configured",
            multiConf.getExpressionEngine() instanceof XPathExpressionEngine);
    assertEquals("Wrong bg color", "#808080",
            config.getString("colors.background"));
    assertEquals("Wrong text color", "#000000",
            multiConf.getString("colors/text"));
}
 
Example #17
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests whether a newly created instance can be read concurrently without a
 * special synchronizer.
 */
@Test
public void testConcurrentReadAccessWithoutSynchronizer()
        throws ConfigurationException
{
    builder.configure(createParameters()
            .setFile(TEST_FILE));
    final CombinedConfiguration config = builder.getConfiguration();
    final int threadCount = 32;
    final CountDownLatch startLatch = new CountDownLatch(1);
    final ReadThread[] threads = new ReadThread[threadCount];
    for (int i = 0; i < threadCount; i++)
    {
        threads[i] = new ReadThread(config, startLatch);
        threads[i].start();
    }

    startLatch.countDown();
    for (final ReadThread t : threads)
    {
        t.verify();
    }
}
 
Example #18
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests whether builder properties can be inherited by child builders.
 */
@Test
public void testInheritProperties() throws ConfigurationException
{
    final Parameters params = new Parameters();
    final XMLBuilderParameters xmlParams =
            prepareParamsForInheritanceTest(params);
    builder.configure(xmlParams);
    final CombinedConfiguration config = builder.getConfiguration();

    List<String> list = config.getList(String.class, "test/mixed/array");
    assertTrue("Wrong number of elements in list", list.size() > 2);
    final String[] stringArray = config.getStringArray("test/mixed/array");
    assertTrue("Wrong number of elements in array", stringArray.length > 2);
    final XMLConfiguration xmlConfig =
            (XMLConfiguration) config.getConfiguration("xml");
    list = xmlConfig.getList(String.class, "split/list1");
    assertEquals("Wrong number of elements in XML list", 3, list.size());
}
 
Example #19
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests whether the inheritance of builder properties can be disabled.
 */
@Test
public void testSuppressChildBuilderPropertyInheritance()
        throws ConfigurationException
{
    final Parameters params = new Parameters();
    final CombinedBuilderParameters combinedParams =
            params.combined().setInheritSettings(false);
    builder.configure(combinedParams,
            prepareParamsForInheritanceTest(params));
    final CombinedConfiguration config = builder.getConfiguration();

    final XMLConfiguration xmlConfig =
            (XMLConfiguration) config.getConfiguration("xml");
    final List<String> list = xmlConfig.getList(String.class, "split.list1");
    assertEquals("Wrong number of elements in XML list", 1, list.size());
}
 
Example #20
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests if the base path is correctly evaluated.
 */
@Test
public void testBasePathForChildConfigurations()
        throws ConfigurationException
{
    final BaseHierarchicalConfiguration defConfig =
            new BaseHierarchicalConfiguration();
    defConfig.addProperty("properties[@fileName]", "test.properties");
    final File deepDir = new File(ConfigurationAssert.TEST_DIR, "config/deep");
    builder.configure(new CombinedBuilderParametersImpl().setBasePath(
            deepDir.getAbsolutePath()).setDefinitionBuilder(
            new ConstantConfigurationBuilder(defConfig)));
    final CombinedConfiguration config = builder.getConfiguration();
    assertEquals("Wrong property value", "somevalue",
            config.getString("somekey"));
}
 
Example #21
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests whether the force-create attribute is taken into account.
 */
@Test
public void testLoadOptionalForceCreate() throws ConfigurationException
{
    final String name = "optionalConfig";
    final Map<String, Object> attrs = new HashMap<>();
    attrs.put("fileName", "nonExisting.xml");
    attrs.put("config-name", name);
    attrs.put("config-optional", Boolean.TRUE);
    attrs.put("config-forceCreate", Boolean.TRUE);
    final BaseHierarchicalConfiguration defConfig =
            createDefinitionConfig("xml", attrs);
    final BasicConfigurationBuilder<? extends BaseHierarchicalConfiguration> defBuilder =
            createDefinitionBuilder(defConfig);
    builder.configure(new CombinedBuilderParametersImpl()
            .setDefinitionBuilder(defBuilder));
    final CombinedConfiguration cc = builder.getConfiguration();
    assertEquals("Wrong number of configurations", 1,
            cc.getNumberOfConfigurations());
    assertTrue("Wrong configuration type",
            cc.getConfiguration(name) instanceof XMLConfiguration);
}
 
Example #22
Source File: ProtocolHandlerChainImpl.java    From james-project with Apache License 2.0 5 votes vote down vote up
private void registerHandlersPackage(HandlersPackage handlersPackage, HierarchicalConfiguration<ImmutableNode> handlerConfig, List<HierarchicalConfiguration<ImmutableNode>> children) throws ConfigurationException {
    List<String> c = handlersPackage.getHandlers();

    for (String cName : c) {
        CombinedConfiguration conf = new CombinedConfiguration();
        HierarchicalConfiguration<ImmutableNode> cmdConf = addHandler(cName);
        conf.addConfiguration(cmdConf);
        if (handlerConfig != null) {
            conf.addConfiguration(handlerConfig);
        }
        children.add(conf);
    }
}
 
Example #23
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Tests whether a Lookup object can be declared in the definition
 * configuration.
 */
@Test
public void testCustomLookup() throws ConfigurationException
{
    final File testFile = ConfigurationAssert.getTestFile("testCCLookup.xml");
    builder.configure(createParameters()
            .setFile(testFile));
    final CombinedConfiguration cc = builder.getConfiguration();
    assertTrue("Lookup not registered in CC", cc.getInterpolator()
            .getLookups().containsKey("test"));
    final Configuration xmlConf = cc.getConfiguration("xml");
    assertTrue("Lookup not registered in sub config", xmlConf
            .getInterpolator().getLookups().containsKey("test"));
}
 
Example #24
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Tests whether a child configuration builder inherits the event listeners
 * from its parent.
 */
@Test
public void testConfigurationBuilderProviderInheritEventListeners()
        throws ConfigurationException
{
    @SuppressWarnings("unchecked")
    final
    EventListener<Event> l1 = EasyMock.createNiceMock(EventListener.class);
    @SuppressWarnings("unchecked")
    final
    EventListener<ConfigurationEvent> l2 =
            EasyMock.createNiceMock(EventListener.class);
    EasyMock.replay(l1, l2);
    final File testFile =
            ConfigurationAssert
                    .getTestFile("testCCCombinedChildBuilder.xml");
    builder.configure(new XMLBuilderParametersImpl().setFile(testFile));
    builder.addEventListener(Event.ANY, l1);
    builder.addEventListener(ConfigurationEvent.ANY, l2);
    final CombinedConfiguration cc = builder.getConfiguration();
    final CombinedConfiguration cc2 =
            (CombinedConfiguration) cc.getConfiguration("subcc");
    final Collection<EventListener<? super ConfigurationEvent>> listeners =
            cc2.getEventListeners(ConfigurationEvent.ANY);
    assertTrue("Listener 1 not found", listeners.contains(l1));
    assertTrue("Listener 2 not found", listeners.contains(l2));
    final Collection<EventListener<? super Event>> eventListeners =
            cc2.getEventListeners(Event.ANY);
    assertEquals("Wrong number of event listeners", 1,
            eventListeners.size());
    assertTrue("Wrong listener", eventListeners.contains(l1));
}
 
Example #25
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Tests whether an INI configuration source can be added to the combined
 * configuration.
 */
@Test
public void testINIConfiguration() throws ConfigurationException
{
    final File multiFile =
            ConfigurationAssert
                    .getTestFile("testDigesterConfiguration3.xml");
    builder.configure(new CombinedBuilderParametersImpl()
            .setDefinitionBuilderParameters(createParameters()
                    .setFile(multiFile)));
    final CombinedConfiguration cc = builder.getConfiguration();
    assertEquals("Property from ini file not found", "yes",
            cc.getString("testini.loaded"));
}
 
Example #26
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Tests whether a JNDI configuration can be integrated into the combined
 * configuration.
 */
@Test
public void testJndiConfiguration() throws ConfigurationException
{
    final File multiFile =
            ConfigurationAssert
                    .getTestFile("testDigesterConfiguration3.xml");
    builder.configure(new CombinedBuilderParametersImpl()
            .setDefinitionBuilderParameters(createParameters()
                    .setFile(multiFile)));
    final CombinedConfiguration cc = builder.getConfiguration();
    assertTrue("JNDI property not found", cc.getBoolean("test.onlyinjndi"));
}
 
Example #27
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Tests whether a custom provider can be defined in the definition file.
 */
@Test
public void testProviderInDefinitionConfig() throws ConfigurationException
{
    builder.configure(createParameters()
            .setFile(ConfigurationAssert
                    .getTestFile("testCCCustomProvider.xml")));
    final CombinedConfiguration cc = builder.getConfiguration();
    assertTrue("Property not found", cc.getBoolean("testKey"));
}
 
Example #28
Source File: CombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc} This implementation evaluates the {@code result} property
 * of the definition configuration. It creates a combined bean declaration
 * with both the properties specified in the definition file and the
 * properties defined as initialization parameters.
 */
@Override
protected BeanDeclaration createResultDeclaration(final Map<String, Object> params)
        throws ConfigurationException
{
    final BeanDeclaration paramsDecl = super.createResultDeclaration(params);
    final XMLBeanDeclaration resultDecl =
            new XMLBeanDeclaration(getDefinitionConfiguration(),
                    KEY_RESULT, true, CombinedConfiguration.class.getName());
    return new CombinedBeanDeclaration(resultDecl, paramsDecl);
}
 
Example #29
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the structure of the returned combined configuration if there is no
 * additional section.
 */
@Test
public void testCombinedConfigurationNoAdditional()
        throws ConfigurationException
{
    builder.configure(createParameters()
            .setFile(TEST_FILE));
    final CombinedConfiguration cc = builder.getConfiguration();
    assertNull(
            "Additional configuration was found",
            cc.getConfiguration(CombinedConfigurationBuilder.ADDITIONAL_NAME));
}
 
Example #30
Source File: StudioConfigurationImpl.java    From studio with GNU General Public License v3.0 5 votes vote down vote up
private HierarchicalConfiguration<ImmutableNode> loadGlobalRepoConfig() {
    if (config.containsKey(STUDIO_CONFIG_GLOBAL_REPO_OVERRIDE_CONFIG)) {
        Path globalRepoOverrideConfigLocation = Paths.get(config.getString(REPO_BASE_PATH),
                config.getString(GLOBAL_REPO_PATH), config.getString(STUDIO_CONFIG_GLOBAL_REPO_OVERRIDE_CONFIG));
        FileSystemResource fsr = new FileSystemResource(globalRepoOverrideConfigLocation.toFile());
        if (fsr.exists()) {
            ZonedDateTime lastModified = null;
            try {
                lastModified = Instant.ofEpochMilli(fsr.lastModified()).atZone(UTC);
                if ((lastModifiedGlobalRepoConfig == null) || lastModified.isAfter(lastModifiedGlobalRepoConfig)) {
                    YamlConfiguration globalRepoOverrideConfig = new YamlConfiguration();
                    try (InputStream in = fsr.getInputStream()) {
                        globalRepoOverrideConfig.setExpressionEngine(getExpressionEngine());
                        globalRepoOverrideConfig.read(in);

                        if (!globalRepoOverrideConfig.isEmpty()) {
                            logger.debug("Loaded additional configuration from location: {0} \n {1}",
                                    fsr.getPath(), globalRepoOverrideConfig);
                        }
                        globalRepoConfig = globalRepoOverrideConfig;

                    }

                    if (!globalRepoConfig.isEmpty()) {
                        CombinedConfiguration combinedConfig = new CombinedConfiguration(new OverrideCombiner());
                        combinedConfig.setExpressionEngine(getExpressionEngine());
                        combinedConfig.addConfiguration(globalRepoConfig);
                        combinedConfig.addConfiguration(systemConfig);

                        config = combinedConfig;
                    }
                    lastModifiedGlobalRepoConfig = lastModified;
                }
            } catch (IOException | ConfigurationException e) {
                logger.error("Failed to load studio configuration from: " + fsr.getPath(), e);
            }
        }
    }
    return config;
}