Package org.apache.commons.configuration2.io

Examples of org.apache.commons.configuration2.io.FileHandler


    {
        String simpleConfigurationFile = ConfigurationAssert.getTestFile("testSequence.properties").getAbsolutePath();
        String compositeConfigurationFile = ConfigurationAssert.getTestFile("testSequenceDigester.xml").getAbsolutePath();

        PropertiesConfiguration simpleConfiguration = new PropertiesConfiguration();
        FileHandler handler = new FileHandler(simpleConfiguration);
        handler.setFileName(simpleConfigurationFile);
        handler.load();

        CombinedConfigurationBuilder builder = new CombinedConfigurationBuilder();
        builder.configure(new FileBasedBuilderParametersImpl().setFileName(compositeConfigurationFile));
        Configuration compositeConfiguration = builder.getConfiguration();
View Full Code Here


    {
        String simpleConfigurationFile = ConfigurationAssert.getTestFile("testSequence.properties").getAbsolutePath();
        String compositeConfigurationFile = ConfigurationAssert.getTestFile("testSequenceDigester.xml").getAbsolutePath();

        PropertiesConfiguration simpleConfiguration = new PropertiesConfiguration();
        FileHandler handler = new FileHandler(simpleConfiguration);
        handler.setFileName(simpleConfigurationFile);
        handler.load();

        CombinedConfigurationBuilder builder = new CombinedConfigurationBuilder();
        builder.configure(new FileBasedBuilderParametersImpl().setFileName(compositeConfigurationFile));
        Configuration compositeConfiguration = builder.getConfiguration();
View Full Code Here

    @Before
    public void setUp() throws Exception
    {
        PropertiesConfiguration c = new PropertiesConfiguration();
        FileHandler handler = new FileHandler(c);
        handler.setFileName(testProperties);
        handler.load();
        conf = c;
        nonStringTestHolder.setConfiguration(conf);
    }
View Full Code Here

     * Tests to save a modified configuration.
     */
    @Test
    public void testSaveModified() throws Exception
    {
        FileHandler handler = new FileHandler(config);
        handler.setFile(new File(TEST_FILE3));
        handler.load();

        assertTrue(config.getString("mean").startsWith("This is\n A long story..."));
        assertTrue(config.getString("mean").indexOf("And even longer") > 0);
        config.clearProperty("test.entity[@name]");
        config.setProperty("element", "new value");
        config.setProperty("test(0)", "A <new> value");
        config.addProperty("test(1).int", new Integer(9));
        config.addProperty("list(1).sublist.item", "seven");
        config.setProperty("clear", "yes");
        config.setProperty("mean", "now it's simple");
        config.addProperty("[@topattr]", "available");
        config.addProperty("[@topattr_other]", "successfull");

        File saveFile = folder.newFile(TEST_SAVENAME);
        handler.save(saveFile);
        config = new XMLConfiguration();
        handler = new FileHandler(config);
        handler.load(saveFile.getAbsolutePath());
        assertFalse(config.containsKey("test.entity[@name]"));
        assertEquals("1<2", config.getProperty("test.entity"));
        assertEquals("new value", config.getString("element"));
        assertEquals("A <new> value", config.getProperty("test(0)"));
        assertEquals((short) 8, config.getShort("test(1).short"));
View Full Code Here

     * configuration was loaded from a file.
     */
    @Test(expected = UnsupportedOperationException.class)
    public void testSetRootElementNameWhenLoadedFromFile() throws Exception
    {
        FileHandler handler = new FileHandler(config);
        handler.setFile(new File(TEST_FILE3));
        handler.load();
        assertEquals("testconfig", config.getRootElementName());
        config.setRootElementName("anotherRootElement");
    }
View Full Code Here

    private Configuration setupSimpleConfiguration()
            throws Exception
    {
        String simpleConfigurationFile = ConfigurationAssert.getTestFile("testEqual.properties").getAbsolutePath();
        PropertiesConfiguration c = new PropertiesConfiguration();
        FileHandler handler = new FileHandler(c);
        handler.setFileName(simpleConfigurationFile);
        handler.load();
        return c;
    }
View Full Code Here

     * Tests whether a file handler is accepted by the constructor.
     */
    @Test
    public void testInitFileHandler()
    {
        FileHandler handler = new FileHandler();
        FileBasedBuilderParametersImpl params =
                new FileBasedBuilderParametersImpl(handler);
        assertSame("Wrong handler", handler, params.getFileHandler());
    }
View Full Code Here

    @Test
    public void testClone()
    {
        FileBased content = EasyMock.createMock(FileBased.class);
        EasyMock.replay(content);
        FileHandler fh = new FileHandler(content);
        FileBasedBuilderParametersImpl params =
                new FileBasedBuilderParametersImpl(fh);
        params.setThrowExceptionOnMissing(true);
        params.setFileName("test.xml");
        FileBasedBuilderParametersImpl clone = params.clone();
View Full Code Here

     */
    private static void checkSavedConfig(File file, int expValue)
            throws ConfigurationException
    {
        PropertiesConfiguration config = new PropertiesConfiguration();
        FileHandler handler = new FileHandler(config);
        handler.load(file);
        assertEquals("Configuration was not saved", expValue,
                config.getInt(PROP));
    }
View Full Code Here

            throws ConfigurationException
    {
        FileBasedConfigurationBuilder<PropertiesConfiguration> builder =
                new FileBasedConfigurationBuilder<PropertiesConfiguration>(
                        PropertiesConfiguration.class);
        FileHandler handler = new FileHandler();
        builder.initFileHandler(handler);
        assertEquals("Wrong encoding",
                PropertiesConfiguration.DEFAULT_ENCODING, handler.getEncoding());
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.configuration2.io.FileHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.