You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2014/06/13 21:25:52 UTC
svn commit: r1602502 -
/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestFileBasedConfigurationBuilder.java
Author: oheger
Date: Fri Jun 13 19:25:52 2014
New Revision: 1602502
URL: http://svn.apache.org/r1602502
Log:
Added a test case for saving to a newly created file.
It is tested whether the allowFailOnInit flag is evaluated, so that a
configuration can be created and associated with a not yet existing file.
Later on, the configuration is saved to this file.
Modified:
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestFileBasedConfigurationBuilder.java
Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestFileBasedConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestFileBasedConfigurationBuilder.java?rev=1602502&r1=1602501&r2=1602502&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestFileBasedConfigurationBuilder.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestFileBasedConfigurationBuilder.java Fri Jun 13 19:25:52 2014
@@ -32,9 +32,11 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationAssert;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.commons.configuration.XMLPropertiesConfiguration;
+import org.apache.commons.configuration.builder.fluent.Parameters;
import org.apache.commons.configuration.ex.ConfigurationException;
import org.apache.commons.configuration.io.FileHandler;
import org.apache.commons.configuration.io.FileLocator;
@@ -319,6 +321,25 @@ public class TestFileBasedConfigurationB
}
/**
+ * Tests whether a configuration can be created and associated with a file that does
+ * not yet exist. Later the configuration is saved to this file.
+ */
+ @Test
+ public void testCreateConfigurationNonExistingFileAndThenSave()
+ throws ConfigurationException {
+ File outFile = ConfigurationAssert.getOutFile("save.properties");
+ Parameters parameters = new Parameters();
+ FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<PropertiesConfiguration>(
+ PropertiesConfiguration.class, null, true).configure(parameters
+ .properties().setFile(outFile));
+ Configuration config = builder.getConfiguration();
+ config.setProperty(PROP, 1);
+ builder.save();
+ checkSavedConfig(outFile, 1);
+ assertTrue("Could not remove test file", outFile.delete());
+ }
+
+ /**
* Tests whether auto save mode works.
*/
@Test