Java Code Examples for org.apache.commons.configuration2.CombinedConfiguration#getConfiguration()
The following examples show how to use
org.apache.commons.configuration2.CombinedConfiguration#getConfiguration() .
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 |
/** * 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: TestCombinedConfigurationBuilder.java From commons-configuration with Apache License 2.0 | 6 votes |
/** * 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 3
Source File: TestCombinedConfigurationBuilder.java From commons-configuration with Apache License 2.0 | 6 votes |
/** * 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 4
Source File: TestCombinedConfigurationBuilder.java From commons-configuration with Apache License 2.0 | 6 votes |
/** * 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 5
Source File: TestCombinedConfigurationBuilder.java From commons-configuration with Apache License 2.0 | 6 votes |
/** * 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 6
Source File: TestCombinedConfigurationBuilder.java From commons-configuration with Apache License 2.0 | 6 votes |
/** * 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 7
Source File: TestCombinedConfigurationBuilder.java From commons-configuration with Apache License 2.0 | 6 votes |
/** * 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 8
Source File: TestCombinedConfigurationBuilder.java From commons-configuration with Apache License 2.0 | 6 votes |
/** * 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 9
Source File: TestCombinedConfigurationBuilder.java From commons-configuration with Apache License 2.0 | 6 votes |
/** * 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 10
Source File: TestCombinedConfigurationBuilder.java From commons-configuration with Apache License 2.0 | 5 votes |
/** * 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 11
Source File: TestCombinedConfigurationBuilder.java From commons-configuration with Apache License 2.0 | 5 votes |
/** * 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")); }