org.apache.commons.configuration2.BaseHierarchicalConfiguration Java Examples

The following examples show how to use org.apache.commons.configuration2.BaseHierarchicalConfiguration. 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: TestHierarchicalConfigurationEvents.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests whether manipulations of a connected sub configuration trigger correct
 * events.
 */
@Test
public void testSubConfigurationChangedEventConnected()
{
    final HierarchicalConfiguration<ImmutableNode> sub =
            ((BaseHierarchicalConfiguration) config)
                    .configurationAt(EXIST_PROPERTY, true);
    sub.addProperty("newProp", "newValue");
    checkSubnodeEvent(
            listener.nextEvent(ConfigurationEvent.SUBNODE_CHANGED),
            true);
    checkSubnodeEvent(
            listener.nextEvent(ConfigurationEvent.SUBNODE_CHANGED),
            false);
    listener.done();
}
 
Example #2
Source File: TestBaseConfigurationBuilderProvider.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a configuration object describing a configuration source.
 *
 * @param reload a flag whether reload operations are supported
 * @return the configuration object
 */
private HierarchicalConfiguration<?> setUpConfig(final boolean reload)
{
    final HierarchicalConfiguration<?> config = new BaseHierarchicalConfiguration();
    config.addProperty(CombinedConfigurationBuilder.ATTR_RELOAD,
            Boolean.valueOf(reload));
    config.addProperty("[@throwExceptionOnMissing]", Boolean.TRUE);
    config.addProperty("[@path]",
            ConfigurationAssert.getTestFile("test.properties")
                    .getAbsolutePath());
    config.addProperty("listDelimiterHandler[@config-class]",
            DefaultListDelimiterHandler.class.getName());
    config.addProperty(
            "listDelimiterHandler.config-constrarg[@config-value]", ";");
    return config;
}
 
Example #3
Source File: CassandraSmtpTestRuleFactory.java    From james-project with Apache License 2.0 6 votes vote down vote up
private static GuiceJamesServer createJamesServer(Host cassandraHost, TemporaryFolder folder, DNSService dnsService) throws Exception {
    Configuration configuration = Configuration.builder()
        .workingDirectory(folder.newFolder())
        .configurationFromClasspath()
        .build();

    return GuiceJamesServer.forConfiguration(configuration)
        .combineWith(CassandraJamesServerMain.CASSANDRA_SERVER_CORE_MODULE,
            new CassandraBlobStoreModule(),
            SmtpTestRule.SMTP_PROTOCOL_MODULE,
            binder -> binder.bind(MailQueueItemDecoratorFactory.class).to(RawMailQueueItemDecoratorFactory.class),
            binder -> binder.bind(CamelMailetContainerModule.DefaultProcessorsConfigurationSupplier.class)
                .toInstance(BaseHierarchicalConfiguration::new))
        .overrideWith(
            binder -> binder.bind(ClusterConfiguration.class).toInstance(
                DockerCassandra.configurationBuilder(cassandraHost)
                    .build()),
            binder -> binder.bind(KeyspacesConfiguration.class)
                .toInstance(KeyspacesConfiguration.builder()
                    .keyspace(DockerCassandra.KEYSPACE)
                    .cacheKeyspace(DockerCassandra.CACHE_KEYSPACE)
                    .replicationFactor(1)
                    .disableDurableWrites()
                    .build()),
            binder -> binder.bind(DNSService.class).toInstance(dnsService));
}
 
Example #4
Source File: TestXMLBeanDeclaration.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests whether constructor arguments can be queried.
 */
