commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1028460 - in /commons/proper/configuration/branches/configuration2_experimental/src: main/java/org/apache/commons/configuration2/base/impl/ test/java/org/apache/commons/configuration2/base/impl/
Date Thu, 28 Oct 2010 20:23:18 GMT
Author: oheger
Date: Thu Oct 28 20:23:18 2010
New Revision: 1028460

URL: http://svn.apache.org/viewvc?rev=1028460&view=rev
Log:
[CONFIGURATION-424] INIConfigurationSource was also partly affected.

Modified:
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/impl/INIConfigurationSource.java
    commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/base/impl/TestINIConfigurationSource.java

Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/impl/INIConfigurationSource.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/impl/INIConfigurationSource.java?rev=1028460&r1=1028459&r2=1028460&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/impl/INIConfigurationSource.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/impl/INIConfigurationSource.java
Thu Oct 28 20:23:18 2010
@@ -214,21 +214,22 @@ public class INIConfigurationSource exte
     {
         Set<String> sections = new LinkedHashSet<String>();
         boolean globalSection = false;
+        boolean inSection = false;
 
         for (ConfigurationNode node : getRootNode().getChildren())
         {
             if (isSectionNode(node))
             {
-                if (globalSection)
-                {
-                    sections.add(null);
-                    globalSection = false;
-                }
+                inSection = true;
                 sections.add(node.getName());
             }
             else
             {
-                globalSection = true;
+                if(!inSection && !globalSection)
+                {
+                    globalSection = true;
+                    sections.add(null);
+                }
             }
         }
 

Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/base/impl/TestINIConfigurationSource.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/base/impl/TestINIConfigurationSource.java?rev=1028460&r1=1028459&r2=1028460&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/base/impl/TestINIConfigurationSource.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/base/impl/TestINIConfigurationSource.java
Thu Oct 28 20:23:18 2010
@@ -89,9 +89,13 @@ public class TestINIConfigurationSource
             + LINE_SEPARATOR + "  line 2" + LINE_SEPARATOR
             + "continueNoLine = one \\" + LINE_SEPARATOR;
 
+    /** An ini file that contains only a property in the global section. */
+    private static final String INI_DATA_GLOBAL_ONLY = "globalVar = testGlobal"
+            + LINE_SEPARATOR + LINE_SEPARATOR;
+
     /** An ini file with a global section. */
-    private static final String INI_DATA_GLOBAL = "globalVar = testGlobal"
-            + LINE_SEPARATOR + LINE_SEPARATOR + INI_DATA;
+    private static final String INI_DATA_GLOBAL = INI_DATA_GLOBAL_ONLY
+            + INI_DATA;
 
     /** Constant for the name of the test output file. */
     private static final String TEST_OUT_FILE = "test.ini";
@@ -186,17 +190,41 @@ public class TestINIConfigurationSource
     }
 
     /**
+     * Helper method for testing a save operation. This method constructs a
+     * configuration source from the specified content string. Then it saves
+     * this source and checks whether the result matches the original content.
+     *
+     * @param content the content of the configuration source
+     * @throws ConfigurationException if an error occurs
+     */
+    private void checkSave(String content) throws ConfigurationException,
+            IOException
+    {
+        load(content);
+        StringWriter writer = new StringWriter();
+        source.save(writer);
+        assertEquals("Wrong content of ini file", content, writer.toString());
+    }
+
+    /**
      * Tests whether a configuration source with a global section can be saved.
      */
     @Test
     public void testSaveWithGlobalSection() throws ConfigurationException,
             IOException
     {
-        load(INI_DATA_GLOBAL);
-        StringWriter writer = new StringWriter();
-        source.save(writer);
-        assertEquals("Wrong content of ini file", INI_DATA_GLOBAL, writer
-                .toString());
+        checkSave(INI_DATA_GLOBAL);
+    }
+
+    /**
+     * Tests whether a configuration source that contains only a global section
+     * can be saved correctly.
+     */
+    @Test
+    public void testSaveWithOnlyGlobalSection() throws ConfigurationException,
+            IOException
+    {
+        checkSave(INI_DATA_GLOBAL_ONLY);
     }
 
     /**
@@ -466,6 +494,18 @@ public class TestINIConfigurationSource
     }
 
     /**
+     * Tests whether the sections of a configuration can be queried that
+     * contains only a global section.
+     */
+    @Test
+    public void testGetSectionsGlobalOnly() throws ConfigurationException
+    {
+        checkSectionNames(INI_DATA_GLOBAL_ONLY, new String[] {
+            null
+        });
+    }
+
+    /**
      * Tests whether variables containing a dot are not misinterpreted as
      * sections. This test is related to CONFIGURATION-327.
      */



Mime
View raw message