craigmcc 01/08/07 20:21:17
Modified: digester/src/test/org/apache/commons/digester
DigesterTestCase.java
Added: digester/src/test/org/apache/commons/digester TestRule.java
Log:
Add tests for rule matching, and remove deprecated method calls in the old
test case.
Submitted by: Robert Burrell Donkin <[EMAIL PROTECTED]>
Revision Changes Path
1.3 +55 -11
jakarta-commons/digester/src/test/org/apache/commons/digester/DigesterTestCase.java
Index: DigesterTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/DigesterTestCase.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DigesterTestCase.java 2001/05/22 04:57:02 1.2
+++ DigesterTestCase.java 2001/08/08 03:21:17 1.3
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/DigesterTestCase.java,v
1.2 2001/05/22 04:57:02 craigmcc Exp $
- * $Revision: 1.2 $
- * $Date: 2001/05/22 04:57:02 $
+ * $Header:
/home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/DigesterTestCase.java,v
1.3 2001/08/08 03:21:17 craigmcc Exp $
+ * $Revision: 1.3 $
+ * $Date: 2001/08/08 03:21:17 $
*
* ====================================================================
*
@@ -83,7 +83,7 @@
* </p>
*
* @author Craig R. McClanahan
- * @version $Revision: 1.2 $ $Date: 2001/05/22 04:57:02 $
+ * @version $Revision: 1.3 $ $Date: 2001/08/08 03:21:17 $
*/
public class DigesterTestCase extends TestCase {
@@ -135,6 +135,7 @@
public void setUp() {
digester = new Digester();
+ digester.setRules(new RulesBase());
}
@@ -269,31 +270,75 @@
/**
- * Test rule creation and matching.
+ * Basic test for rule creation and matching.
*/
public void testRules() {
List list = null;
assertNull("Initial rules list is empty",
- digester.getRules("a"));
+ digester.getRules().match("a"));
digester.addSetProperties("a");
assertEquals("Add a matching rule",
- 1, digester.getRules("a").size());
+ 1, digester.getRules().match("a").size());
digester.addSetProperties("b");
assertEquals("Add a non-matching rule",
- 1, digester.getRules("a").size());
+ 1, digester.getRules().match("a").size());
digester.addSetProperties("a/b");
assertEquals("Add a non-matching nested rule",
- 1, digester.getRules("a").size());
+ 1, digester.getRules().match("a").size());
digester.addSetProperties("a/b");
assertEquals("Add a second matching rule",
- 2, digester.getRules("a/b").size());
+ 2, digester.getRules().match("a/b").size());
}
/**
+ * <p>Test matching rules in {@link RulesBase}.</p>
+ *
+ * <p>Tests:</p>
+ * <ul>
+ * <li>exact match</li>
+ * <li>tail match</li>
+ * <li>longest pattern rule</li>
+ * </ul>
+ */
+ public void testRulesBase() {
+
+ assertEquals("Initial rules list is empty",
+ 0, digester.getRules().rules().size());
+
+ // We're going to set up
+ digester.addRule("a/b/c/d", new TestRule(digester, "a/b/c/d"));
+ digester.addRule("*/d", new TestRule(digester, "*/d"));
+ digester.addRule("*/c/d", new TestRule(digester, "*/c/d"));
+
+ // Test exact match
+ assertEquals("Exact match takes precedence 1",
+ 1, digester.getRules().match("a/b/c/d").size());
+ assertEquals("Exact match takes precedence 2",
+ "a/b/c/d",
+ ((TestRule)
digester.getRules().match("a/b/c/d").iterator().next()).getIdentifier());
+
+ // Test wildcard tail matching
+ assertEquals("Wildcard tail matching rule 1",
+ 1, digester.getRules().match("a/b/d").size());
+ assertEquals("Wildcard tail matching rule 2",
+ "*/d",
+ ((TestRule)
digester.getRules().match("a/b/d").iterator().next()).getIdentifier());
+
+ // Test the longest matching pattern rule
+ assertEquals("Longest tail rule 1",
+ 1, digester.getRules().match("x/c/d").size());
+ assertEquals("Longest tail rule 2",
+ "*/c/d",
+ ((TestRule)
digester.getRules().match("x/c/d").iterator().next()).getIdentifier());
+
+ }
+
+
+ /**
* Test the basic stack mechanisms.
*/
public void testStackMethods() {
@@ -339,7 +384,6 @@
assertNull("Cleared stack pop() returns null", value);
}
-
}
1.1
jakarta-commons/digester/src/test/org/apache/commons/digester/TestRule.java
Index: TestRule.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.digester;
/**
* <p>This rule implementation is intended to help test digester.
* The idea is that you can test which rule matches by looking
* at the identifier.</p>
*
* @author Robert Burrell Donkin
* @revision $Revision: 1.1 $ $Date: 2001/08/08 03:21:17 $
*/
public class TestRule extends Rule {
// ----------------------------------------------------- Instance Variables
/** String identifing this particular <code>TestRule</code> */
private String identifier;
// ----------------------------------------------------------- Constructors
/**
* Base constructor.
*
* @param digester The digester with which this rule is associated
* @param identifier Used to tell which TestRule is which.
*/
public TestRule(Digester digester, String identifier) {
super(digester);
this.identifier=identifier;
}
// ------------------------------------------------ Methods
/**
* Get the identifier associated with this test.
*/
public String getIdentifier()
{
return identifier;
}
/**
* Return the identifier.
*/
public String toString()
{
return identifier;
}
}