@Test
public void testGetConstructorArgs()
{
    final BaseHierarchicalConfiguration config = prepareNestedBeanDeclarations();
    final XMLBeanDeclaration decl = new XMLBeanDeclaration(config, KEY);
    final Collection<ConstructorArg> args = decl.getConstructorArgs();
    assertEquals("Wrong number of constructor arguments", 2, args.size());
    final Iterator<ConstructorArg> it = args.iterator();
    final ConstructorArg arg1 = it.next();
    assertTrue("No bean declaration", arg1.isNestedBeanDeclaration());
    checkProperties(arg1.getBeanDeclaration(), CTOR_COMPLEX_ATTRIBUTES,
            CTOR_COMPLEX_VALUES);
    assertNull("Got a type", arg1.getTypeName());
    assertEquals("Wrong class name", "TestClass", arg1.getBeanDeclaration()
            .getBeanClassName());
    final ConstructorArg arg2 = it.next();
    assertFalse("A bean declaration", arg2.isNestedBeanDeclaration());
    assertEquals("Wrong value", CTOR_ID, arg2.getValue());
    assertEquals("Wrong type", "long", arg2.getTypeName());
}
 
Example #5
Source File: JPARecomputeCurrentQuotasServiceTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@BeforeEach
void setUp() throws Exception {
    EntityManagerFactory entityManagerFactory = JPA_TEST_CLUSTER.getEntityManagerFactory();
    JPAMailboxSessionMapperFactory mapperFactory = new JPAMailboxSessionMapperFactory(entityManagerFactory,
        new JPAUidProvider(entityManagerFactory),
        new JPAModSeqProvider(entityManagerFactory));

    usersRepository = new JPAUsersRepository(NO_DOMAIN_LIST);
    usersRepository.setEntityManagerFactory(JPA_TEST_CLUSTER.getEntityManagerFactory());
    BaseHierarchicalConfiguration configuration = new BaseHierarchicalConfiguration();
    configuration.addProperty("enableVirtualHosting", "false");
    usersRepository.configure(configuration);

    mailboxManager = JpaMailboxManagerProvider.provideMailboxManager(JPA_TEST_CLUSTER);
    sessionProvider = mailboxManager.getSessionProvider();
    currentQuotaManager = new JpaCurrentQuotaManager(entityManagerFactory);

    userQuotaRootResolver = new DefaultUserQuotaRootResolver(sessionProvider, mapperFactory);

    CurrentQuotaCalculator currentQuotaCalculator = new CurrentQuotaCalculator(mapperFactory, userQuotaRootResolver);

    testee = new RecomputeCurrentQuotasService(usersRepository, currentQuotaManager, currentQuotaCalculator, userQuotaRootResolver, sessionProvider);
}
 
Example #6
Source File: TestBuilderConfigurationWrapperFactory.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests whether event source support of level builder is possible even for a
 * mock builder.
 */
@Test
public void testEventSourceSupportMockBuilder()
{
    final BaseHierarchicalConfiguration conf =
            new BaseHierarchicalConfiguration();
    final ConfigurationBuilder<BaseHierarchicalConfiguration> builder =
            createBuilderMock(conf);
    final EventListenerTestImpl listener = new EventListenerTestImpl(null);
    builder.addEventListener(ConfigurationEvent.ANY, listener);
    EasyMock.replay(builder);

    final BuilderConfigurationWrapperFactory factory =
            new BuilderConfigurationWrapperFactory(EventSourceSupport.BUILDER);
    final EventSource src =
            (EventSource) factory.createBuilderConfigurationWrapper(
                    HierarchicalConfiguration.class, builder);
    src.addEventListener(ConfigurationEvent.ANY, listener);
    EasyMock.verify(builder);
}
 
Example #7
Source File: TestCombinedConfigurationBuilderVFS.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 testSetConfigurationBasePath() throws ConfigurationException
{
    final File deepDir = new File(ConfigurationAssert.TEST_DIR, "config/deep");
    final Map<String, Object> params = new HashMap<>();
    params.put("fileName", "test.properties");
    final BaseHierarchicalConfiguration defConfig =
            createDefinitionConfig("properties", params);
    defConfig.addProperty("override.properties.fileSystem[@config-class]",
            VFSFileSystem.class.getName());
    final BasicConfigurationBuilder<? extends HierarchicalConfiguration<ImmutableNode>> defBuilder =
            createDefinitionBuilder(defConfig);
    builder.configure(new CombinedBuilderParametersImpl()
            .setDefinitionBuilder(defBuilder).setBasePath(
                    deepDir.getAbsolutePath()));
    final Configuration config = builder.getConfiguration();
    assertEquals("Wrong property value", "somevalue",
            config.getString("somekey"));
}
 
