commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From skitch...@apache.org
Subject svn commit: r151644 - in jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2: AbstractRuleManagerTestCase.java DefaultRuleManagerTestCase.java
Date Mon, 07 Feb 2005 00:09:00 GMT
Author: skitching
Date: Sun Feb  6 16:08:59 2005
New Revision: 151644

URL: http://svn.apache.org/viewcvs?view=rev&rev=151644
Log:
Added new test suites

Added:
    jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/AbstractRuleManagerTestCase.java
  (with props)
    jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/DefaultRuleManagerTestCase.java
  (with props)

Added: jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/AbstractRuleManagerTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/AbstractRuleManagerTestCase.java?view=auto&rev=151644
==============================================================================
--- jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/AbstractRuleManagerTestCase.java
(added)
+++ jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/AbstractRuleManagerTestCase.java
Sun Feb  6 16:08:59 2005
@@ -0,0 +1,150 @@
+/* $Id$
+ *
+ * Copyright 2001-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;
+
+import java.math.BigDecimal;
+import java.net.URL;
+import java.io.StringReader;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.ArrayList;
+import java.util.EmptyStackException;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.Attributes;
+import org.xml.sax.helpers.AttributesImpl;
+import org.xml.sax.InputSource;
+
+import org.apache.commons.logging.Log;
+
+/**
+ * Test Case for the AbstractRuleManager class.
+ * <p>
+ * Mostly, this involves checking that the methods are invoked at
+ * the times that they are expected to be invoked.
+ */
+
+public class AbstractRuleManagerTestCase extends TestCase {
+
+    private static class MyRuleManager extends AbstractRuleManager {
+        private List operations;
+        
+        public MyRuleManager(List operations) {
+            this.operations = operations;
+        }
+        
+        public RuleManager copy() {
+            operations.add("copy");
+            return null; // there's no point testing abstract copy!
+        }
+        
+        public void startParse(Context context) throws DigestionException {
+            operations.add("startParse");
+        }
+        
+        public void finishParse(Context context) throws DigestionException {
+            operations.add("finishParse");
+        }
+        
+        public void addNamespace(String prefix, String uri) {
+            operations.add("addNamespace");
+        }
+        
+        public void addRule(String pattern, Action action) {
+            operations.add("addRule");
+        }
+
+        public List getMatchingActions(String path) {
+            operations.add("getMatchingActions");
+            return java.util.Collections.EMPTY_LIST;
+        }
+    }
+    
+    // -----------------------------------------------------------
+    // Constructors
+    // -----------------------------------------------------------
+
+    /**
+     * Construct a new instance of this test case.
+     *
+     * @param name Name of the test case
+     */
+    public AbstractRuleManagerTestCase(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(AbstractRuleManagerTestCase.class));
+    }
+
+    /**
+     * Tear down instance variables required by this test case.
+     */
+    public void tearDown() {
+    }
+
+    // ------------------------------------------------
+    // Individual Test Methods
+    // ------------------------------------------------
+
+    /**
+     * Test everything.
+     */
+    public void testEverything() throws Exception {
+        String inputText = "<root/>";
+
+        ArrayList opsList = new ArrayList(10);
+        MyRuleManager rm = new MyRuleManager(opsList);
+
+        rm.addRule(
+            "/root", 
+            new org.apache.commons.digester2.actions.SetPropertiesAction());
+
+        Digester d = new Digester();
+        d.setRuleManager(rm);
+        InputSource source = new InputSource(new StringReader(inputText));
+        d.parse(source);
+
+        assertEquals("Expected number of operations", 4, opsList.size());
+        assertEquals("First op: addRule", "addRule", opsList.get(0)); 
+        assertEquals("Second op: startParse", "startParse", opsList.get(1));
+        assertEquals("Third op: getMatchingActions", 
+            "getMatchingActions", opsList.get(2));
+        assertEquals("Fourth op: finishParse", 
+            "finishParse", opsList.get(3));
+    }
+}

