1 4 package org.oddjob.designer.arooa; 5 6 import org.oddjob.arooa.ArooaHandler; 7 import org.oddjob.arooa.ArooaContext; 8 import org.xml.sax.Attributes ; 9 import org.xml.sax.SAXParseException ; 10 11 import junit.framework.TestCase; 12 13 16 public class DualHandlerTest extends TestCase { 17 18 class GoodHandler extends ArooaHandler { 19 public void onStartElement(String uri, String tag, String qname, 20 Attributes attrs, ArooaContext context) { 21 } 22 23 public ArooaHandler onStartChild(String uri, String tag, 24 String qname, Attributes attrs, ArooaContext context) { 25 return this; 26 } 27 28 public void onEndChild(String uri, String tag, String qname, 29 ArooaContext context) { 30 } 31 32 public void onEndElement(String uri, String tag, 33 ArooaContext context) { 34 } 35 36 public void characters(char[] buf, int start, int count, 37 ArooaContext context) { 38 } 39 } 40 41 class BadHandler extends ArooaHandler { 42 public void onStartElement(String uri, String tag, String qname, 43 Attributes attrs, ArooaContext context) { 44 throw new NullPointerException ("Ah ha!"); 45 } 46 47 public ArooaHandler onStartChild(String uri, String tag, 48 String qname, Attributes attrs, ArooaContext context) { 49 throw new NullPointerException ("Ah ha!"); 50 } 51 52 public void onEndChild(String uri, String tag, String qname, 53 ArooaContext context) { 54 throw new NullPointerException ("Ah ha!"); 55 } 56 57 public void onEndElement(String uri, String tag, 58 ArooaContext context) { 59 throw new NullPointerException ("Ah ha!"); 60 } 61 62 public void characters(char[] buf, int start, int count, 63 ArooaContext context) { 64 throw new NullPointerException ("Ah ha!"); 65 } 66 } 67 68 public void testGoodStartElement() throws SAXParseException { 69 DualHandler h = new DualHandler(new GoodHandler(), new GoodHandler()); 70 h.onStartElement("", "tag", "tag", null, null); 71 assertTrue("h1OK", h.isHandler1OK()); 72 assertTrue("h2OK", h.isHandler2OK()); 73 } 74 75 public void testBadStartElement() throws SAXParseException { 76 DualHandler h = new DualHandler(new BadHandler(), new BadHandler()); 77 h.onStartElement("", "tag", "tag", null, null); 78 assertFalse("h1OK", h.isHandler1OK()); 79 assertFalse("h2OK", h.isHandler2OK()); 80 } 81 82 public void testGoodStartChild() throws SAXParseException { 83 DualHandler h = new DualHandler(new GoodHandler(), new GoodHandler()); 84 h.onStartChild("", "tag", "tag", null, null); 85 assertTrue("h1OK", h.isHandler1OK()); 86 assertTrue("h2OK", h.isHandler2OK()); 87 } 88 89 public void testBadStartChild() throws SAXParseException { 90 DualHandler h = new DualHandler(new BadHandler(), new BadHandler()); 91 h.onStartElement("", "tag", "tag", null, null); 92 assertFalse("h1OK", h.isHandler1OK()); 93 assertFalse("h2OK", h.isHandler2OK()); 94 } 95 96 public void testGoodEndChild() throws SAXParseException { 97 DualHandler h = new DualHandler(new GoodHandler(), new GoodHandler()); 98 h = (DualHandler)h.onStartChild("", "tag", "tag", null, null); 99 100 h.onEndChild("", "tag", "tag", null); 101 assertTrue("h1OK", h.isHandler1OK()); 102 assertTrue("h2OK", h.isHandler2OK()); 103 } 104 105 public void testBadEndChild() throws SAXParseException { 106 DualHandler h = new DualHandler(new BadHandler(), new BadHandler()); 107 h = (DualHandler)h.onStartChild("", "tag", "tag", null, null); 108 109 h.onEndChild("", "tag", "tag", null); 110 assertFalse("h1OK", h.isHandler1OK()); 111 assertFalse("h2OK", h.isHandler2OK()); 112 } 113 114 public void testGoodEndElement() throws SAXParseException { 115 DualHandler h = new DualHandler(new GoodHandler(), new GoodHandler()); 116 h.onEndElement("", "tag", null); 117 assertTrue("h1OK", h.isHandler1OK()); 118 assertTrue("h2OK", h.isHandler2OK()); 119 } 120 121 public void testBadEndElement() throws SAXParseException { 122 DualHandler h = new DualHandler(new BadHandler(), new BadHandler()); 123 h.onEndElement("", "tag", null); 124 assertFalse("h1OK", h.isHandler1OK()); 125 assertFalse("h2OK", h.isHandler2OK()); 126 } 127 128 public void testGoodChars() throws SAXParseException { 129 DualHandler h = new DualHandler(new GoodHandler(), new GoodHandler()); 130 h.characters(new char[0], 0, 0, null); 131 assertTrue("h1OK", h.isHandler1OK()); 132 assertTrue("h2OK", h.isHandler2OK()); 133 } 134 135 public void testBadChars() throws SAXParseException { 136 DualHandler h = new DualHandler(new BadHandler(), new BadHandler()); 137 h.characters(new char[0], 0, 0, null); 138 assertFalse("h1OK", h.isHandler1OK()); 139 assertFalse("h2OK", h.isHandler2OK()); 140 } 141 } 142 | Popular Tags |