1 16 package org.apache.ws.jaxme.junit; 17 18 import java.io.StringReader ; 19 import java.io.StringWriter ; 20 21 import javax.xml.bind.JAXBContext; 22 import javax.xml.bind.Marshaller; 23 24 import org.apache.ws.jaxme.examples.misc.address.AddressCreator; 25 import org.apache.ws.jaxme.examples.misc.address.AddressPrinter; 26 import org.apache.ws.jaxme.impl.JMMarshallerImpl; 27 import org.apache.ws.jaxme.test.misc.address.Address; 28 import org.xml.sax.InputSource ; 29 30 31 34 public class PrinterCreatorTest extends BaseTestCase { 35 37 public PrinterCreatorTest(String pName) { 38 super(pName); 39 } 40 41 private String getAddress() throws Exception { 42 StringWriter sw = new StringWriter (); 43 AddressCreator.writeAddress(sw); 44 sw.close(); 45 return "<Address xmlns=\"http://ws.apache.org/jaxme/test/misc/address\">\n" + 46 " <Name>\n" + 47 " <First>Jane</First>\n" + 48 " <Last>Doe</Last>\n" + 49 " </Name>\n" + 50 " <Postal>\n" + 51 " <Street>34 Main Street</Street>\n" + 52 " <ZIP>02215</ZIP>\n" + 53 " <City>Boston</City>\n" + 54 " <State>MA</State>\n" + 55 " </Postal>\n" + 56 " <PhoneDetails>\n" + 57 " <Phone type=\"Work\">\n" + 58 " <PhoneNumber>555.6789</PhoneNumber>\n" + 59 " </Phone>\n" + 60 " <Phone type=\"Fax\">\n" + 61 " <PhoneNumber>555.1212</PhoneNumber>\n" + 62 " </Phone>\n" + 63 " </PhoneDetails>\n" + 64 " <EmailDetails>\n" + 65 " <Email type=\"Private\">\n" + 66 " <EmailAddress>jdoe@yourcompany.com</EmailAddress>\n" + 67 " </Email>\n" + 68 " <Email type=\"Office\">\n" + 69 " <EmailAddress>josephdoe@mycompany.com</EmailAddress>\n" + 70 " </Email>\n" + 71 " <Email type=\"Office\">\n" + 72 " <EmailAddress>joseph.doe@mycompany.com</EmailAddress>\n" + 73 " </Email>\n" + 74 " </EmailDetails>\n" + 75 "</Address>"; 76 } 77 78 80 public void testCreate() throws Exception { 81 StringWriter sw = new StringWriter (); 82 AddressCreator.writeAddress(sw); 83 sw.close(); 84 String expect = "<Address xmlns=\"http://ws.apache.org/jaxme/test/misc/address\">\n" + 85 " <Name>\n" + 86 " <First>Jane</First>\n" + 87 " <Last>Doe</Last>\n" + 88 " </Name>\n" + 89 " <Postal>\n" + 90 " <Street>34 Main Street</Street>\n" + 91 " <ZIP>02215</ZIP>\n" + 92 " <City>Boston</City>\n" + 93 " <State>MA</State>\n" + 94 " </Postal>\n" + 95 " <PhoneDetails>\n" + 96 " <Phone type=\"Work\">\n" + 97 " <PhoneNumber>555.6789</PhoneNumber>\n" + 98 " </Phone>\n" + 99 " <Phone type=\"Fax\">\n" + 100 " <PhoneNumber>555.1212</PhoneNumber>\n" + 101 " </Phone>\n" + 102 " </PhoneDetails>\n" + 103 " <EmailDetails>\n" + 104 " <Email type=\"Private\">\n" + 105 " <EmailAddress>jdoe@yourcompany.com</EmailAddress>\n" + 106 " </Email>\n" + 107 " <Email type=\"Office\">\n" + 108 " <EmailAddress>josephdoe@mycompany.com</EmailAddress>\n" + 109 " </Email>\n" + 110 " <Email type=\"Office\">\n" + 111 " <EmailAddress>joseph.doe@mycompany.com</EmailAddress>\n" + 112 " </Email>\n" + 113 " </EmailDetails>\n" + 114 "</Address>"; 115 String got = sw.toString(); 116 assertEquals(expect, got); 117 } 118 119 121 public void testPrint() throws Exception { 122 String address = getAddress(); 123 InputSource isource = new InputSource (new StringReader (address)); 124 isource.setSystemId("testPrint.xml"); 125 Address addr = AddressPrinter.getAddress(isource); 126 JAXBContext context = JAXBContext.newInstance("org.apache.ws.jaxme.test.misc.address"); 127 StringWriter sw = new StringWriter (); 128 Marshaller m = context.createMarshaller(); 129 m.setProperty(JMMarshallerImpl.JAXME_XML_DECLARATION, Boolean.FALSE); 130 m.marshal(addr, sw); 131 sw.close(); 132 String got = sw.toString(); 133 assertEquals(address, got); 134 } 135 } 136 | Popular Tags |