KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

20 public class XmlHandlerTest extends TestCase {
21
22     public void testOuput() {
23         String JavaDoc input = "<person>\n" +
24                 " <name firstname='John' surname='Smith'/>" +
25                 "<email address='john@somwhere.com'/>" +
26                 " <comment>\n" +
27                 " Possible sales contact.\n" +
28                 " Met at convention.\n" +
29                 " </comment>" +
30                 "</person>";
31         
32         ByteArrayOutputStream JavaDoc out = new ByteArrayOutputStream JavaDoc();
33         XmlHandler handler = new XmlHandler(out);
34         
35         InputSource JavaDoc in = new InputSource JavaDoc(new ByteArrayInputStream JavaDoc(input.getBytes()));
36         XMLDefinitionHelper xDef = new XMLDefinitionHelper(new ArooaContext());
37         xDef.parse(in, new MainHandler("person", handler));
38     
39         String JavaDoc s = new String JavaDoc(out.toByteArray());
40         System.out.println(s);
41         
42         ByteArrayOutputStream JavaDoc out2 = new ByteArrayOutputStream JavaDoc();
43         XmlHandler handler2 = new XmlHandler(out2);
44         InputSource JavaDoc in2 = new InputSource JavaDoc(new ByteArrayInputStream JavaDoc(out.toByteArray()));
45         xDef.parse(in2, new MainHandler("person", handler2));
46         
47         String JavaDoc s2 = new String JavaDoc(out2.toByteArray());
48         System.out.println(s2);
49         
50         assertEquals("should be the same", s, s2);
51     }
52 }
53
Popular Tags