commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1757890 - in /commons/proper/configuration/trunk/src/test: java/org/apache/commons/configuration2/ resources/
Date Fri, 26 Aug 2016 16:41:38 GMT
Author: oheger
Date: Fri Aug 26 16:41:38 2016
New Revision: 1757890

URL: http://svn.apache.org/viewvc?rev=1757890&view=rev
Log:
[CONFIGURATION-638] Removed temporary files in tests.

Some tests have been rewritten to use JUnit's TemporaryFolder class
to prevent that temporary files or folders remain after test
exectuion. Thanks to Ahmet Celik for the patch.

Modified:
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestDynamicCombinedConfiguration.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java
    commons/proper/configuration/trunk/src/test/resources/testMultiTenentConfigurationBuilder5.xml

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestDynamicCombinedConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestDynamicCombinedConfiguration.java?rev=1757890&r1=1757889&r2=1757890&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestDynamicCombinedConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestDynamicCombinedConfiguration.java
Fri Aug 26 16:41:38 2016
@@ -52,6 +52,8 @@ import org.apache.commons.configuration2
 import org.apache.commons.configuration2.tree.xpath.XPathExpressionEngine;
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.junit.Rule;
+import org.junit.rules.TemporaryFolder;
 
 public class TestDynamicCombinedConfiguration
 {
@@ -72,6 +74,10 @@ public class TestDynamicCombinedConfigur
     /** A helper object for creating builder parameters. */
     private static Parameters parameters;
 
+    /** Helper object for creating temporary files. */
+    @Rule
+    public TemporaryFolder folder = new TemporaryFolder();
+
     @BeforeClass
     public static void setUpOnce()
     {
@@ -342,9 +348,10 @@ public class TestDynamicCombinedConfigur
     {
         final int threadCount = 25;
         System.getProperties().remove("Id");
+        System.setProperty("TemporaryFolder", folder.getRoot().getAbsolutePath());
         // create a new configuration
         File input = new File("target/test-classes/testMultiDynamic_default.xml");
-        File output = new File("target/test-classes/testwrite/testMultiDynamic_default.xml");
+        File output = folder.newFile("testMultiDynamic_default.xml");
         output.delete();
         output.getParentFile().mkdir();
         copyFile(input, output);

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java?rev=1757890&r1=1757889&r2=1757890&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java
Fri Aug 26 16:41:38 2016
@@ -68,6 +68,8 @@ import org.apache.commons.configuration2
 import org.apache.commons.lang3.mutable.MutableObject;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.Rule;
+import org.junit.rules.TemporaryFolder;
 
 /**
  * Test for loading and saving properties files.
@@ -95,6 +97,10 @@ public class TestPropertiesConfiguration
     private static String testBasePath2 = ConfigurationAssert.TEST_DIR.getParentFile().getAbsolutePath();
     private static File testSavePropertiesFile = ConfigurationAssert.getOutFile("testsave.properties");
 
+    /** Helper object for creating temporary files. */
+    @Rule
+    public TemporaryFolder folder = new TemporaryFolder();
+
     @Before
     public void setUp() throws Exception
     {
@@ -297,7 +303,7 @@ public class TestPropertiesConfiguration
     public void testSaveToCustomURL() throws Exception
     {
         // save the configuration to a custom URL
-        URL url = new URL("foo", "", 0, "./target/testsave-custom-url.properties", new FileURLStreamHandler());
+        URL url = new URL("foo", "", 0, folder.newFile("testsave-custom-url.properties").getAbsolutePath(),
new FileURLStreamHandler());
         FileHandler handlerSave = new FileHandler(conf);
         handlerSave.save(url);
 
@@ -778,8 +784,7 @@ public class TestPropertiesConfiguration
     @Test
     public void testFileWithSharpSymbol() throws Exception
     {
-        File file = new File("target/sharp#1.properties");
-        file.createNewFile();
+        File file = folder.newFile("sharp#1.properties");
 
         PropertiesConfiguration conf = new PropertiesConfiguration();
         FileHandler handler = new FileHandler(conf);

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java?rev=1757890&r1=1757889&r2=1757890&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java
Fri Aug 26 16:41:38 2016
@@ -54,6 +54,8 @@ import org.apache.commons.configuration2
 import org.apache.commons.configuration2.tree.xpath.XPathExpressionEngine;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.Rule;
+import org.junit.rules.TemporaryFolder;
 import org.xml.sax.SAXException;
 import org.xml.sax.SAXParseException;
 import org.xml.sax.helpers.DefaultHandler;
@@ -87,11 +89,15 @@ public class TestXMLConfiguration
     /** Constant for the transformer factory property.*/
     static final String PROP_FACTORY = "javax.xml.transform.TransformerFactory";
 
+    /** Helper object for creating temporary files. */
+    @Rule
+    public TemporaryFolder folder = new TemporaryFolder();
+
     /** The File that we test with */
     private final String testProperties = ConfigurationAssert.getTestFile("test.xml").getAbsolutePath();
     private final String testProperties2 = ConfigurationAssert.getTestFile("testDigesterConfigurationInclude1.xml").getAbsolutePath();
-    private final File testSaveConf = ConfigurationAssert.getOutFile("testsave.xml");
-    private final File testSaveFile = ConfigurationAssert.getOutFile("testsample2.xml");
+    private File testSaveConf;
+    private File testSaveFile;
     private final String testFile2 = ConfigurationAssert.getTestFile("sample.xml").getAbsolutePath();
 
     /** Constant for the number of test threads. */
@@ -105,6 +111,8 @@ public class TestXMLConfiguration
     @Before
     public void setUp() throws Exception
     {
+        testSaveConf = folder.newFile("testsave.xml");
+        testSaveFile = folder.newFile("testsample2.xml");
         conf = createFromFile(testProperties);
         removeTestFile();
     }

Modified: commons/proper/configuration/trunk/src/test/resources/testMultiTenentConfigurationBuilder5.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/resources/testMultiTenentConfigurationBuilder5.xml?rev=1757890&r1=1757889&r2=1757890&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/resources/testMultiTenentConfigurationBuilder5.xml
(original)
+++ commons/proper/configuration/trunk/src/test/resources/testMultiTenentConfigurationBuilder5.xml
Fri Aug 26 16:41:38 2016
@@ -32,17 +32,17 @@
     <entity-resolver catalogFiles="catalog.xml"/>
   </header>
   <override>
-    <multiFile filePattern="testwrite/testMultiConfiguration_$${sys:Id}.xml"
+    <multiFile filePattern="${sys:TemporaryFolder}/testMultiConfiguration_$${sys:Id}.xml"
                config-name="clientConfig" config-optional="true"
                config-forceCreate="true" schemaValidation="false">
        <expressionEngine
           config-class="org.apache.commons.configuration2.tree.xpath.XPathExpressionEngine"/>
     </multiFile>
-    <xml fileName="testwrite/testMultiDynamic_default.xml"
+    <xml fileName="${sys:TemporaryFolder}/testMultiDynamic_default.xml"
          config-name="defaultConfig" config-reload="true"
          schemaValidation="false">
       <expressionEngine
           config-class="org.apache.commons.configuration2.tree.xpath.XPathExpressionEngine"/>
     </xml>
   </override>
-</configuration>
\ No newline at end of file
+</configuration>



Mime
View raw message