You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sk...@apache.org on 2005/02/13 05:45:02 UTC

svn commit: r153601 - in jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions: BeanPropertySetterActionTestCase.java SetPropertyActionTestCase.java

Author: skitching
Date: Sat Feb 12 20:45:00 2005
New Revision: 153601

URL: http://svn.apache.org/viewcvs?view=rev&rev=153601
Log:
Renamed BeanPropertySetterActionTestCase to SetPropertyActionTestCase, and added tests.

Added:
    jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/SetPropertyActionTestCase.java
      - copied, changed from r153315, jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/BeanPropertySetterActionTestCase.java
Removed:
    jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/BeanPropertySetterActionTestCase.java

Copied: jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/SetPropertyActionTestCase.java (from r153315, jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/BeanPropertySetterActionTestCase.java)
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/SetPropertyActionTestCase.java?view=diff&rev=153601&p1=jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/BeanPropertySetterActionTestCase.java&r1=153315&p2=jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/SetPropertyActionTestCase.java&r2=153601
==============================================================================
--- jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/BeanPropertySetterActionTestCase.java (original)
+++ jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/SetPropertyActionTestCase.java Sat Feb 12 20:45:00 2005
@@ -31,10 +31,10 @@
 import org.apache.commons.digester2.Digester;
 
 /**
- * <p>Test Cases for the BeanPropertySetterActionTestCase class.</p>
+ * <p>Test Cases for the SetPropertyActionTestCase class.</p>
  */
 
-public class BeanPropertySetterActionTestCase extends TestCase {
+public class SetPropertyActionTestCase extends TestCase {
     
     public static class TestObject {
         private String name;
@@ -52,7 +52,7 @@
      *
      * @param name Name of the test case
      */
-    public BeanPropertySetterActionTestCase(String name) {
+    public SetPropertyActionTestCase(String name) {
         super(name);
     }
 
@@ -70,7 +70,7 @@
      * Return the tests included in this test suite.
      */
     public static Test suite() {
-        return (new TestSuite(BeanPropertySetterActionTestCase.class));
+        return (new TestSuite(SetPropertyActionTestCase.class));
     }
 
     /**
@@ -84,9 +84,9 @@
     // ------------------------------------------------ 
 
     /**
-     * Test basic operations.
+     * Test use of xml element name as element property.
      */
-    public void testBasicOperations() throws Exception {
+    public void testPropertyIsXmlElementName() throws Exception {
         String inputText = 
             "<root>" +
             "  <name>  Rumplestiltskin  </name>" +
@@ -97,8 +97,54 @@
         Digester d = new Digester();
         TestObject testObject = new TestObject();
         
-        BeanPropertySetterAction action = new BeanPropertySetterAction();
+        SetPropertyAction action = new SetPropertyAction();
         d.addRule("/root/name", action);
+        d.setInitialObject(testObject);
+        d.parse(source);
+        
+        // string was passed ok, and surrounding whitespace was trimmed
+        assertEquals("name property", "Rumplestiltskin", testObject.getName());
+    }
+
+    /**
+     * Test use of explicit property name
+     */
+    public void testExplicitPropertyName() throws Exception {
+        String inputText = 
+            "<root>" +
+            "  <data>  Rumplestiltskin  </data>" +
+            "</root>";
+
+        InputSource source = new InputSource(new StringReader(inputText));
+
+        Digester d = new Digester();
+        TestObject testObject = new TestObject();
+        
+        SetPropertyAction action = new SetPropertyAction("name");
+        d.addRule("/root/data", action);
+        d.setInitialObject(testObject);
+        d.parse(source);
+        
+        // string was passed ok, and surrounding whitespace was trimmed
+        assertEquals("name property", "Rumplestiltskin", testObject.getName());
+    }
+
+    /**
+     * Test use of explicit property name
+     */
+    public void testAttributePropertyName() throws Exception {
+        String inputText = 
+            "<root>" +
+            "  <property target='name'>  Rumplestiltskin  </property>" +
+            "</root>";
+
+        InputSource source = new InputSource(new StringReader(inputText));
+
+        Digester d = new Digester();
+        TestObject testObject = new TestObject();
+        
+        SetPropertyAction action = new SetPropertyAction("", "target", null);
+        d.addRule("/root/property", action);
         d.setInitialObject(testObject);
         d.parse(source);
         



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