1 4 package org.oddjob.designer.arooa; 5 6 import java.io.ByteArrayInputStream ; 7 import java.io.ByteArrayOutputStream ; 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 ; 14 15 import junit.framework.TestCase; 16 17 20 public class XmlHandlerTest extends TestCase { 21 22 public void testOuput() { 23 String 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 out = new ByteArrayOutputStream (); 33 XmlHandler handler = new XmlHandler(out); 34 35 InputSource in = new InputSource (new ByteArrayInputStream (input.getBytes())); 36 XMLDefinitionHelper xDef = new XMLDefinitionHelper(new ArooaContext()); 37 xDef.parse(in, new MainHandler("person", handler)); 38 39 String s = new String (out.toByteArray()); 40 System.out.println(s); 41 42 ByteArrayOutputStream out2 = new ByteArrayOutputStream (); 43 XmlHandler handler2 = new XmlHandler(out2); 44 InputSource in2 = new InputSource (new ByteArrayInputStream (out.toByteArray())); 45 xDef.parse(in2, new MainHandler("person", handler2)); 46 47 String s2 = new String (out2.toByteArray()); 48 System.out.println(s2); 49 50 assertEquals("should be the same", s, s2); 51 } 52 } 53 | Popular Tags |