Author: ozeigermann Date: Sun Feb 13 23:15:49 2005 New Revision: 153730 URL: http://svn.apache.org/viewcvs?view=rev&rev=153730 Log: Individual basic test cases for fallback and supplementary rule manager
Modified: jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/SupplementaryRuleManagerTestCase.java Modified: jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/SupplementaryRuleManagerTestCase.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/SupplementaryRuleManagerTestCase.java?view=diff&r1=153729&r2=153730 ============================================================================== --- jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/SupplementaryRuleManagerTestCase.java (original) +++ jakarta/commons/proper/digester/branches/digester2/src/test/org/apache/commons/digester2/SupplementaryRuleManagerTestCase.java Sun Feb 13 23:15:49 2005 @@ -25,7 +25,6 @@ import org.xml.sax.Attributes; import org.xml.sax.InputSource; -import org.xml.sax.XMLReader; /** * <p> @@ -35,27 +34,33 @@ public class SupplementaryRuleManagerTestCase extends TestCase { + private static class NullAction extends AbstractAction { + } + private static class XMLLikeAction extends AbstractAction { - + boolean rootFoundAbsolute = false; + boolean rootFoundRelative = false; + boolean wrongRelativeFound = false; + boolean longAbsoluteFound = false; - + public void begin(Context context, String namespace, String name, Attributes attrs) { String path = context.getMatchPath(); if (SupplementaryRuleManager.matches(path, "/root")) { rootFoundAbsolute = true; - } - + } + if (SupplementaryRuleManager.matches(path, "root")) { rootFoundRelative = true; } if (SupplementaryRuleManager.matches(path, "/root/p/em")) { longAbsoluteFound = true; - } + } if (SupplementaryRuleManager.matches(path, "ot/p")) { wrongRelativeFound = true; @@ -106,27 +111,52 @@ // Individual Test Methods // ------------------------------------------------ - public void testGlobalCallBack() throws Exception { + public void testFallback() throws Exception { String inputText = "<root><p>Hi <em>There</em></p></root>"; InputSource source = new InputSource(new StringReader(inputText)); + // xmlio-style digester + XMLLikeAction xmlioLikeAction = new XMLLikeAction(); + + FallbackRuleManager manager = new FallbackRuleManager(); + manager.addFallbackAction(xmlioLikeAction); + manager.addRule("/root/p/em", new NullAction()); + Digester d = new Digester(); + d.setRuleManager(manager); + d.parse(source); - XMLReader reader = d.getXMLReader(); + assertTrue("Root element was found absolute", xmlioLikeAction.rootFoundAbsolute); + assertTrue("Root element was found relative", xmlioLikeAction.rootFoundRelative); + assertFalse("Long absolute path was found by other rule", xmlioLikeAction.longAbsoluteFound); + assertFalse("Incomplete relative was not found", xmlioLikeAction.wrongRelativeFound); + + } + + public void testSupplementary() throws Exception { + String inputText = "<root><p>Hi <em>There</em></p></root>"; // xmlio-style digester - XMLLikeAction xmlioLikeHandler = new XMLLikeAction(); + XMLLikeAction xmlioLikeAction = new XMLLikeAction(); + + SupplementaryRuleManager manager = new SupplementaryRuleManager(); + manager.addSupplementaryAction(xmlioLikeAction); + manager.addRule("root", new NullAction()); - RuleManager manager = new SupplementaryRuleManager(xmlioLikeHandler); + Digester d = new Digester(); d.setRuleManager(manager); - d.parse(source); + // try twice to check caching + for (int i = 0; i < 2; i++) { + InputSource source = new InputSource(new StringReader(inputText)); + d.parse(source); + + assertTrue("Root element was found absolute", xmlioLikeAction.rootFoundAbsolute); + assertTrue("Root element was found relative", xmlioLikeAction.rootFoundRelative); + assertTrue("Long absolute path was found", xmlioLikeAction.longAbsoluteFound); + assertFalse("Incomplete relative was not found", xmlioLikeAction.wrongRelativeFound); + } - assertTrue("Root element was found absolute", xmlioLikeHandler.rootFoundAbsolute); - assertTrue("Root element was found relative", xmlioLikeHandler.rootFoundRelative); - assertTrue("Long absolute path was found", xmlioLikeHandler.longAbsoluteFound); - assertFalse("Incomplete relative was not found", xmlioLikeHandler.wrongRelativeFound); - } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]