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

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

Introduction

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

Prototype

public XMLConfiguration(URL url) throws ConfigurationException 

Source Link

Document

Creates a new instance of XMLConfiguration.

Usage

From source file:io.datalayer.conf.XmlConfigurationTest.java

/**
 * Tests whether the auto save mechanism is triggered by changes at a
 * subnode configuration./*from  www . j a v a 2  s .  co  m*/
 */
@Test
public void testAutoSaveWithSubnodeConfig() throws ConfigurationException {
    final String newValue = "I am autosaved";
    conf.setFile(testSaveConf);
    conf.setAutoSave(true);
    Configuration sub = conf.configurationAt("element2.subelement");
    sub.setProperty("subsubelement", newValue);
    assertEquals("Change not visible to parent", newValue, conf.getString("element2.subelement.subsubelement"));
    XMLConfiguration conf2 = new XMLConfiguration(testSaveConf);
    assertEquals("Change was not saved", newValue, conf2.getString("element2.subelement.subsubelement"));
}

From source file:io.datalayer.conf.XmlConfigurationTest.java

/**
 * Tests whether a subnode configuration created from another subnode
 * configuration of a XMLConfiguration can trigger the auto save mechanism.
 *///  w  w  w .ja va  2  s. c  om
@Test
public void testAutoSaveWithSubSubnodeConfig() throws ConfigurationException {
    final String newValue = "I am autosaved";
    conf.setFile(testSaveConf);
    conf.setAutoSave(true);
    SubnodeConfiguration sub1 = conf.configurationAt("element2");
    SubnodeConfiguration sub2 = sub1.configurationAt("subelement");
    sub2.setProperty("subsubelement", newValue);
    assertEquals("Change not visible to parent", newValue, conf.getString("element2.subelement.subsubelement"));
    XMLConfiguration conf2 = new XMLConfiguration(testSaveConf);
    assertEquals("Change was not saved", newValue, conf2.getString("element2.subelement.subsubelement"));
}

From source file:com.termmed.reconciliation.RelationshipReconciliation.java

/**
 * Gets the params.//  w w  w. j  a  v a 2s .  com
 *
 * @return the params
 * @throws ConfigurationException the configuration exception
 */
@SuppressWarnings("unchecked")
private void getParams() throws ConfigurationException {

    try {
        xmlConfig = new XMLConfiguration(config);
    } catch (ConfigurationException e) {
        logger.info("Reconciliation Runner - Error happened getting params file." + e.getMessage());
        throw e;
    }

    List<String> relFiles = xmlConfig.getList(I_Constants.CURRENT_INFERRED_RELATIONSHIP_FILES);
    currentRelationshipsFile = new String[relFiles.size()];
    relFiles.toArray(currentRelationshipsFile);

    List<String> prevRelFiles = xmlConfig.getList(I_Constants.PREVIOUS_INFERRED_RELATIONSHIP_FILES);
    if (prevRelFiles != null && prevRelFiles.size() > 0) {
        previousInferredRelationshipsFile = new String[prevRelFiles.size()];
        prevRelFiles.toArray(previousInferredRelationshipsFile);
    }
    outputRelationships = xmlConfig.getString(I_Constants.RELATIONSHIP_FILE);
    logger.info("Reconciliation - Parameters:");
    logger.info("Current Relationship files : ");
    if (currentRelationshipsFile != null) {
        for (String relFile : currentRelationshipsFile) {
            logger.info(relFile);
        }
    }
    logger.info("Previous Relationship files : ");
    if (previousInferredRelationshipsFile != null) {
        for (String relFile : previousInferredRelationshipsFile) {
            logger.info(relFile);
        }
    }
    logger.info("Output Relationship file : " + outputRelationships);
}

From source file:io.datalayer.conf.XmlConfigurationTest.java

/**
 * Tests adding nodes from another configuration.
 *///w  w w .ja  v  a2s .co m
@Test
public void testAddNodesCopy() throws ConfigurationException {
    XMLConfiguration c2 = new XMLConfiguration(testProperties2);
    conf.addNodes("copiedProperties", c2.getRootNode().getChildren());
    conf.save(testSaveConf);
    XMLConfiguration checkConf = new XMLConfiguration();
    checkConf.setFile(testSaveConf);
    checkSavedConfig(checkConf);
}

From source file:io.datalayer.conf.XmlConfigurationTest.java

/**
 * Tests whether the addNodes() method triggers an auto save.
 *//*www  . j a  v  a2  s .  c  o  m*/
