Example usage for org.apache.commons.configuration CompositeConfiguration CompositeConfiguration

List of usage examples for org.apache.commons.configuration CompositeConfiguration CompositeConfiguration

Introduction

In this page you can find the example usage for org.apache.commons.configuration CompositeConfiguration CompositeConfiguration.

Prototype

public CompositeConfiguration() 

Source Link

Document

Creates an empty CompositeConfiguration object which can then be added some other Configuration files

Usage

From source file:org.wso2.andes.server.virtualhost.plugins.SlowConsumerDetectionConfigurationTest.java

/**
 * Failure Testing:// ww w.  ja v a  2  s . c  o m
 *
 * Test that erroneous TimeUnit fails.
 *
 * Valid TimeUnit values vary based on the JVM version i.e. 1.6 added HOURS/DAYS etc.
 *
 * We don't test the values for TimeUnit are accepted other than MILLISECONDS in the
 * positive testing at the start.
 *
 * Here we ensure that an erroneous for TimeUnit correctly throws an exception.
 *
 * We test with 'foo', which will never be a TimeUnit
 *
 */
public void testConfigLoadingInValidTimeUnit() {
    SlowConsumerDetectionConfiguration config = new SlowConsumerDetectionConfiguration();

    String TIMEUNIT = "foo";
    XMLConfiguration xmlconfig = new XMLConfiguration();

    xmlconfig.addProperty("delay", "10");
    xmlconfig.addProperty("timeunit", TIMEUNIT);

    // Create a CompositeConfiguration as this is what the broker uses
    CompositeConfiguration composite = new CompositeConfiguration();
    composite.addConfiguration(xmlconfig);
    try {
        config.setConfiguration("", composite);
        fail("Configuration should fail to validate");
    } catch (ConfigurationException e) {
        assertEquals("Incorrect message.",
                "Unable to configure Slow Consumer Detection invalid TimeUnit:" + TIMEUNIT, e.getMessage());
    }
}

From source file:org.wso2.andes.server.virtualhost.plugins.SlowConsumerDetectionPolicyConfigurationTest.java

/**
 * Input Testing://from   w  ww  . j a  va  2  s  .c o  m
 *
 * Test that a given String can be set and retrieved through the configuration
 *
 * No validation is being performed to ensure that the policy exists. Only
 * that a value can be set for the policy.
 *
 */
public void testConfigLoadingValidConfig() {
    SlowConsumerDetectionPolicyConfiguration config = new SlowConsumerDetectionPolicyConfiguration();

    XMLConfiguration xmlconfig = new XMLConfiguration();

    String policyName = "TestPolicy";
    xmlconfig.addProperty("name", policyName);

    // Create a CompositeConfiguration as this is what the broker uses
    CompositeConfiguration composite = new CompositeConfiguration();
    composite.addConfiguration(xmlconfig);

    try {
        config.setConfiguration("", composite);
    } catch (ConfigurationException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }

    assertEquals("Policy name not retrieved as expected.", policyName, config.getPolicyName());
}

From source file:org.wso2.andes.server.virtualhost.plugins.SlowConsumerDetectionPolicyConfigurationTest.java

/**
 * Failure Testing:/*  www.j  a v a  2 s.  c o  m*/
 *
 * Test that providing a configuration section without the 'name' field
 * causes an exception to be thrown.
 *
 * An empty configuration is provided and the thrown exception message
 * is checked to confirm the right reason. 
 *
 */
public void testConfigLoadingInValidConfig() {
    SlowConsumerDetectionPolicyConfiguration config = new SlowConsumerDetectionPolicyConfiguration();

    XMLConfiguration xmlconfig = new XMLConfiguration();

    // Create a CompositeConfiguration as this is what the broker uses
    CompositeConfiguration composite = new CompositeConfiguration();
    composite.addConfiguration(xmlconfig);

    try {
        config.setConfiguration("", composite);
        fail("Config is invalid so won't validate.");
    } catch (ConfigurationException e) {
        e.printStackTrace();
        assertEquals("Exception message not as expected.", "No Slow consumer policy defined.", e.getMessage());
    }
}

From source file:org.wso2.andes.server.virtualhost.plugins.SlowConsumerDetectionQueueConfigurationTest.java

