So I found MarshallerTest and I added the following tests. (I am having
trouble with the marshaller test with whitespace comparison...can you
help me out here....how do you deal with this?).
Anyways, here are the tests....(I don't fully test out using a
Classloader outside the environment and I might add a test for that
later as it is a little more difficult. I would have to load a jar
dynamically into the jvm through the URL classloader...or load class
files off filesystem).
/** <p>Tests marshalling of non-registered element and then
* registers package and test that it can be marshalled now</p>
*/
public void testDynamicMarshal() throws Exception {
JAXBContext ctx = getFactory();
Marshaller marshaller = ctx.createMarshaller();
org.apache.ws.jaxme.test.misc.address.ObjectFactory factory =
new org.apache.ws.jaxme.test.misc.address.ObjectFactory();
Address addr = factory.createAddress();
NameType name = factory.createAddressTypeNameType();
PostalType postal = factory.createAddressTypePostalType();
postal.setStreet("56 East Ave");
postal.setZIP("50344");
postal.setCity("thornton");
postal.setCountry("US");
postal.setState("CO");
name.setFirst("dean");
name.setLast("hiller");
addr.setId("someID");
addr.setName(name);
addr.setPostal(postal);
StringWriter writer = new StringWriter();
try {
marshaller.marshal(addr, writer);
fail("Should have thrown an exception since address is not
registered yet");
} catch(JAXBException e) {}
//now register(this is not JAXB compliant as of yet)
JAXBContextImpl ctxImpl = (JAXBContextImpl)ctx;
ctxImpl.registerPackages("org.apache.ws.jaxme.test.misc.address",
addr.getClass().getClassLoader());
writer = new StringWriter();
marshaller.marshal(addr, writer);
assertEquals(getXml(), writer.toString());
}
public String getXml() {
return "<?xml version='1.0' encoding='UTF-8'?>\n <Address
id=\"someID\"
xmlns=\"http://ws.apache.org/jaxme/test/misc/address\">\n
<Name>\n <First>dean</First>\n
<Last>hiller</Last>\n </Name>\n <Postal>\n
<Street>56 East Ave</Street>\n <ZIP>50344</ZIP>\n
<City>thornton</City>\n <State>CO</State>\n
<Country>US</Country>\n </Postal>\n </Address>";
}
public void testDynamicUnmarshal() throws JAXBException {
JAXBContext ctx = getFactory();
Unmarshaller unmarshaller = ctx.createUnmarshaller();
StringReader reader = new StringReader(getXml());
InputSource src = new InputSource(reader);
try {
unmarshaller.unmarshal(src);
fail("Should fail since package not registered");
} catch(JAXBException e) {}
//now register(this is not JAXB compliant as of yet)
JAXBContextImpl ctxImpl = (JAXBContextImpl)ctx;
ctxImpl.registerPackages("org.apache.ws.jaxme.test.misc.address",
Address.class.getClassLoader());
reader = new StringReader(getXml());
src = new InputSource(reader);
Address addr = (Address)unmarshaller.unmarshal(src);
assertEquals("someID", addr.getId());
assertEquals("dean", addr.getName().getFirst());
assertEquals("hiller", addr.getName().getLast());
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]