KickJava   Java API By Example, From Geeks To Geeks.

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


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

4 package org.oddjob.designer.arooa;
5
6 import java.io.ByteArrayOutputStream JavaDoc;
7
8 import junit.framework.TestCase;
9
10 import org.oddjob.arooa.ArooaContext;
11 import org.oddjob.arooa.handlers.MainHandler;
12 import org.oddjob.arooa.handlers.XmlHandler;
13 import org.xml.sax.SAXParseException JavaDoc;
14
15 /**
16  *
17  */

18 public class DesignParserTest extends TestCase {
19
20     public void testParse() throws SAXParseException JavaDoc {
21         class Test {
22             public String JavaDoc getTest() {
23                 return "test";
24             }
25             
26             public ElementWrapper[] elements() {
27                 return new ElementWrapper[] {
28                     new ElementWrapper("test",
29                         new Object JavaDoc() {
30                             public String JavaDoc getTest2() {
31                                 return "test2";
32                             }
33                         }
34                     ) };
35             }
36         }
37         Test test = new Test();
38         
39         ByteArrayOutputStream JavaDoc out = new ByteArrayOutputStream JavaDoc();
40         XmlHandler handler = new XmlHandler(out);
41         
42         DesignParser dp = new DesignParser(new ArooaContext());
43         dp.parse("mytest", test, new MainHandler(handler));
44
45         String JavaDoc eol = System.getProperty("line.separator");
46         String JavaDoc expected = "<mytest test=\"test\">" + eol +
47                 " <test test2=\"test2\"/>" + eol +
48                 "</mytest>" + eol;
49         
50         assertEquals("xml", expected, out.toString());
51     }
52 }
53
Popular Tags