/**
 * Test a fully loaded configuration file.
 *
 * It is not an error to have all control values specified.
 * <p>// w  ww.ja va 2s. com
 * Here we need to catch the {@link ConfigurationException} that ensues due to lack
 * of a policy plugin.
 */
public void testConfigLoadingValidConfig() {
    SlowConsumerDetectionQueueConfiguration config = new SlowConsumerDetectionQueueConfiguration();

    XMLConfiguration xmlconfig = new XMLConfiguration();

    xmlconfig.addProperty("messageAge", "60000");
    xmlconfig.addProperty("depth", "1024");
    xmlconfig.addProperty("messageCount", "10");

    // Create a CompositeConfiguration as this is what the broker uses
    CompositeConfiguration composite = new CompositeConfiguration();
    composite.addConfiguration(xmlconfig);

    try {
        config.setConfiguration("", composite);
        fail("No Policies are avaialbe to load in a unit test");
    } catch (ConfigurationException e) {
        assertTrue("Exception message incorrect, was: " + e.getMessage(),
                e.getMessage().startsWith("No Slow Consumer Policy specified. Known Policies:["));
    }
}

From source file:org.wso2.andes.server.virtualhost.plugins.SlowConsumerDetectionQueueConfigurationTest.java

/**
 * When we do not specify any control value then a {@link ConfigurationException}
 * must be thrown to remind us./*from  w  ww . j av  a  2 s .  co m*/
 */
public void testConfigLoadingMissingConfig() {
    SlowConsumerDetectionQueueConfiguration config = new SlowConsumerDetectionQueueConfiguration();

    XMLConfiguration xmlconfig = new XMLConfiguration();

    // Create a CompositeConfiguration as this is what the broker uses
    CompositeConfiguration composite = new CompositeConfiguration();
    composite.addConfiguration(xmlconfig);

    try {
        config.setConfiguration("", composite);
        fail("No Policies are avaialbe to load in a unit test");
    } catch (ConfigurationException e) {

        assertEquals("At least one configuration property('messageAge','depth'"
                + " or 'messageCount') must be specified.", e.getMessage());
    }
}

From source file:org.wso2.andes.server.virtualhost.plugins.SlowConsumerDetectionQueueConfigurationTest.java

/**
 * Setting messageAge on its own is enough to have a valid configuration
 *
 * Here we need to catch the {@link ConfigurationException} that ensues due to lack
 * of a policy plugin./*from  w w w  .j a va  2  s . c om*/
 */
public void testConfigLoadingMessageAgeOk() {
    SlowConsumerDetectionQueueConfiguration config = new SlowConsumerDetectionQueueConfiguration();

    XMLConfiguration xmlconfig = new XMLConfiguration();
    xmlconfig.addProperty("messageAge", "60000");

    // Create a CompositeConfiguration as this is what the broker uses
    CompositeConfiguration composite = new CompositeConfiguration();
    composite.addConfiguration(xmlconfig);

    try {
        config.setConfiguration("", composite);
        fail("No Policies are avaialbe to load in a unit test");
    } catch (ConfigurationException e) {
        assertTrue("Exception message incorrect, was: " + e.getMessage(),
                e.getMessage().startsWith("No Slow Consumer Policy specified. Known Policies:["));
    }
}

From source file:org.wso2.andes.server.virtualhost.plugins.SlowConsumerDetectionQueueConfigurationTest.java

/**
 * Setting depth on its own is enough to have a valid configuration.
 *
 * Here we need to catch the {@link ConfigurationException} that ensues due to lack
 * of a policy plugin./*  w  ww  . j av a 2  s.c om*/
 */
public void testConfigLoadingDepthOk() {
    SlowConsumerDetectionQueueConfiguration config = new SlowConsumerDetectionQueueConfiguration();

    XMLConfiguration xmlconfig = new XMLConfiguration();
    xmlconfig.addProperty("depth", "1024");

    // Create a CompositeConfiguration as this is what the broker uses
    CompositeConfiguration composite = new CompositeConfiguration();
    composite.addConfiguration(xmlconfig);

    try {
        config.setConfiguration("", composite);
        fail("No Policies are avaialbe to load in a unit test");
    } catch (ConfigurationException e) {
        assertTrue("Exception message incorrect, was: " + e.getMessage(),
                e.getMessage().startsWith("No Slow Consumer Policy specified. Known Policies:["));
    }
}

From source file:org.wso2.andes.server.virtualhost.plugins.SlowConsumerDetectionQueueConfigurationTest.java