Example #8
Source File: TestOverrideCombiner.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method for checking the combined table structure.
 *
 * @param config the config
 * @return the node for the table element
 */
private ImmutableNode checkTable(final BaseHierarchicalConfiguration config)
{
    assertEquals("Wrong number of tables", 0, config
            .getMaxIndex("database.tables.table"));
    final HierarchicalConfiguration<ImmutableNode> c = config
            .configurationAt("database.tables.table");
    assertEquals("Wrong table name", "documents", c.getString("name"));
    assertEquals("Wrong number of fields", 2, c
            .getMaxIndex("fields.field.name"));
    assertEquals("Wrong field", "docname", c
            .getString("fields.field(1).name"));

    final NodeHandler<ImmutableNode> nodeHandler = config.getNodeModel().getNodeHandler();
    final List<QueryResult<ImmutableNode>> nds =
            config.getExpressionEngine().query(nodeHandler.getRootNode(),
                    "database.tables.table",
                    nodeHandler);
    assertFalse("No node found", nds.isEmpty());
    assertFalse("An attribute result", nds.get(0).isAttributeResult());
    return nds.get(0).getNode();
}
 
Example #9
Source File: TestUnionCombiner.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests combination of lists.
 */
@Test
public void testLists() throws ConfigurationException
{
    final BaseHierarchicalConfiguration config = createCombinedConfiguration();
    assertEquals("Too few list elements", 2, config
            .getMaxIndex("net.service.url"));
    assertEquals("Wrong first service", "http://service1.org", config
            .getString("net.service.url(0)"));
    assertEquals("Wrong second service", "http://service2.org", config
            .getString("net.service.url(1)"));
    assertEquals("Wrong service attribute", 2, config
            .getInt("net.service.url(2)[@type]"));
    assertEquals("Wrong number of server elements", 3, config
            .getMaxIndex("net.server.url"));
}
 
Example #10
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 #11
Source File: TestBuilderConfigurationWrapperFactory.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the factory if support for EventSource is disabled.
 */
@Test
public void testEventSourceSupportNone()
{
    final BaseHierarchicalConfiguration conf =
            new BaseHierarchicalConfiguration();
    final ConfigurationBuilder<BaseHierarchicalConfiguration> builder =
            createBuilderMock(conf);
    EasyMock.replay(builder);
    final BuilderConfigurationWrapperFactory factory =
            new BuilderConfigurationWrapperFactory();
    final HierarchicalConfiguration<?> wrapper =
            factory.createBuilderConfigurationWrapper(
                    HierarchicalConfiguration.class, builder);
    assertFalse("EventSource support", wrapper instanceof EventSource);
}
 
Example #12
Source File: TestUnionCombiner.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests combinations of elements with attributes.
 */
@Test
public void testSimpleValuesWithAttributes() throws ConfigurationException
{
    final BaseHierarchicalConfiguration config = createCombinedConfiguration();
    assertEquals("Too few level elements", 1, config
            .getMaxIndex("gui.level"));
    assertEquals("Wrong value of first element", 1, config
            .getInt("gui.level(0)"));
    assertEquals("Wrong value of second element", 4, config
            .getInt("gui.level(1)"));
    assertEquals("Wrong value of first attribute", 2, config
            .getInt("gui.level(0)[@default]"));
    assertFalse("Found wrong attribute", config
            .containsKey("gui.level(0)[@min]"));
    assertEquals("Wrong value of second attribute", 1, config
            .getInt("gui.level(1)[@min]"));
}
 
Example #13
Source File: TestBuilderConfigurationWrapperFactory.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests whether the returned configuration correctly wraps the builder.
 */
