Author: oheger
Date: Wed Apr  3 18:53:03 2013
New Revision: 1464156

URL: http://svn.apache.org/r1464156
Log:
PropertyListConfiguration no longer extends AbstractFileConfiguration.

Modified:
    
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/plist/PropertyListConfiguration.java
    
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/plist/TestPropertyListConfiguration.java
    
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/plist/TestPropertyListConfigurationEvents.java

Modified: 
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/plist/PropertyListConfiguration.java
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/plist/PropertyListConfiguration.java?rev=1464156&r1=1464155&r2=1464156&view=diff
==============================================================================
--- 
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/plist/PropertyListConfiguration.java
 (original)
+++ 
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/plist/PropertyListConfiguration.java
 Wed Apr  3 18:53:03 2013
@@ -17,11 +17,9 @@
 
 package org.apache.commons.configuration.plist;
 
-import java.io.File;
 import java.io.PrintWriter;
 import java.io.Reader;
 import java.io.Writer;
-import java.net.URL;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
@@ -32,9 +30,10 @@ import java.util.Map;
 import java.util.TimeZone;
 
 import org.apache.commons.codec.binary.Hex;
-import org.apache.commons.configuration.AbstractHierarchicalFileConfiguration;
+import org.apache.commons.configuration.BaseHierarchicalConfiguration;
 import org.apache.commons.configuration.Configuration;
 import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.FileBasedConfiguration;
 import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.commons.configuration.MapConfiguration;
 import org.apache.commons.configuration.tree.ConfigurationNode;
@@ -83,7 +82,8 @@ import org.apache.commons.lang.StringUti
  * @author Emmanuel Bourg
  * @version $Id$
  */
-public class PropertyListConfiguration extends 
AbstractHierarchicalFileConfiguration
+public class PropertyListConfiguration extends BaseHierarchicalConfiguration
+    implements FileBasedConfiguration
 {
     /** Constant for the separator parser for the date part. */
     private static final DateComponentParser DATE_SEPARATOR_PARSER = new 
DateSeparatorParser(
@@ -151,39 +151,6 @@ public class PropertyListConfiguration e
         super(c);
     }
 
-    /**
-     * Creates and loads the property list from the specified file.
-     *
-     * @param fileName The name of the plist file to load.
-     * @throws ConfigurationException Error while loading the plist file
-     */
-    public PropertyListConfiguration(String fileName) throws 
ConfigurationException
-    {
-        super(fileName);
-    }
-
-    /**
-     * Creates and loads the property list from the specified file.
-     *
-     * @param file The plist file to load.
-     * @throws ConfigurationException Error while loading the plist file
-     */
-    public PropertyListConfiguration(File file) throws ConfigurationException
-    {
-        super(file);
-    }
-
-    /**
-     * Creates and loads the property list from the specified URL.
-     *
-     * @param url The location of the plist file to load.
-     * @throws ConfigurationException Error while loading the plist file
-     */
-    public PropertyListConfiguration(URL url) throws ConfigurationException
-    {
-        super(url);
-    }
-
     @Override
     public void setProperty(String key, Object value)
     {
@@ -224,7 +191,7 @@ public class PropertyListConfiguration e
         }
     }
 
-    public void load(Reader in) throws ConfigurationException
+    public void read(Reader in) throws ConfigurationException
     {
         PropertyListParser parser = new PropertyListParser(in);
         try
@@ -238,7 +205,7 @@ public class PropertyListConfiguration e
         }
     }
 