/**
 * Setting messageCount on its own is enough to have a valid configuration.
 *
 * Here we need to catch the {@link ConfigurationException} that ensues due to lack
 * of a policy plugin./* www  .j  a v  a  2s  .  com*/
 */
public void testConfigLoadingMessageCountOk() {
    SlowConsumerDetectionQueueConfiguration config = new SlowConsumerDetectionQueueConfiguration();

    XMLConfiguration xmlconfig = new XMLConfiguration();
    xmlconfig.addProperty("messageCount", "10");

    // Create a CompositeConfiguration as this is what the broker uses
    CompositeConfiguration composite = new CompositeConfiguration();
    composite.addConfiguration(xmlconfig);

    try {
        config.setConfiguration("", composite);
        fail("No Policies are avaialbe to load in a unit test");
    } catch (ConfigurationException e) {
        assertTrue("Exception message incorrect, was: " + e.getMessage(),
                e.getMessage().startsWith("No Slow Consumer Policy specified. Known Policies:["));
    }
}

From source file:org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization.config.AuthorizationConfiguration.java

public static void initialize() throws AuthorizationException {
    String brokerConfigFilePath = ROOT_CONFIG_FILE_PATH + ROOT_CONFIG_FILE_NAME;
    if (log.isDebugEnabled()) {
        log.debug("Configuration located at : " + brokerConfigFilePath);
    }/*from w ww  .  j a  v  a 2 s .c  o  m*/
    try {
        compositeConfiguration = new CompositeConfiguration();
        compositeConfiguration.setDelimiterParsingDisabled(true);
        XMLConfiguration rootConfiguration = new XMLConfiguration();
        rootConfiguration.setDelimiterParsingDisabled(true);
        rootConfiguration.setFileName(brokerConfigFilePath);
        rootConfiguration.setExpressionEngine(new XPathExpressionEngine());
        rootConfiguration.load();
        readConfigurationFromFile(brokerConfigFilePath);
        compositeConfiguration.addConfiguration(rootConfiguration);
    } catch (FileNotFoundException e) {
        String error = "Error occurred when trying to read the configuration file : " + brokerConfigFilePath;
        log.error(error, e);
        throw new AuthorizationException(error, e);
    } catch (JaxenException e) {
        String error = "Error occurred when trying to process file : " + brokerConfigFilePath;
        log.error(error, e);
        throw new AuthorizationException(error, e);
    } catch (XMLStreamException e) {
        String error = "Error occurred when trying to process file : " + brokerConfigFilePath;
        log.error(error, e);
        throw new AuthorizationException(error, e);
    } catch (ConfigurationException e) {
        String error = "Error occurred when trying to process file :" + brokerConfigFilePath;
        log.error(error, e);
        throw new AuthorizationException(error, e);
    }
}

From source file:org.xwiki.rendering.test.cts.TestDataParser.java

/**
 * Parse Test configuration by looking for a {@code config.properties} file in the Syntax directory.
 *
 * @param syntaxDirectory the syntax directory under which to look for the configuration file
 * @param ctsRootPackageName the root of the CTS resources
 * @param classLoader the class loader from which the test configuration is read from
 * @return the configuration// w  w  w  . j  a v  a2  s  . c  om
 * @throws Exception in case of error while reading test configuration
 */
public TestDataConfiguration parseTestConfiguration(String syntaxDirectory, String ctsRootPackageName,
        ClassLoader classLoader) throws Exception {
    TestDataConfiguration configuration = new TestDataConfiguration();

    CompositeConfiguration compositeConfiguration = new CompositeConfiguration();
    addConfigurationData(compositeConfiguration, ctsRootPackageName, classLoader);
    addConfigurationData(compositeConfiguration, syntaxDirectory, classLoader);

    // TODO: Remove these unsafe casts, need to find out how to do that nicely...
    configuration.notApplicableTests = (List<String>) (List<?>) compositeConfiguration
            .getList("notApplicableTests", Collections.emptyList());
    configuration.failingTests = (List<String>) (List<?>) compositeConfiguration.getList("failingTests",
            Collections.emptyList());
    configuration.testDescriptions = compositeConfiguration.getProperties("testDescriptions", new Properties());
    configuration.inheritSyntax = compositeConfiguration.getString("inheritSyntax");

    return configuration;
}