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/12 12:13:49 UTC
svn commit: r153496 -
jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions
Author: skitching
Date: Sat Feb 12 03:13:47 2005
New Revision: 153496
URL: http://svn.apache.org/viewcvs?view=rev&rev=153496
Log:
More test cases for CallParam actions
Added:
jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/CallParamAttributeActionTestCase.java (with props)
jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/CallParamBodyActionTestCase.java (with props)
jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/CallParamFromStackActionTestCase.java (with props)
jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/CallParamPathActionTestCase.java (with props)
Modified:
jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/CallParamLiteralActionTestCase.java
Added: jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/CallParamAttributeActionTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/CallParamAttributeActionTestCase.java?view=auto&rev=153496
==============================================================================
--- jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/CallParamAttributeActionTestCase.java (added)
+++ jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/CallParamAttributeActionTestCase.java Sat Feb 12 03:13:47 2005
@@ -0,0 +1,144 @@
+/* $Id$
+ *
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.commons.digester2.actions;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import java.io.StringReader;
+
+import org.xml.sax.InputSource;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.digester2.Digester;
+
+/**
+ * Test Cases for the CallParamAttributeAction class.
+ */
+
+public class CallParamAttributeActionTestCase extends TestCase {
+
+ public static class TargetObject {
+ private Object item;
+
+ // allows us to tell the difference between the method not being
+ // called, and being called with a null parameter.
+ private int invocationCount = 0;
+
+ public void addItem(Object item) {
+ this.item = item;
+ ++this.invocationCount;
+ }
+ public Object getItem() { return item; }
+ public int getInvocationCount() { return invocationCount; }
+ }
+
+ // -----------------------------------------------------------
+ // Constructors
+ // -----------------------------------------------------------
+
+ /**
+ * Construct a new instance of this test case.
+ *
+ * @param name Name of the test case
+ */
+ public CallParamAttributeActionTestCase(String name) {
+ super(name);
+ }
+
+ // --------------------------------------------------
+ // Overall Test Methods
+ // --------------------------------------------------
+
+ /**
+ * Set up instance variables required by this test case.
+ */
+ public void setUp() {
+ }
+
+ /**
+ * Return the tests included in this test suite.
+ */
+ public static Test suite() {
+ return (new TestSuite(CallParamAttributeActionTestCase.class));
+ }
+
+ /**
+ * Tear down instance variables required by this test case.
+ */
+ public void tearDown() {
+ }
+
+ // ------------------------------------------------
+ // Individual Test Methods
+ // ------------------------------------------------
+
+ /**
+ * Test basic operations.
+ */
+ public void testBasicOperations() throws Exception {
+ String inputText =
+ "<root>" +
+ " <item value='attr'/>" +
+ "</root>";
+
+ InputSource source = new InputSource(new StringReader(inputText));
+
+ Digester d = new Digester();
+ d.addRule("/root/item", new CallMethodAction("addItem", 1));
+ d.addRule("/root/item", new CallParamAttributeAction(0, "value"));
+
+ TargetObject targetObject = new TargetObject();
+ d.setInitialObject(targetObject);
+ d.parse(source);
+
+ // string was passed ok
+ Object item = targetObject.getItem();
+ assertNotNull("Item set", item);
+ assertSame("Object is a string", String.class, item.getClass());
+ assertEquals("Literal value correct", "attr", item);
+ }
+
+ /**
+ * Test attr not found.
+ */
+ public void testAttrNotFound() throws Exception {
+ String inputText =
+ "<root>" +
+ " <item/>" +
+ "</root>";
+
+ InputSource source = new InputSource(new StringReader(inputText));
+
+ Object literalObj = new Object();
+
+ Digester d = new Digester();
+ d.addRule("/root/item", new CallMethodAction("addItem", 1));
+ d.addRule("/root/item", new CallParamAttributeAction(0, "value"));
+
+ TargetObject targetObject = new TargetObject();
+ d.setInitialObject(targetObject);
+ d.parse(source);
+
+ Object item = targetObject.getItem();
+ assertNull("Item set to null", item);
+ assertEquals("Method invoked", 1, targetObject.getInvocationCount());
+ }
+}
Propchange: jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/CallParamAttributeActionTestCase.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/CallParamBodyActionTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/CallParamBodyActionTestCase.java?view=auto&rev=153496
==============================================================================
--- jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/CallParamBodyActionTestCase.java (added)
+++ jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/CallParamBodyActionTestCase.java Sat Feb 12 03:13:47 2005
@@ -0,0 +1,146 @@
+/* $Id$
+ *
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.commons.digester2.actions;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import java.io.StringReader;
+
+import org.xml.sax.InputSource;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.digester2.Digester;
+
+/**
+ * Test Cases for the CallParamBodyAction class.
+ */
+
+public class CallParamBodyActionTestCase extends TestCase {
+
+ public static class TargetObject {
+ private Object item;
+
+ // allows us to tell the difference between the method not being
+ // called, and being called with a null parameter.
+ private int invocationCount = 0;
+
+ public void addItem(Object item) {
+ this.item = item;
+ ++this.invocationCount;
+ }
+ public Object getItem() { return item; }
+ public int getInvocationCount() { return invocationCount; }
+ }
+
+ // -----------------------------------------------------------
+ // Constructors
+ // -----------------------------------------------------------
+
+ /**
+ * Construct a new instance of this test case.
+ *
+ * @param name Name of the test case
+ */
+ public CallParamBodyActionTestCase(String name) {
+ super(name);
+ }
+
+ // --------------------------------------------------
+ // Overall Test Methods
+ // --------------------------------------------------
+
+ /**
+ * Set up instance variables required by this test case.
+ */
+ public void setUp() {
+ }
+
+ /**
+ * Return the tests included in this test suite.
+ */
+ public static Test suite() {
+ return (new TestSuite(CallParamBodyActionTestCase.class));
+ }
+
+ /**
+ * Tear down instance variables required by this test case.
+ */
+ public void tearDown() {
+ }
+
+ // ------------------------------------------------
+ // Individual Test Methods
+ // ------------------------------------------------
+
+ /**
+ * Test basic operations.
+ */
+ public void testBasicOperations() throws Exception {
+ String inputText =
+ "<root>" +
+ " <item>bodytext</item>" +
+ "</root>";
+
+ InputSource source = new InputSource(new StringReader(inputText));
+
+ Digester d = new Digester();
+ d.addRule("/root/item", new CallMethodAction("addItem", 1));
+ d.addRule("/root/item", new CallParamBodyAction(0));
+
+ TargetObject targetObject = new TargetObject();
+ d.setInitialObject(targetObject);
+ d.parse(source);
+
+ // string was passed ok
+ Object item = targetObject.getItem();
+ assertNotNull("Item set", item);
+ assertSame("Object is a string", String.class, item.getClass());
+ assertEquals("Literal value correct", "bodytext", item);
+ }
+
+ /**
+ * Test element with no body
+ */
+ public void testNoBody() throws Exception {
+ String inputText =
+ "<root>" +
+ " <item/>" +
+ "</root>";
+
+ InputSource source = new InputSource(new StringReader(inputText));
+
+ Object literalObj = new Object();
+
+ Digester d = new Digester();
+ d.addRule("/root/item", new CallMethodAction("addItem", 1));
+ d.addRule("/root/item", new CallParamBodyAction(0));
+
+ TargetObject targetObject = new TargetObject();
+ d.setInitialObject(targetObject);
+ d.parse(source);
+
+ Object item = targetObject.getItem();
+ assertNotNull("Item set", item);
+ assertSame("Object is a string", String.class, item.getClass());
+ assertEquals("String is empty", "", item);
+ assertEquals("Method invoked", 1, targetObject.getInvocationCount());
+ }
+}
Propchange: jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/CallParamBodyActionTestCase.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/CallParamFromStackActionTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/CallParamFromStackActionTestCase.java?view=auto&rev=153496
==============================================================================
--- jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/CallParamFromStackActionTestCase.java (added)
+++ jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/CallParamFromStackActionTestCase.java Sat Feb 12 03:13:47 2005
@@ -0,0 +1,118 @@
+/* $Id$
+ *
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.commons.digester2.actions;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import java.io.StringReader;
+
+import org.xml.sax.InputSource;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.digester2.Digester;
+
+/**
+ * Test Cases for the CallParamFromStackAction class.
+ */
+
+public class CallParamFromStackActionTestCase extends TestCase {
+
+ public static class TargetObject {
+ private Object item;
+
+ // allows us to tell the difference between the method not being
+ // called, and being called with a null parameter.
+ private int invocationCount = 0;
+
+ public void addItem(Object item) {
+ this.item = item;
+ ++this.invocationCount;
+ }
+ public Object getItem() { return item; }
+ public int getInvocationCount() { return invocationCount; }
+ }
+
+ // -----------------------------------------------------------
+ // Constructors
+ // -----------------------------------------------------------
+
+ /**
+ * Construct a new instance of this test case.
+ *
+ * @param name Name of the test case
+ */
+ public CallParamFromStackActionTestCase(String name) {
+ super(name);
+ }
+
+ // --------------------------------------------------
+ // Overall Test Methods
+ // --------------------------------------------------
+
+ /**
+ * Set up instance variables required by this test case.
+ */
+ public void setUp() {
+ }
+
+ /**
+ * Return the tests included in this test suite.
+ */
+ public static Test suite() {
+ return (new TestSuite(CallParamFromStackActionTestCase.class));
+ }
+
+ /**
+ * Tear down instance variables required by this test case.
+ */
+ public void tearDown() {
+ }
+
+ // ------------------------------------------------
+ // Individual Test Methods
+ // ------------------------------------------------
+
+ /**
+ * Test basic operations.
+ */
+ public void testBasicOperations() throws Exception {
+ String inputText =
+ "<root>" +
+ " <item value='attr'/>" +
+ "</root>";
+
+ InputSource source = new InputSource(new StringReader(inputText));
+
+ Digester d = new Digester();
+ d.addRule("/root/item", new CallMethodAction("addItem", 1));
+ d.addRule("/root/item", new CreateObjectAction(StringBuffer.class));
+ d.addRule("/root/item", new CallParamFromStackAction(0));
+
+ TargetObject targetObject = new TargetObject();
+ d.setInitialObject(targetObject);
+ d.parse(source);
+
+ // created object was passed ok
+ Object item = targetObject.getItem();
+ assertNotNull("Item set", item);
+ assertSame("Object is a stringbuffer", StringBuffer.class, item.getClass());
+ }
+}
Propchange: jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/CallParamFromStackActionTestCase.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/CallParamLiteralActionTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/CallParamLiteralActionTestCase.java?view=diff&r1=153495&r2=153496
==============================================================================
--- jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/CallParamLiteralActionTestCase.java (original)
+++ jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/CallParamLiteralActionTestCase.java Sat Feb 12 03:13:47 2005
@@ -30,16 +30,24 @@
import org.apache.commons.digester2.Digester;
/**
- * <p>Test Cases for the CallParamLiteralAction class.</p>
+ * Test Cases for the CallParamLiteralAction class.
*/
public class CallParamLiteralActionTestCase extends TestCase {
public static class TargetObject {
private Object item;
+
+ // allows us to tell the difference between the method not being
+ // called, and being called with a null parameter.
+ private int invocationCount = 0;
- public void addItem(Object item) { this.item = item; }
+ public void addItem(Object item) {
+ this.item = item;
+ ++this.invocationCount;
+ }
public Object getItem() { return item; }
+ public int getInvocationCount() { return invocationCount; }
}
// -----------------------------------------------------------
@@ -132,5 +140,31 @@
Object item = targetObject.getItem();
assertNotNull("Item set", item);
assertSame("Object is same", literalObj, item);
+ }
+
+ /**
+ * Test passing a null reference as a parameter.
+ */
+ public void testNullLiteral() throws Exception {
+ String inputText =
+ "<root>" +
+ " <item/>" +
+ "</root>";
+
+ InputSource source = new InputSource(new StringReader(inputText));
+
+ Object literalObj = new Object();
+
+ Digester d = new Digester();
+ d.addRule("/root/item", new CallMethodAction("addItem", 1));
+ d.addRule("/root/item", new CallParamLiteralAction(0, null));
+
+ TargetObject targetObject = new TargetObject();
+ d.setInitialObject(targetObject);
+ d.parse(source);
+
+ Object item = targetObject.getItem();
+ assertNull("Item set", item);
+ assertEquals("Method invoked", 1, targetObject.getInvocationCount());
}
}
Added: jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/CallParamPathActionTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/CallParamPathActionTestCase.java?view=auto&rev=153496
==============================================================================
--- jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/CallParamPathActionTestCase.java (added)
+++ jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/CallParamPathActionTestCase.java Sat Feb 12 03:13:47 2005
@@ -0,0 +1,118 @@
+/* $Id$
+ *
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.commons.digester2.actions;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import java.io.StringReader;
+
+import org.xml.sax.InputSource;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.digester2.Digester;
+
+/**
+ * Test Cases for the CallParamPathAction class.
+ */
+
+public class CallParamPathActionTestCase extends TestCase {
+
+ public static class TargetObject {
+ private Object item;
+
+ // allows us to tell the difference between the method not being
+ // called, and being called with a null parameter.
+ private int invocationCount = 0;
+
+ public void addItem(Object item) {
+ this.item = item;
+ ++this.invocationCount;
+ }
+ public Object getItem() { return item; }
+ public int getInvocationCount() { return invocationCount; }
+ }
+
+ // -----------------------------------------------------------
+ // Constructors
+ // -----------------------------------------------------------
+
+ /**
+ * Construct a new instance of this test case.
+ *
+ * @param name Name of the test case
+ */
+ public CallParamPathActionTestCase(String name) {
+ super(name);
+ }
+
+ // --------------------------------------------------
+ // Overall Test Methods
+ // --------------------------------------------------
+
+ /**
+ * Set up instance variables required by this test case.
+ */
+ public void setUp() {
+ }
+
+ /**
+ * Return the tests included in this test suite.
+ */
+ public static Test suite() {
+ return (new TestSuite(CallParamPathActionTestCase.class));
+ }
+
+ /**
+ * Tear down instance variables required by this test case.
+ */
+ public void tearDown() {
+ }
+
+ // ------------------------------------------------
+ // Individual Test Methods
+ // ------------------------------------------------
+
+ /**
+ * Test basic operations.
+ */
+ public void testBasicOperations() throws Exception {
+ String inputText =
+ "<root>" +
+ " <item/>" +
+ "</root>";
+
+ InputSource source = new InputSource(new StringReader(inputText));
+
+ Digester d = new Digester();
+ d.addRule("/root/item", new CallMethodAction("addItem", 1));
+ d.addRule("/root/item", new CallParamPathAction(0));
+
+ TargetObject targetObject = new TargetObject();
+ d.setInitialObject(targetObject);
+ d.parse(source);
+
+ // created object was passed ok
+ Object item = targetObject.getItem();
+ assertNotNull("Item set", item);
+ assertSame("Object is a string", String.class, item.getClass());
+ assertEquals("Path is correct", "/root/item", item);
+ }
+}
Propchange: jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/actions/CallParamPathActionTestCase.java
------------------------------------------------------------------------------
svn:keywords = Id
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org