KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > designer > arooa > DesignElementHandlerTest


1 /*
2  * (c) Rob Gordon 2005.
3  */

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 JavaDoc;
14 import org.xml.sax.helpers.AttributesImpl JavaDoc;
15
16 /**
17  *
18  */

19 public class DesignElementHandlerTest extends TestCase {
20
21     
22     public static class Test1 extends DesignAdult {
23         public String JavaDoc[] supportedTypes() {
24             return new String JavaDoc[] { "test", "test2" };
25         }
26         
27         public DesignElementType createType(String JavaDoc type) {
28             return new Test2();
29         }
30     }
31     
32     public static class Test2 extends DesignElementType {
33         String JavaDoc what;
34         public void setWhat(String JavaDoc what) {
35             this.what = what;
36         }
37     }
38     
39     public void testStartElement() throws SAXParseException JavaDoc {
40         DesignElementHandler h = new DesignElementHandler();
41         AttributesImpl JavaDoc attrs = new AttributesImpl JavaDoc();
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 JavaDoc {
55         DesignElementHandler h = new DesignElementHandler();
56         AttributesImpl JavaDoc attrs = new AttributesImpl JavaDoc();
57         ArooaContext context = new ArooaContext();
58         context.set(ArooaConstants.ELEMENT_HANDLER, h);
59         context.set(ArooaConstants.CURRENTLY_CONFIGURING, new Object JavaDoc());
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 JavaDoc {
68         DesignElementHandler h = new DesignElementHandler();
69         AttributesImpl JavaDoc attrs = new AttributesImpl JavaDoc();
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