Propchange: jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/AbstractRuleManagerTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/DefaultRuleManagerTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/DefaultRuleManagerTestCase.java?view=auto&rev=151644
==============================================================================
--- jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/DefaultRuleManagerTestCase.java
(added)
+++ jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/DefaultRuleManagerTestCase.java
Sun Feb  6 16:08:59 2005
@@ -0,0 +1,175 @@
+/* $Id$
+ *
+ * Copyright 2001-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;
+
+import java.math.BigDecimal;
+import java.net.URL;
+import java.io.StringReader;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.ArrayList;
+import java.util.EmptyStackException;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.Attributes;
+import org.xml.sax.helpers.AttributesImpl;
+import org.xml.sax.InputSource;
+
+import org.apache.commons.logging.Log;
+
+/**
+ * <p>Test Case for the DefaultRuleManager class.</p>
+ */
+
+public class DefaultRuleManagerTestCase extends TestCase {
+
+    private static class DummyAction extends AbstractAction {
+        private String name;
+
+        public DummyAction(String name) {
+            this.name = name;
+        }
+
+        public String getName() {
+            return name;
+        }
+        
+        public String toString() {
+            return name;
+        }
+    }
+
+    // -----------------------------------------------------------
+    // Constructors
+    // -----------------------------------------------------------
+
+    /**
+     * Construct a new instance of this test case.
+     *
+     * @param name Name of the test case
+     */
+    public DefaultRuleManagerTestCase(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(DefaultRuleManagerTestCase.class));
+    }
+
+    /**
+     * Tear down instance variables required by this test case.
+     */
+    public void tearDown() {
+    }
+
+    // ------------------------------------------------
+    // Individual Test Methods
+    // ------------------------------------------------
+
+    /**
+     * Test the Constructor, plus the getters that access constructor params.
+     */
+    public void testConstructor() {
+        DefaultRuleManager rm = new DefaultRuleManager();
+
+        List actions = rm.getActions();
+        assertTrue("Initial action list is empty", actions.isEmpty());
+    }
+
+    /**
+     * Test the copy method.
+     */
+    public void testCopy() throws Exception {
+        DefaultRuleManager drm1 = new DefaultRuleManager();
+
+        drm1.addRule("/root", new DummyAction("one"));
+        drm1.addRule("/root", new DummyAction("two"));
+
+        RuleManager rmCopy = drm1.copy();
+        List actions;
+
+        assertNotNull("Copy works", rmCopy);
+        assertEquals("Copy returns same class",
+            DefaultRuleManager.class, rmCopy.getClass());
+
+        DefaultRuleManager drm2 = (DefaultRuleManager) rmCopy;
+        
+        assertNotSame("Actions list is copied",
+            drm1.getActions(), drm2.getActions());
+
+        assertEquals("Actions lists are same size",
+            drm1.getActions().size(), drm2.getActions().size());
+
+        assertSame("Actions are not copied",
+            drm1.getActions().get(0), drm2.getActions().get(0));
+
+        assertSame("Actions are not copied",
+            drm1.getActions().get(1), drm2.getActions().get(1));
+    }
+
+    /**
+     * Test basic matching of paths to rules.
+     */
+    public void testBasicMatching() throws Exception {
+        DefaultRuleManager rm = new DefaultRuleManager();
+        
+        Action actionA = new DummyAction("a");
+        Action actionB1 = new DummyAction("b1");
+        Action actionB2 = new DummyAction("b2");
+        
+        List list = null;
+
+        rm.addRule("/a", actionA);
+        rm.addRule("/a/b", actionB1);
+        rm.addRule("/a/b", actionB2);
+
+        // match nothing
+        list = rm.getMatchingActions("/c");
+        assertEquals("Action list is empty for no match", 0, list.size());
+        
+        // match one action
+        list = rm.getMatchingActions("/a");
+        assertEquals("One rule matched", 1, list.size());
+        assertEquals("A rule matched", "a", list.get(0).toString());
+
+        // match multiple actions
+        list = rm.getMatchingActions("/a/b");
+        assertEquals("Multiple rules matched", 2, list.size());
+        assertEquals("B1 rule matched", "b1", list.get(0).toString());
+        assertEquals("B2 rule matched", "b2", list.get(1).toString());
+    }
+}

Propchange: jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/DefaultRuleManagerTestCase.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


Mime
View raw message