commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1700564 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration2/PropertiesConfiguration.java test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java
Date Tue, 01 Sep 2015 14:23:05 GMT
Author: oheger
Date: Tue Sep  1 14:23:04 2015
New Revision: 1700564

URL: http://svn.apache.org/r1700564
Log:
[CONFIGURATION-609] Use the correct file system for include files.

The FileHandler used for loading include properties dropped some of the
properties configured for the builder. This has been fixed.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java?rev=1700564&r1=1700563&r2=1700564&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java
Tue Sep  1 14:23:04 2015
@@ -1417,6 +1417,7 @@ public class PropertiesConfiguration ext
         }
 
         FileHandler fh = new FileHandler(this);
+        fh.setFileLocator(locator);
         fh.load(url);
     }
 

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=1700564&r1=1700563&r2=1700564&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
Tue Sep  1 14:23:04 2015
@@ -27,15 +27,18 @@ import static org.junit.Assert.assertTru
 import static org.junit.Assert.fail;
 
 import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.Reader;
 import java.io.StringReader;
 import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
 import java.io.Writer;
 import java.net.HttpURLConnection;
 import java.net.URL;
@@ -50,14 +53,18 @@ import java.util.Set;
 
 import org.apache.commons.configuration2.SynchronizerTestImpl.Methods;
 import org.apache.commons.configuration2.builder.FileBasedBuilderParametersImpl;
+import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder;
 import org.apache.commons.configuration2.builder.combined.CombinedConfigurationBuilder;
+import org.apache.commons.configuration2.builder.fluent.Parameters;
 import org.apache.commons.configuration2.convert.DefaultListDelimiterHandler;
 import org.apache.commons.configuration2.convert.DisabledListDelimiterHandler;
 import org.apache.commons.configuration2.convert.LegacyListDelimiterHandler;
 import org.apache.commons.configuration2.convert.ListDelimiterHandler;
 import org.apache.commons.configuration2.event.ConfigurationEvent;
 import org.apache.commons.configuration2.ex.ConfigurationException;
+import org.apache.commons.configuration2.io.DefaultFileSystem;
 import org.apache.commons.configuration2.io.FileHandler;
+import org.apache.commons.configuration2.io.FileSystem;
 import org.apache.commons.lang3.mutable.MutableObject;
 import org.junit.Before;
 import org.junit.Test;
@@ -143,7 +150,7 @@ public class TestPropertiesConfiguration
 
     /**
      * Checks for a property without a value.
-     * 
+     *
      * @param key the key to be checked
      */
     private void checkEmpty(String key)
@@ -1123,6 +1130,50 @@ public class TestPropertiesConfiguration
     }
 
     /**
+     * Tests whether the correct file system is used when loading an include
+     * file. This test is related to CONFIGURATION-609.
+     */
+    @Test
+    public void testLoadIncludeFileViaFileSystem() throws ConfigurationException
+    {
+        conf.clear();
+        conf.addProperty("include", "include.properties");
+        saveTestConfig();
+
+        FileSystem fs = new DefaultFileSystem()
+        {
+            @Override
+            public InputStream getInputStream(URL url)
+                    throws ConfigurationException
+            {
+                if (url.toString().endsWith("include.properties"))
+                {
+                    try
+                    {
+                        return new ByteArrayInputStream(
+                                "test.outcome = success".getBytes("UTF-8"));
+                    }
+                    catch (UnsupportedEncodingException e)
+                    {
+                        throw new ConfigurationException("Unsupported encoding",
+                                e);
+                    }
+                }
+                return super.getInputStream(url);
+            }
+        };
+        Parameters params = new Parameters();
+        FileBasedConfigurationBuilder<PropertiesConfiguration> builder =
+                new FileBasedConfigurationBuilder<PropertiesConfiguration>(
+                        PropertiesConfiguration.class);
+        builder.configure(params.fileBased().setFile(testSavePropertiesFile)
+                .setBasePath(ConfigurationAssert.OUT_DIR.toURI().toString())
+                .setFileSystem(fs));
+        PropertiesConfiguration configuration = builder.getConfiguration();
+        assertEquals("success", configuration.getString("test.outcome"));
+    }
+
+    /**
      * Helper method for testing the content of a list with elements that
      * contain backslashes.
      *



Mime
View raw message