use of org.apache.cxf.jaxb.fortest.QualifiedBean in project cxf by apache.
the class JAXBDataBindingTest method doNamespaceMappingTest.
void doNamespaceMappingTest(boolean internal, boolean asm) throws Exception {
if (internal) {
try {
Class.forName("com.sun.xml.internal.bind.v2.ContextFactory");
} catch (Throwable t) {
// on a JVM (likely IBM's) that doesn't rename the ContextFactory package to include "internal"
return;
}
}
try {
if (!asm) {
ReflectionUtil.setAccessible(ReflectionUtil.getDeclaredField(ASMHelper.class, "badASM")).set(null, Boolean.TRUE);
}
JAXBDataBinding db = createJaxbContext(internal);
DataWriter<XMLStreamWriter> writer = db.createWriter(XMLStreamWriter.class);
XMLOutputFactory writerFactory = XMLOutputFactory.newInstance();
StringWriter stringWriter = new StringWriter();
XMLStreamWriter xmlWriter = writerFactory.createXMLStreamWriter(stringWriter);
QualifiedBean bean = new QualifiedBean();
bean.setAriadne("spider");
writer.write(bean, xmlWriter);
xmlWriter.flush();
String xml = stringWriter.toString();
assertTrue("Failed to map namespace " + xml, xml.contains("greenland=\"uri:ultima:thule"));
} finally {
if (!asm) {
ReflectionUtil.setAccessible(ReflectionUtil.getDeclaredField(ASMHelper.class, "badASM")).set(null, Boolean.FALSE);
}
}
}
Aggregations