-    public void save(Writer out) throws ConfigurationException
+    public void write(Writer out) throws ConfigurationException
     {
         PrintWriter writer = new PrintWriter(out);
         printNode(writer, 0, getRootNode());

Modified: 
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/plist/TestPropertyListConfiguration.java
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/plist/TestPropertyListConfiguration.java?rev=1464156&r1=1464155&r2=1464156&view=diff
==============================================================================
--- 
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/plist/TestPropertyListConfiguration.java
 (original)
+++ 
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/plist/TestPropertyListConfiguration.java
 Wed Apr  3 18:53:03 2013
@@ -40,8 +40,11 @@ import org.apache.commons.configuration.
 import org.apache.commons.configuration.ConfigurationComparator;
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.StrictConfigurationComparator;
+import org.apache.commons.configuration.io.FileHandler;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
 
 /**
  * @author Emmanuel Bourg
@@ -49,16 +52,32 @@ import org.junit.Test;
  */
 public class TestPropertyListConfiguration
 {
+    /** A helper object for dealing with temporary files. */
+    @Rule
+    public TemporaryFolder folder = new TemporaryFolder();
+
     private PropertyListConfiguration config;
 
-    private String testProperties = 
ConfigurationAssert.getTestFile("test.plist").getAbsolutePath();
+    private File testProperties = 
ConfigurationAssert.getTestFile("test.plist");
 
     @Before
     public void setUp() throws Exception
     {
         config = new PropertyListConfiguration();
-        config.setFileName(testProperties);
-        config.load();
+        load(config, testProperties);
+    }
+
+    /**
+     * Loads a configuration from the specified test file.
+     *
+     * @param c the configuration to be loaded
+     * @param f the file to be loaded
+     * @throws ConfigurationException if an error occurs
+     */
+    private static void load(PropertyListConfiguration c, File f)
+            throws ConfigurationException
+    {
+        new FileHandler(c).load(f);
     }
 
     @Test
@@ -72,7 +91,7 @@ public class TestPropertyListConfigurati
     {
         config = new PropertyListConfiguration();
         try {
-            config.load(new StringReader(""));
+            new FileHandler(config).load(new StringReader(""));
             fail("No exception thrown on loading an empty file");
         } catch (ConfigurationException e) {
             // expected
@@ -210,25 +229,29 @@ public class TestPropertyListConfigurati
         assertEquals("date", date, config.getProperty("date"));
     }
 
+    /**
+     * Saves the test configuration to the specified file.
+     *
+     * @param file the target file
+     * @throws ConfigurationException if an error occurs
+     */
+    private void saveConfig(File file) throws ConfigurationException
+    {
+        new FileHandler(config).save(file);
+    }
+
     @Test
     public void testSave() throws Exception
     {
-        File savedFile = new File("target/testsave.plist");
-
-        // remove the file previously saved if necessary
-        if (savedFile.exists())
-        {
-            assertTrue(savedFile.delete());
-        }
+        File savedFile = folder.newFile("testsave.plist");
 
         // save the configuration
-        String filename = savedFile.getAbsolutePath();
-        config.save(filename);
-
+        saveConfig(savedFile);
         assertTrue("The saved file doesn't exist", savedFile.exists());
 
         // read the configuration and compare the properties
-        Configuration checkConfig = new PropertyListConfiguration(new 
File(filename));
+        PropertyListConfiguration checkConfig = new 
PropertyListConfiguration();
+        load(checkConfig, savedFile);
 
         Iterator<String> it = config.getKeys();
         while (it.hasNext())
@@ -278,22 +301,15 @@ public class TestPropertyListConfigurati
     @Test
     public void testSaveEmptyDictionary() throws Exception
     {
-        File savedFile = new File("target/testsave.plist");
-
-        // remove the file previously saved if necessary
-        if (savedFile.exists())
-        {
-            assertTrue(savedFile.delete());
-        }
+        File savedFile = folder.newFile("testsave.plist");
 
         // save the configuration
-        String filename = savedFile.getAbsolutePath();
-        config.save(filename);
-
+        saveConfig(savedFile);
         assertTrue("The saved file doesn't exist", savedFile.exists());
 
         // read the configuration and compare the properties
-        PropertyListConfiguration checkConfig = new 
PropertyListConfiguration(new File(filename));
+        PropertyListConfiguration checkConfig = new 
PropertyListConfiguration();
+        load(checkConfig, savedFile);
 
         
assertFalse(config.getRootNode().getChildren("empty-dictionary").isEmpty());
         
assertFalse(checkConfig.getRootNode().getChildren("empty-dictionary").isEmpty());
@@ -316,12 +332,14 @@ public class TestPropertyListConfigurati
     @Test
     public void testSetDataProperty() throws Exception
     {
+        File saveFile = folder.newFile();
         byte[] expected = new byte[]{1, 2, 3, 4};
-        PropertyListConfiguration config = new PropertyListConfiguration();
+        config = new PropertyListConfiguration();
         config.setProperty("foo", expected);
-        config.save("target/testdata.plist");
+        saveConfig(saveFile);
 
-        PropertyListConfiguration config2 = new 
PropertyListConfiguration("target/testdata.plist");
+        PropertyListConfiguration config2 = new PropertyListConfiguration();
+        load(config2, saveFile);
         Object array = config2.getProperty("foo");
 
         assertNotNull("data not found", array);
@@ -335,12 +353,14 @@ public class TestPropertyListConfigurati
     @Test
     public void testAddDataProperty() throws Exception
     {
+        File saveFile = folder.newFile();
         byte[] expected = new byte[]{1, 2, 3, 4};
-        PropertyListConfiguration config = new PropertyListConfiguration();
+        config = new PropertyListConfiguration();
         config.addProperty("foo", expected);
-        config.save("target/testdata.plist");
+        saveConfig(saveFile);
 
-        PropertyListConfiguration config2 = new 
PropertyListConfiguration("target/testdata.plist");
+        PropertyListConfiguration config2 = new PropertyListConfiguration();
+        load(config2, saveFile);
         Object array = config2.getProperty("foo");
 
         assertNotNull("data not found", array);

Modified: 
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/plist/TestPropertyListConfigurationEvents.java
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/plist/TestPropertyListConfigurationEvents.java?rev=1464156&r1=1464155&r2=1464156&view=diff
==============================================================================
--- 
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/plist/TestPropertyListConfigurationEvents.java
 (original)
+++ 
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/plist/TestPropertyListConfigurationEvents.java
 Wed Apr  3 18:53:03 2013
@@ -19,8 +19,10 @@ package org.apache.commons.configuration
 import java.io.File;
 
 import org.apache.commons.configuration.AbstractConfiguration;
+import org.apache.commons.configuration.ConfigurationAssert;
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.ConfigurationRuntimeException;
+import org.apache.commons.configuration.io.FileHandler;
 
 /**
  * Test class for the events generated by PropertyListConfiguration.
@@ -31,14 +33,16 @@ public class TestPropertyListConfigurati
         AbstractTestPListEvents
 {
     /** Constant for the test file that will be loaded. */
-    private static final File TEST_FILE = new File("conf/test.plist");
+    private static final File TEST_FILE = 
ConfigurationAssert.getTestFile("test.plist");
 
     @Override
     protected AbstractConfiguration createConfiguration()
     {
         try
         {
-            return new PropertyListConfiguration(TEST_FILE);
+            PropertyListConfiguration c = new PropertyListConfiguration();
+            new FileHandler(c).load(TEST_FILE);
+            return c;
         }
         catch (ConfigurationException cex)
         {


Reply via email to