@Test
public void testConfigurationBuilderWrapper()
{
    final BaseHierarchicalConfiguration conf =
            new BaseHierarchicalConfiguration();
    final ConfigurationBuilder<BaseHierarchicalConfiguration> builder =
            createBuilderMock(conf);
    EasyMock.replay(builder);
    conf.addProperty("test1", "value1");
    conf.addProperty("test2", "42");
    final BuilderConfigurationWrapperFactory factory =
            new BuilderConfigurationWrapperFactory();
    final HierarchicalConfiguration<?> wrapper =
            factory.createBuilderConfigurationWrapper(
                    HierarchicalConfiguration.class, builder);
    assertEquals("Wrong value (1)", "value1", wrapper.getString("test1"));
    assertEquals("Wrong value (2)", 42, wrapper.getInt("test2"));
    assertSame("Wrong root node", conf.getNodeModel().getNodeHandler()
            .getRootNode(), wrapper.getNodeModel().getNodeHandler()
            .getRootNode());
}
 
Example #14
Source File: CamelMailetContainerModuleTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Test
void getProcessortConfigurationShouldReturnEmptyWhenNoContextSection() throws Exception {
    ConfigurationProvider configurationProvider = mock(ConfigurationProvider.class);
    when(configurationProvider.getConfiguration("mailetcontainer"))
        .thenReturn(new BaseHierarchicalConfiguration());
    XMLConfiguration defaultConfiguration = FileConfigurationProvider.getConfig(new ByteArrayInputStream((
            "<processors>" +
            "  <key>value</key>" +
            "</processors>")
        .getBytes(StandardCharsets.UTF_8)));

    MailetModuleInitializationOperation testee = new MailetModuleInitializationOperation(configurationProvider,
        mock(CamelCompositeProcessor.class),
        NO_TRANSPORT_CHECKS,
        () -> defaultConfiguration,
        mock(DefaultCamelContext.class));

    assertThat(testee.getProcessorConfiguration())
        .isEqualTo(defaultConfiguration);
}
 
Example #15
Source File: PreDeletionHooksConfigurationTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Test
void fromShouldThrowWhenInvalidHookConfiguration() throws Exception {
    XMLConfiguration configuration = FileConfigurationProvider.getConfig(new ByteArrayInputStream((
        "<preDeletionHooks>" +
            "  <preDeletionHook>" +
            "    <class></class>" +
            "  </preDeletionHook>" +
            "</preDeletionHooks>")
        .getBytes(StandardCharsets.UTF_8)));

    HierarchicalConfiguration<ImmutableNode> invalidConfigurationEntry = new BaseHierarchicalConfiguration();
    configuration.addProperty(PreDeletionHooksConfiguration.CONFIGURATION_ENTRY_NAME, ImmutableList.of(invalidConfigurationEntry));

    assertThatThrownBy(() -> PreDeletionHooksConfiguration.from(configuration))
        .isInstanceOf(ConfigurationException.class);
}
 
Example #16
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 #17
Source File: TestXMLBeanDeclaration.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests whether the factory method for creating nested bean declarations
 * gets called.
 */
@Test
public void testGetNestedBeanDeclarationsFactoryMethod()
{
    final BaseHierarchicalConfiguration config = prepareNestedBeanDeclarations();
    final XMLBeanDeclaration decl = new XMLBeanDeclaration(config, KEY)
    {
        @Override
        BeanDeclaration createBeanDeclaration(final NodeData<?> node)
        {
            return new XMLBeanDeclarationTestImpl(getConfiguration()
                    .configurationAt(node.nodeName()), node);
        }
    };
    final Map<String, Object> nested = decl.getNestedBeanDeclarations();
    for (final String element : COMPLEX_PROPS) {
        final Object d = nested.get(element);
        assertTrue("Wrong class for bean declaration: " + d,
                d instanceof XMLBeanDeclarationTestImpl);
    }
}
 
Example #18
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests whether the entity resolver is initialized with other XML-related
 * properties.
 */
