Mapping mapping = xmlContext.createMapping();
mapping.loadMapping(getClass().getResource(MAPPING_FILE).toExternalForm());
StringWriter out = new StringWriter();
Marshaller marshaller = xmlContext.createMarshaller();
marshaller.setWriter(out);
marshaller.setMapping(mapping);
// Joachim 2007-09-04 before XMLContext was introduced it looked like:
// Configuration config = LocalConfiguration.getInstance();
// config.getProperties().setProperty(
// XMLConfiguration.PROXY_INTERFACES, "net.sf.cglib.proxy.Factory");
//
// Mapping mapping = new Mapping();
// mapping.loadMapping(getClass().getResource(MAPPING_FILE).toExternalForm());
//
// StringWriter out = new StringWriter();
// Marshaller marshaller = new Marshaller(out);
// marshaller.setMapping(mapping);
Bean refered = new Bean(new Integer(999), "element of 999", null);
Bean referedProxy = (Bean) Proxy.newInstance(refered);
assertNotNull(referedProxy);
assertEquals(Bean.class, referedProxy.getClass().getSuperclass());
assertEquals(1, referedProxy.getClass().getInterfaces().length);
assertEquals(Factory.class, referedProxy.getClass().getInterfaces()[0]);
assertEquals(999, referedProxy.getAttribute().intValue());
assertEquals("element of 999", referedProxy.getElement());
assertNull(referedProxy.getReference());
Bean referer = new Bean(new Integer(100), "element of 100", referedProxy);
Bean refererProxy = (Bean) Proxy.newInstance(referer);
assertNotNull(refererProxy);
assertEquals(Bean.class, refererProxy.getClass().getSuperclass());
assertEquals(1, refererProxy.getClass().getInterfaces().length);
assertEquals(Factory.class, refererProxy.getClass().getInterfaces()[0]);
assertEquals(100, refererProxy.getAttribute().intValue());
assertEquals("element of 100", refererProxy.getElement());
assertNotNull(refererProxy.getReference());
marshaller.marshal(refererProxy);
String output = out.toString();
String expected
= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"