1 17 18 19 package org.apache.commons.digester; 20 21 22 import java.io.IOException ; 23 import java.io.StringReader ; 24 import java.util.ArrayList ; 25 26 import junit.framework.Test; 27 import junit.framework.TestCase; 28 import junit.framework.TestSuite; 29 30 import org.xml.sax.SAXException ; 31 32 33 38 public class ObjectParamRuleTestCase extends TestCase { 39 40 41 43 44 47 protected Digester digester = null; 48 49 50 52 53 58 public ObjectParamRuleTestCase(String name) { 59 60 super(name); 61 62 } 63 64 65 public static void main(String [] args){ 66 67 junit.textui.TestRunner.run(suite()); 69 70 } 71 72 73 75 76 79 public void setUp() { 80 81 digester = new Digester(); 82 83 } 84 85 86 89 public static Test suite() { 90 91 return (new TestSuite(ObjectParamRuleTestCase.class)); 92 93 } 94 95 96 99 public void tearDown() { 100 101 digester = null; 102 103 } 104 105 106 107 109 private StringBuffer sb = new StringBuffer (). 110 append("<arraylist><A/><B/><C/><D desc=\"the fourth\"/><E/></arraylist>"); 111 112 113 118 public void testBasic() throws SAXException , IOException { 119 120 digester.addObjectCreate("arraylist", ArrayList .class); 122 123 digester.addCallMethod("arraylist/A", "add", 1); 125 ObjectParamRule opr = new ObjectParamRule(0, new Integer (-9)); 126 digester.addRule("arraylist/A", opr); 127 digester.addCallMethod("arraylist/B", "add", 1); 128 opr = new ObjectParamRule(0, new Float (3.14159)); 129 digester.addRule("arraylist/B", opr); 130 digester.addCallMethod("arraylist/C", "add", 1); 131 opr = new ObjectParamRule(0, new Long (999999999)); 132 digester.addRule("arraylist/C", opr); 133 digester.addCallMethod("arraylist/D", "add", 1); 134 opr = new ObjectParamRule(0, "desc", new String ("foobarbazbing")); 135 digester.addRule("arraylist/D", opr); 136 digester.addCallMethod("arraylist/E", "add", 1); 139 opr = new ObjectParamRule(0, "nonexistentattribute", new String ("ignore")); 140 digester.addRule("arraylist/E", opr); 141 142 ArrayList al = (ArrayList )digester.parse(new StringReader (sb.toString())); 144 this.assertNotNull(al); 145 this.assertEquals(al.size(), 4); 146 this.assertTrue(al.contains(new Integer (-9))); 147 this.assertTrue(al.contains(new Float (3.14159))); 148 this.assertTrue(al.contains(new Long (999999999))); 149 this.assertTrue(al.contains(new String ("foobarbazbing"))); 150 this.assertTrue(!(al.contains(new String ("ignore")))); 151 } 152 153 } 154 155 | Popular Tags |