@Test
public void testConfigureEntityResolverWithProperties()
        throws ConfigurationException
{
    final HierarchicalConfiguration<ImmutableNode> config = new BaseHierarchicalConfiguration();
    config.addProperty("header.entity-resolver[@config-class]",
            EntityResolverWithPropertiesTestImpl.class.getName());
    final XMLBuilderParametersImpl xmlParams = new XMLBuilderParametersImpl();
    final FileSystem fs = EasyMock.createMock(FileSystem.class);
    final String baseDir = ConfigurationAssert.OUT_DIR_NAME;
    xmlParams.setBasePath(baseDir);
    xmlParams.setFileSystem(fs);
    builder.configureEntityResolver(config, xmlParams);
    final EntityResolverWithPropertiesTestImpl resolver =
            (EntityResolverWithPropertiesTestImpl) xmlParams
                    .getEntityResolver();
    assertSame("File system not set", fs, resolver.getFileSystem());
    assertSame("Base directory not set", baseDir, resolver.getBaseDir());
}
 
Example #19
Source File: TestMergeCombiner.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Tests combination of attributes.
 */
@Test
public void testAttributes() throws ConfigurationException
{
    final BaseHierarchicalConfiguration config = createCombinedConfiguration();
    assertEquals("Wrong value of min attribute", 1, config
            .getInt("gui.level[@min]"));
    assertEquals("Wrong value of default attribute", 2, config
            .getInt("gui.level[@default]"));
    assertEquals("Wrong number of id attributes", 0, config
            .getMaxIndex("database.tables.table(0)[@id]"));
    assertEquals("Wrong value of table id", 1, config
            .getInt("database.tables.table(0)[@id]"));
}
 
Example #20
Source File: TestMergeCombiner.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Tests whether property values are correctly overridden.
 */
@Test
public void testOverrideValues() throws ConfigurationException
{
    final BaseHierarchicalConfiguration config = createCombinedConfiguration();
    assertEquals("Wrong user", "Admin", config
            .getString("base.services.security.login.user"));
    assertEquals("Wrong user type", "default", config
            .getString("base.services.security.login.user[@type]"));
    assertNull("Wrong password", config.getString("base.services.security.login.passwd"));
    assertEquals("Wrong password type", "secret", config
            .getString("base.services.security.login.passwd[@type]"));
}
 
Example #21
Source File: TestXMLBeanDeclaration.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Tests constructing a bean declaration from a key with multiple values.
 * This should cause an exception because keys must be unique.
 */
@Test(expected = ConfigurationRuntimeException.class)
public void testInitFromMultiValueKey()
{
    final BaseHierarchicalConfiguration config = new BaseHierarchicalConfiguration();
    config.addProperty(KEY, "myFirstKey");
    config.addProperty(KEY, "mySecondKey");
    new XMLBeanDeclaration(config, KEY);
}
 
Example #22
Source File: ListenerConfigurationTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void getGroupShouldBeEmptyByDefault() {
    BaseHierarchicalConfiguration configuration = new BaseHierarchicalConfiguration();
    configuration.addProperty("class", "MyClassName");

    ListenerConfiguration listenerConfiguration = ListenerConfiguration.from(configuration);

    assertThat(listenerConfiguration.getGroup()).isEmpty();
}
 
Example #23
Source File: TestXMLBeanDeclaration.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that a missing bean class name does not cause an exception.
 */
@Test
public void testGetBeanClassNameUndefinedWithEx()
{
    final BaseHierarchicalConfiguration config = new BaseHierarchicalConfiguration();
    config.setThrowExceptionOnMissing(true);
    final XMLBeanDeclaration decl = new XMLBeanDeclaration(config);
    assertNull("Got a bean class name", decl.getBeanClassName());
}
 
