CVS: plexus-container-new/src/test/org/apache/plexus/configuration primitive-attr.xml,NONE,1.1 primitive-element.xml,NONE,1.1 XmlPullConfigurationBuilderTest.java,1.2,1.3

[email protected] Sat, 3 May 2003 08:19:40 -0500
Newsgroups gmane.comp.java.plexus.devel
Message-ID <[email protected]>
Update of /cvsroot/plexus/plexus-container-new/src/test/org/apache/plexus/configuration
In directory eng.werken.com:/tmp/cvs-serv6300

Modified Files:
	XmlPullConfigurationBuilderTest.java 
Added Files:
	primitive-attr.xml primitive-element.xml 
Log Message:
o Test input for configuration tests.


--- NEW FILE: primitive-attr.xml ---
<test>

  <!--
  <integer-floor></integer-floor>
  <integer-ceiling></integer-ceiling>
  <long-floor></long-floor>
  <long-ceiling></long-ceiling>
  <float-floor></float-floor>
  <float-ceiling></float-ceiling>
  -->

  <integer value="0"/>
  <long value="0"/>
  <float value="0"/>

  <boolean-true value="true"/>
  <boolean-yes value="yes"/>
  <boolean-on value="on"/>
  <boolean-1 value="1"/>
  <boolean-false value="false"/>
  <boolean-no value="no"/>
  <boolean-off value="off"/>
  <boolean-0 value="0"/>

</test>

--- NEW FILE: primitive-element.xml ---
<test>

  <!--
  <integer-floor></integer-floor>
  <integer-ceiling></integer-ceiling>
  <long-floor></long-floor>
  <long-ceiling></long-ceiling>
  <float-floor></float-floor>
  <float-ceiling></float-ceiling>
  -->

  <integer>0</integer>
  <long>0</long>
  <float>0</float>

  <boolean-true>true</boolean-true>
  <boolean-yes>yes</boolean-yes>
  <boolean-on>on</boolean-on>
  <boolean-1>1</boolean-1>
  <boolean-false>false</boolean-false>
  <boolean-no>no</boolean-no>
  <boolean-off>off</boolean-off>
  <boolean-0>0</boolean-0>

</test>

Index: XmlPullConfigurationBuilderTest.java
===================================================================
RCS file: /cvsroot/plexus/plexus-container-new/src/test/org/apache/plexus/configuration/XmlPullConfigurationBuilderTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- XmlPullConfigurationBuilderTest.java	3 May 2003 00:38:57 -0000	1.2
+++ XmlPullConfigurationBuilderTest.java	3 May 2003 13:19:34 -0000	1.3
@@ -51,7 +51,6 @@
         throws Exception
     {
         InputStream is = XmlPullConfigurationBuilder.class.getResourceAsStream( "plexus.conf" );
-
         XmlPullConfigurationBuilder cb = new XmlPullConfigurationBuilder();
         Configuration c = cb.parse( new InputStreamReader( is ) );
 
@@ -132,4 +131,49 @@
         assertNotNull( c );
         assertEquals( "melissa", c.getChild( "name" ).getValue() );
     }
+
+    public void testPrimitiveElementRetrieval()
+        throws Exception
+    {
+        InputStream is = XmlPullConfigurationBuilder.class.getResourceAsStream( "primitive-element.xml" );
+        XmlPullConfigurationBuilder cb = new XmlPullConfigurationBuilder();
+        Configuration c = cb.parse( new InputStreamReader( is ) );
+
+        assertTrue( 0 == c.getChild( "integer" ).getValueAsInteger() );
+        assertTrue( 0 == c.getChild( "long" ).getValueAsLong() );
+        assertTrue( 0 == c.getChild( "float" ).getValueAsFloat() );
+
+        assertEquals( true, c.getChild( "boolean-true" ).getValueAsBoolean() );
+        assertEquals( true, c.getChild( "boolean-yes" ).getValueAsBoolean() );
+        assertEquals( true, c.getChild( "boolean-on" ).getValueAsBoolean() );
+        assertEquals( true, c.getChild( "boolean-1" ).getValueAsBoolean() );
+
+        assertEquals( false, c.getChild( "boolean-false" ).getValueAsBoolean() );
+        assertEquals( false, c.getChild( "boolean-no" ).getValueAsBoolean() );
+        assertEquals( false, c.getChild( "boolean-off" ).getValueAsBoolean() );
+        assertEquals( false, c.getChild( "boolean-0" ).getValueAsBoolean() );
+    }
+
+    public void testPrimitiveAttributeRetrieval()
+        throws Exception
+    {
+        InputStream is = XmlPullConfigurationBuilder.class.getResourceAsStream( "primitive-attr.xml" );
+        XmlPullConfigurationBuilder cb = new XmlPullConfigurationBuilder();
+        Configuration c = cb.parse( new InputStreamReader( is ) );
+
+        assertTrue( 0 == c.getChild( "integer" ).getAttributeAsInteger( "value" ) );
+        assertTrue( 0 == c.getChild( "long" ).getAttributeAsInteger( "value" ) );
+        assertTrue( 0 == c.getChild( "float" ).getAttributeAsInteger( "value" ) );
+
+        assertEquals( true, c.getChild( "boolean-true" ).getAttributeAsBoolean( "value" ) );
+        assertEquals( true, c.getChild( "boolean-yes" ).getAttributeAsBoolean( "value" ) );
+        assertEquals( true, c.getChild( "boolean-on" ).getAttributeAsBoolean( "value" ) );
+        assertEquals( true, c.getChild( "boolean-1" ).getAttributeAsBoolean( "value" ) );
+
+        assertEquals( false, c.getChild( "boolean-false" ).getAttributeAsBoolean( "value" ) );
+        assertEquals( false, c.getChild( "boolean-no" ).getAttributeAsBoolean( "value" ) );
+        assertEquals( false, c.getChild( "boolean-off" ).getAttributeAsBoolean( "value" ) );
+        assertEquals( false, c.getChild( "boolean-0" ).getAttributeAsBoolean( "value" ) );
+    }
+
 }