1 16 17 18 package org.apache.commons.digester.xmlrules; 19 20 21 import java.io.StringReader ; 22 23 import junit.framework.TestCase; 24 import junit.framework.TestSuite; 25 26 import org.apache.commons.digester.Digester; 27 28 import org.xml.sax.InputSource ; 29 30 33 34 public class FromXmlRuleSetTest extends TestCase { 35 36 public FromXmlRuleSetTest(java.lang.String testName) { 37 super(testName); 38 } 39 40 public static void main(java.lang.String [] args) { 41 junit.textui.TestRunner.run(suite()); 42 } 43 44 public static junit.framework.Test suite() { 45 TestSuite suite = new TestSuite(FromXmlRuleSetTest.class); 46 47 return suite; 48 } 49 50 54 55 public void testBasePath() throws Exception { 56 String xmlRules = 57 "<?xml version='1.0'?>" + 58 "<digester-rules>" + 59 " <pattern value='foo'>" + 60 " <call-method-rule " + 61 " methodname='setProperty' " + 62 " paramcount='0' />" + 63 " </pattern>" + 64 "</digester-rules>"; 65 66 String xml = 67 "<?xml version='1.0'?>" + 68 "<root>" + 69 " <foo>success</foo>" + 70 "</root>"; 71 72 { 75 TestObject testObject = new TestObject(); 76 FromXmlRuleSet ruleset = 77 new FromXmlRuleSet( 78 new InputSource (new StringReader (xmlRules))); 79 Digester digester = new Digester(); 80 ruleset.addRuleInstances(digester); 81 82 digester.push(testObject); 83 digester.parse(new InputSource (new StringReader (xml))); 84 85 assertEquals("", testObject.getProperty()); 86 } 87 88 { 90 TestObject testObject = new TestObject(); 91 FromXmlRuleSet ruleset = 92 new FromXmlRuleSet( 93 new InputSource (new StringReader (xmlRules))); 94 Digester digester = new Digester(); 95 ruleset.addRuleInstances(digester, "root"); 96 97 digester.push(testObject); 98 digester.parse(new InputSource (new StringReader (xml))); 99 100 assertEquals("success", testObject.getProperty()); 101 } 102 } 103 } 104 | Popular Tags |