ebourg      2004/07/21 05:36:27

  Modified:    configuration/conf test.xml
               configuration/src/test/org/apache/commons/configuration
                        TestXMLConfiguration.java
  Log:
  More tests for XMLConfiguration
  
  Revision  Changes    Path
  1.3       +12 -2     jakarta-commons/configuration/conf/test.xml
  
  Index: test.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/conf/test.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- test.xml  12 Jul 2004 14:38:29 -0000      1.2
  +++ test.xml  21 Jul 2004 12:36:26 -0000      1.3
  @@ -1,4 +1,7 @@
  -<baseElement>
  +<?xml version="1.0"?>
  +
  +<!-- Test file for XMLConfiguration -->
  +<configuration>
       <element>value</element>
       <element2>
           <subelement>
  @@ -7,6 +10,13 @@
       </element2>
       <element3 name="foo">value</element3>
       <test>
  +        <comment><!-- this value is commented --></comment>
  +        <cdata><![CDATA[<cdata value>]]></cdata>
  +        <entity name="foo&quot;bar">1&lt;2</entity>
  +    </test>
  +
  +    <!-- non string properties -->
  +    <test>
           <short>8</short>
       </test>
  -</baseElement>
  +</configuration>
  
  
  
  1.4       +56 -4     
jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
  
  Index: TestXMLConfiguration.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestXMLConfiguration.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestXMLConfiguration.java 13 Jul 2004 14:10:06 -0000      1.3
  +++ TestXMLConfiguration.java 21 Jul 2004 12:36:27 -0000      1.4
  @@ -21,6 +21,7 @@
   import java.util.Iterator;
   
   import junit.framework.TestCase;
  +import junitx.framework.ArrayAssert;
   
   /**
    * test for loading and saving xml properties files
  @@ -46,6 +47,22 @@
           assertEquals("value", conf.getProperty("element"));
       }
   
  +    public void testGetCommentedProperty()
  +    {
  +        assertEquals(null, conf.getProperty("test.comment"));
  +    }
  +
  +    public void testGetPropertyWithXMLEntity()
  +    {
  +        assertEquals("1<2", conf.getProperty("test.entity"));
  +    }
  +
  +    public void testClearProperty()
  +    {
  +        conf.clearProperty("element");
  +        assertEquals("element", null, conf.getProperty("element"));
  +    }
  +
       public void testGetAttribute() throws Exception
       {
           assertEquals("[EMAIL PROTECTED]", "foo", conf.getProperty("[EMAIL 
PROTECTED]"));
  @@ -161,8 +178,7 @@
           // add an array of strings in an attribute
           for (int i = 1; i < 5; i++)
           {
  -            //conf.addProperty("[EMAIL PROTECTED]", "value" + i);
  -            conf.addProperty("[EMAIL PROTECTED]", "value" + i);
  +            conf.addProperty("[EMAIL PROTECTED]", "value" + i);
           }
   
           // save the configuration
  @@ -171,10 +187,46 @@
           // read the configuration and compare the properties
           XMLConfiguration checkConfig = new XMLConfiguration();
           checkConfig.setFileName(testSaveConf.getAbsolutePath());
  -        for (Iterator i = conf.getKeys(); i.hasNext();) {
  +        checkConfig.load();
  +
  +        for (Iterator i = conf.getKeys(); i.hasNext();)
  +        {
                String key = (String) i.next();
                assertTrue("The saved configuration doesn't contain the key '" + key + 
"'", checkConfig.containsKey(key));
                assertEquals("Value of the '" + key + "' property", 
conf.getProperty(key), checkConfig.getProperty(key));
           }
  +    }
  +
  +    public void testParseElementsNames()
  +    {
  +        // without attribute
  +        String key = "x.y.z";
  +        String[] array = new String[] {"x", "y", "z"};
  +        ArrayAssert.assertEquals("key without attribute", array, 
XMLConfiguration.parseElementNames(key));
  +
  +        // with attribute
  +        key = "[EMAIL PROTECTED]";
  +        ArrayAssert.assertEquals("key with attribute", array, 
XMLConfiguration.parseElementNames(key));
  +
  +        // null key
  +        ArrayAssert.assertEquals("null key", new String[] {}, 
XMLConfiguration.parseElementNames(null));
  +    }
  +
  +    public void testParseAttributeName()
  +    {
  +        // no attribute
  +        String key = "x.y.z";
  +        assertEquals("no attribute", null, 
XMLConfiguration.parseAttributeName(key));
  +
  +        // simple attribute
  +        key = "[EMAIL PROTECTED]";
  +        assertEquals("simple attribute", "name", 
XMLConfiguration.parseAttributeName(key));
  +
  +        // missing end marker
  +        key = "[EMAIL PROTECTED]";
  +        assertEquals("missing end marker", "name", 
XMLConfiguration.parseAttributeName(key));
  +
  +        // null key
  +        assertEquals("null key", null, XMLConfiguration.parseAttributeName(null));
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to