Example #24
Source File: PackageMetadataReader.java    From obevo with Apache License 2.0 5 votes vote down vote up
private ImmutableHierarchicalConfiguration getConfig(String configContent) {
    if (configContent == null) {
        return new BaseHierarchicalConfiguration();
    }

    Properties props = new Properties();
    try {
        props.load(new StringReader(configContent));
        return ConfigurationUtils.convertToHierarchical(ConfigurationConverter.getConfiguration(props));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example #25
Source File: TestMergeCombiner.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Tests if a list from the first node structure overrides a list in the
 * second structure.
 */
@Test
public void testListFromFirstStructure() throws ConfigurationException
{
    final BaseHierarchicalConfiguration config = createCombinedConfiguration();
    assertEquals("Wrong number of services", 0, config
            .getMaxIndex("net.service.url"));
    assertEquals("Wrong service", "http://service1.org", config
            .getString("net.service.url"));
    assertFalse("Type attribute available", config
            .containsKey("net.service.url[@type]"));
}
 
Example #26
Source File: TestXMLBeanDeclaration.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Tests if the bean's properties are correctly extracted from the
 * configuration object.
 */
@Test
public void testGetBeanProperties()
{
    final BaseHierarchicalConfiguration config = new BaseHierarchicalConfiguration();
    setupBeanDeclaration(config, KEY, TEST_PROPS, TEST_VALUES);
    final XMLBeanDeclaration decl = new XMLBeanDeclaration(config, KEY);
    checkProperties(decl, TEST_PROPS, TEST_VALUES);
}
 
Example #27
Source File: TestXMLBeanDeclaration.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Tests interpolate() if no ConfigurationInterpolator is available.
 */
@Test
public void testInterpolateNoInterpolator()
{
    final BaseHierarchicalConfiguration config = new BaseHierarchicalConfiguration();
    config.addProperty("value", "expectedValue");
    setupBeanDeclaration(config, KEY, TEST_PROPS, TEST_VALUES);
    final String value = "${value}";
    config.addProperty(KEY + ".config-constrarg[@config-value]", value);
    config.setInterpolator(null);
    final XMLBeanDeclaration decl = new XMLBeanDeclaration(config, KEY);
    final Collection<ConstructorArg> args = decl.getConstructorArgs();
    final ConstructorArg arg = args.iterator().next();
    assertEquals("Value was changed", value, arg.getValue());
}
 
Example #28
Source File: TestXMLBeanDeclaration.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Tests fetching the parameter for the bean factory if it is undefined.
 */
@Test
public void testGetBeanFactoryParameterUndefined()
{
    final XMLBeanDeclaration decl = new XMLBeanDeclaration(new BaseHierarchicalConfiguration());
    assertNull(decl.getBeanFactoryParameter());
}
 
Example #29
Source File: TestConfigurationDeclaration.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Tests if special reserved attributes are recognized by the
 * isReservedNode() method. For compatibility reasons the attributes "at"
 * and "optional" are also treated as reserved attributes, but only if there
 * are no corresponding attributes with the "config-" prefix.
 *
 * @param name the attribute name
 */
private void checkOldReservedAttribute(final String name)
{
    final String prefixName = "config-" + name;
    final BaseHierarchicalConfiguration config = new BaseHierarchicalConfiguration();
    config.addProperty(String.format("[@%s]", prefixName), Boolean.TRUE);
    final ConfigurationDeclaration decl = createDeclaration(config);
    assertTrue(prefixName + " attribute not recognized",
            decl.isReservedAttributeName(prefixName));
    config.addProperty(String.format("[@%s]", name), Boolean.TRUE);
    assertFalse(name + " is reserved though config- exists",
            decl.isReservedAttributeName(name));
    assertTrue("config- attribute not recognized when " + name + " exists",
            decl.isReservedAttributeName(prefixName));
}
 
Example #30
Source File: TestXMLBeanDeclaration.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Tests fetching properties if none are defined.
 */
@Test
public void testGetBeanPropertiesEmpty()
{
    final XMLBeanDeclaration decl = new XMLBeanDeclaration(new BaseHierarchicalConfiguration());
    final Map<String, Object> props = decl.getBeanProperties();
    assertTrue("Properties found", props == null || props.isEmpty());
}