@Test
public void testAutoSaveAddNodes() throws ConfigurationException {
    conf.setFile(testSaveConf);
    conf.setAutoSave(true);
    HierarchicalConfiguration.Node node = new HierarchicalConfiguration.Node("addNodesTest", Boolean.TRUE);
    Collection<ConfigurationNode> nodes = new ArrayList<ConfigurationNode>(1);
    nodes.add(node);
    conf.addNodes("test.autosave", nodes);
    XMLConfiguration c2 = new XMLConfiguration(testSaveConf);
    assertTrue("Added nodes are not saved", c2.getBoolean("test.autosave.addNodesTest"));
}

From source file:io.datalayer.conf.XmlConfigurationTest.java

/**
 * Tests registering the publicId of a DTD.
 *//*from   w  w  w.j a  v  a  2  s  . co  m*/
@Test
public void testRegisterEntityId() throws Exception {
    URL dtdURL = getClass().getResource("/properties.dtd");
    final String publicId = "http://commons.apache.org/test/properties.dtd";
    conf = new XMLConfiguration("testDtd.xml");
    conf.setPublicID(publicId);
    conf.save(testSaveConf);
    XMLConfiguration checkConfig = new XMLConfiguration();
    checkConfig.setFile(testSaveConf);
    checkConfig.registerEntityId(publicId, dtdURL);
    checkConfig.setValidating(true);
    checkSavedConfig(checkConfig);
}

From source file:io.datalayer.conf.XmlConfigurationTest.java

/**
 * Tests saving a configuration that was created from a hierarchical
 * configuration. This test exposes bug CONFIGURATION-301.
 *///from  w ww. java2 s .co m
@Test
public void testSaveAfterCreateWithCopyConstructor() throws ConfigurationException {
    HierarchicalConfiguration hc = conf.configurationAt("element2");
    conf = new XMLConfiguration(hc);
    conf.save(testSaveConf);
    XMLConfiguration checkConfig = new XMLConfiguration();
    checkConfig.setFile(testSaveConf);
    checkSavedConfig(checkConfig);
    assertEquals("Wrong name of root element", "element2", checkConfig.getRootElementName());
}

From source file:io.datalayer.conf.XmlConfigurationTest.java

/**
 * Tests whether the name of the root element is copied when a configuration
 * is created using the copy constructor.
 *//*  w ww .  j a  va2  s .c om*/
@Test
public void testCopyRootName() throws ConfigurationException {
    final String rootName = "rootElement";
    final String xml = "<" + rootName + "><test>true</test></" + rootName + ">";
    conf.clear();
    conf.load(new StringReader(xml));
    XMLConfiguration copy = new XMLConfiguration(conf);
    assertEquals("Wrong name of root element", rootName, copy.getRootElementName());
    copy.save(testSaveConf);
    copy = new XMLConfiguration(testSaveConf);
    assertEquals("Wrong name of root element after save", rootName, copy.getRootElementName());
}

From source file:io.datalayer.conf.XmlConfigurationTest.java

@Test
public void testConcurrentGetAndReload() throws Exception {
    // final FileConfiguration config = new
    // PropertiesConfiguration("test.properties");
    final FileConfiguration config = new XMLConfiguration("test.xml");
    config.setReloadingStrategy(new FileAlwaysReloadingStrategy());

    assertTrue("Property not found", config.getProperty("test.short") != null);

    Thread testThreads[] = new Thread[THREAD_COUNT];

    for (int i = 0; i < testThreads.length; ++i) {
        testThreads[i] = new ReloadThread(config);
        testThreads[i].start();//from  w  ww .  j  a v a2s  . c  o  m
    }

    for (int i = 0; i < LOOP_COUNT; i++) {
        assertTrue("Property not found", config.getProperty("test.short") != null);
    }

    for (int i = 0; i < testThreads.length; ++i) {
        testThreads[i].join();
    }
}

From source file:io.datalayer.conf.XmlConfigurationTest.java

/**
 * Tests whether a windows path can be saved correctly. This test is related
 * to CONFIGURATION-428./*w w  w  .  j av  a2  s .c  o  m*/
 */
@Test
public void testSaveWindowsPath() throws ConfigurationException {
    conf.clear();
    conf.addProperty("path", "C:\\Temp");
    StringWriter writer = new StringWriter();
    conf.save(writer);
    String content = writer.toString();
    assertTrue("Path not found: " + content, content.indexOf("<path>C:\\Temp</path>") >= 0);
    conf.save(testSaveFile);
    XMLConfiguration conf2 = new XMLConfiguration(testSaveFile);
    assertEquals("Wrong windows path", "C:\\Temp", conf2.getString("path"));
}