1 4 package org.oddjob.designer.arooa; 5 6 import junit.framework.TestCase; 7 8 import org.oddjob.arooa.ArooaHandler; 9 import org.oddjob.arooa.ArooaContext; 10 import org.oddjob.arooa.ArooaConstants; 11 import org.oddjob.designer.model.DesignAdult; 12 import org.oddjob.designer.model.DesignElementType; 13 import org.xml.sax.SAXParseException ; 14 import org.xml.sax.helpers.AttributesImpl ; 15 16 19 public class DesignElementHandlerTest extends TestCase { 20 21 22 public static class Test1 extends DesignAdult { 23 public String [] supportedTypes() { 24 return new String [] { "test", "test2" }; 25 } 26 27 public DesignElementType createType(String type) { 28 return new Test2(); 29 } 30 } 31 32 public static class Test2 extends DesignElementType { 33 String what; 34 public void setWhat(String what) { 35 this.what = what; 36 } 37 } 38 39 public void testStartElement() throws SAXParseException { 40 DesignElementHandler h = new DesignElementHandler(); 41 AttributesImpl attrs = new AttributesImpl (); 42 attrs.addAttribute("", "what", "what", null, "something"); 43 Test1 t1 = new Test1(); 44 ArooaContext context = new ArooaContext(); 45 context.set(ArooaConstants.CURRENTLY_CONFIGURING, t1); 46 context = new ArooaContext(context); 47 48 h.onStartElement("", "test", "test", attrs, context); 49 50 Test2 result = (Test2) context.get(ArooaConstants.CURRENTLY_CONFIGURING); 51 assertEquals("t", "something", result.what); 52 } 53 54 public void testStartChild() throws SAXParseException { 55 DesignElementHandler h = new DesignElementHandler(); 56 AttributesImpl attrs = new AttributesImpl (); 57 ArooaContext context = new ArooaContext(); 58 context.set(ArooaConstants.ELEMENT_HANDLER, h); 59 context.set(ArooaConstants.CURRENTLY_CONFIGURING, new Object ()); 60 61 ArooaHandler ah = h.onStartChild("", "whatever", "whatever", attrs, context); 62 63 assertTrue("Handler", ah == h); 64 } 65 66 67 public void testEndElement() throws SAXParseException { 68 DesignElementHandler h = new DesignElementHandler(); 69 AttributesImpl attrs = new AttributesImpl (); 70 ArooaContext context = new ArooaContext(); 71 Test1 t1 = new Test1(); 72 context.set(ArooaConstants.CURRENTLY_CONFIGURING, t1); 73 context = new ArooaContext(context); 74 context.set(ArooaConstants.CURRENTLY_CONFIGURING, new Test2()); 75 76 h.onEndElement("", "test2", context); 77 78 assertEquals("t2c", 1, t1.children().length); 79 } 80 } 81 | Popular Tags |