1 17 18 19 package org.apache.commons.digester.plugins; 20 21 import java.util.List ; 22 23 import junit.framework.Test; 24 import junit.framework.TestCase; 25 import junit.framework.TestSuite; 26 27 import org.apache.commons.digester.Digester; 28 29 32 33 public class TestDeclaration extends TestCase { 34 35 public TestDeclaration(String name) { 36 super(name); 37 } 38 39 40 public void setUp() {} 41 42 43 public static Test suite() { 44 45 return (new TestSuite(TestDeclaration.class)); 46 47 } 48 49 50 public void tearDown() {} 51 52 54 public void testPredeclaration() throws Exception { 55 57 Digester digester = new Digester(); 58 PluginRules rc = new PluginRules(); 59 digester.setRules(rc); 60 61 PluginDeclarationRule pdr = new PluginDeclarationRule(); 62 digester.addRule("root/plugin", pdr); 63 64 PluginCreateRule pcr = new PluginCreateRule(Widget.class); 65 digester.addRule("root/widget", pcr); 66 digester.addSetNext("root/widget", "addChild"); 67 68 Container root = new Container(); 69 digester.push(root); 70 71 try { 72 digester.parse( 73 TestAll.getInputStream(this, "test3.xml")); 74 } 75 catch(Exception e) { 76 throw e; 77 } 78 79 Object child; 80 List children = root.getChildren(); 81 assertTrue(children != null); 82 assertEquals(2, children.size()); 83 84 child = children.get(0); 85 assertTrue(child != null); 86 assertEquals(TextLabel.class, child.getClass()); 87 assertEquals("label1", ((TextLabel)child).getLabel()); 88 89 child = children.get(1); 90 assertTrue(child != null); 91 assertEquals(TextLabel.class, child.getClass()); 92 assertEquals("label2", ((TextLabel)child).getLabel()); 93 } 94 } 95 | Popular Tags |