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

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

Introduction

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

Prototype

public void addConfiguration(Configuration config) 

Source Link

Document

Add a configuration.

Usage

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

/**
 * Failure Testing:/*w w  w . j  av a 2  s. c  om*/
 *
 * 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 www .  j  ava2s . 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://from  ww w.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  w w.  j  a  v  a  2s  .c o m
 * 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  w  w  .  ja  v  a2s  .  c o  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.// w  w  w . j a v a2  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 w w  .j a  v a  2s .c  o  m
 */
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.//ww w.j a v a  2s  .c  o m
 */
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.xwiki.rendering.test.cts.TestDataParser.java

/**
 * Add Configuration Data loaded from "config.properties" resources.
 *
 * @param configuration the composite configuration to add to
 * @param rootPackageName the package where the configuration properties file is located
 * @param classLoader the class loader from which the configuration is read from
 * @throws Exception in case of error while reading test configuration
 *///from  ww  w  .  j  a v a  2  s  .c o m
private void addConfigurationData(CompositeConfiguration configuration, String rootPackageName,
        ClassLoader classLoader) throws Exception {
    URL configurationURL = classLoader.getResource(rootPackageName + "/config.properties");
    if (configurationURL != null) {
        configuration.addConfiguration(new PropertiesConfiguration(configurationURL));
    }
}

From source file:ro.nextreports.server.web.ApplicationLoaderListener.java

private void config() {

    LOG.info("NextReports Server " + ReleaseInfo.getVersion() + " starting ... ");

    CompositeConfiguration config = new CompositeConfiguration();
    config.addConfiguration(new SystemConfiguration());
    try {/*  w w w  .ja  v a2 s  . c o m*/
        config.addConfiguration(new PropertiesConfiguration(getClass().getResource("/nextserver.properties")));
    } catch (ConfigurationException e) {
        // TODO
        e.printStackTrace();
    }

    File defaultNextServerHomeFolder = new File(System.getProperty("user.home"), ".nextserver");
    String defaultNextServerHome = defaultNextServerHomeFolder.getPath();
    String nextServerHome = config.getString("nextserver.home", defaultNextServerHome);
    LOG.info("nextserver.home = " + nextServerHome);

    String demo = System.getProperty("DEMO");
    LOG.info("DEMO=" + demo);
    boolean installWithDemo = Boolean.valueOf(demo);

    File nextServerHomeFolder = new File(nextServerHome);
    if (!nextServerHomeFolder.exists()) {
        try {
            if (installWithDemo) {
                deployDemoData(nextServerHome);
            } else {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Create nextserver home folder: '" + nextServerHomeFolder + "'");
                }
                FileUtils.forceMkdir(nextServerHomeFolder);
            }
        } catch (IOException e) {
            // TODO
            e.printStackTrace();
        }
    }

    System.setProperty("nextserver.home", nextServerHome);

    //      File defaultJaspersHomeFolder = new File(nextServerHome, "jaspers");
    //      String defaultJaspersHome = defaultJaspersHomeFolder.getPath();
    //      String jaspersHome = config.getString("jaspers.home", defaultJaspersHome);
    //      System.setProperty("jaspers.home", jaspersHome);
    //      if (LOG.isDebugEnabled()) {
    //         LOG.debug("jaspers.home = " + jaspersHome);         
    //      }      

    // indexing.file
    ClassPathResource classPathResource = new ClassPathResource("indexing.xml");
    String indexingFile = null;
    try {
        indexingFile = classPathResource.getFile().getAbsolutePath();
    } catch (IOException e) {
        // TODO
        e.printStackTrace();
    }
    System.setProperty("indexing.file", indexingFile);
    if (LOG.isDebugEnabled()) {
        LOG.debug("indexing.file = " + indexingFile);
    }

    //      String baseUrl = config.getString("nextserver.baseUrl");
    //      String reportsUrl = config.getString("reports.url");
    //      if (LOG.isDebugEnabled()) {
    //         LOG.debug("nextserver.baseUrl = " + baseUrl);
    //         LOG.debug("reports.url = " + reportsUrl);
    //      }
}