commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject cvs commit: jakarta-commons/configuration/src/test/org/apache/commons/configuration TestXMLConfiguration.java
Date Mon, 12 Jul 2004 14:38:29 GMT
ebourg      2004/07/12 07:38:29

  Modified:    configuration/conf test.xml
               configuration/src/test/org/apache/commons/configuration
                        TestXMLConfiguration.java
  Log:
  Better test coverage (addProperty on non initialiazed configurations and attribute properties
tests)
  
  Revision  Changes    Path
  1.2       +11 -10    jakarta-commons/configuration/conf/test.xml
  
  Index: test.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/conf/test.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- test.xml	23 Dec 2003 15:09:05 -0000	1.1
  +++ test.xml	12 Jul 2004 14:38:29 -0000	1.2
  @@ -1,11 +1,12 @@
   <baseElement>
  -  <element>value</element>
  -  <element2>
  -    <subelement>
  -      <subsubelement>I'm complex!</subsubelement>
  -    </subelement>
  -  </element2>
  -  <test>
  -  	<short>8</short>
  -  </test>
  -</baseElement>
  \ No newline at end of file
  +    <element>value</element>
  +    <element2>
  +        <subelement>
  +            <subsubelement>I'm complex!</subsubelement>
  +        </subelement>
  +    </element2>
  +    <element3 name="foo">value</element3>
  +    <test>
  +        <short>8</short>
  +    </test>
  +</baseElement>
  
  
  
  1.2       +41 -3     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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestXMLConfiguration.java	12 Jul 2004 12:14:38 -0000	1.1
  +++ TestXMLConfiguration.java	12 Jul 2004 14:38:29 -0000	1.2
  @@ -17,6 +17,7 @@
   package org.apache.commons.configuration;
   
   import java.io.File;
  +import java.util.List;
   
   import junit.framework.TestCase;
   
  @@ -42,6 +43,34 @@
           assertEquals("value", conf.getProperty("element"));
       }
   
  +    public void testGetAttribute() throws Exception
  +    {
  +        assertEquals("element3{name}", "foo", conf.getProperty("element3[@name]"));
  +    }
  +
  +    public void testClearAttribute() throws Exception
  +    {
  +        conf.clearProperty("element3[@name]");
  +        assertEquals("element3[@name]", null, conf.getProperty("element3[@name]"));
  +    }
  +
  +    public void testSetAttribute() throws Exception
  +    {
  +        conf.setProperty("element3[@name]", "bar");
  +        assertEquals("element3[@name]", "bar", conf.getProperty("element3[@name]"));
  +    }
  +
  +    public void testAddAttribute() throws Exception
  +    {
  +        conf.addProperty("element3[@name]", "bar");
  +
  +        List list = conf.getList("element3[@name]");
  +        assertNotNull("null list", list);
  +        assertTrue("'foo' element missing", list.contains("foo"));
  +        assertTrue("'bar' element missing", list.contains("bar"));
  +        assertEquals("list size", 2, list.size());
  +    }
  +
       public void testGetComplexProperty() throws Exception
       {
           assertEquals("I'm complex!", conf.getProperty("element2.subelement.subsubelement"));
  @@ -74,15 +103,24 @@
   
           assertEquals("I'm complex!", conf.getProperty("element2.subelement.subsubelement"));
       }
  -    
  +
       public void testLoadWithBasePath() throws Exception
       {
           conf = new XMLConfiguration();
  -        
  +
           conf.setFileName("test.xml");
           conf.setBasePath(testBasePath);
           conf.load();
   
           assertEquals("I'm complex!", conf.getProperty("element2.subelement.subsubelement"));
  +    }
  +
  +    public void testAddProperty()
  +    {
  +        // add a property to a non initialized xml configuration
  +        XMLConfiguration config = new XMLConfiguration();
  +        config.addProperty("test.string", "hello");
  +
  +        assertEquals("'test.string'", "hello", config.getString("test.string"));
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message