Search in sources :

Example 1 with UnqualifiedBean

use of org.apache.cxf.jaxb.fortest.unqualified.UnqualifiedBean in project cxf by apache.

the class JAXBDataBindingTest method testContextProperties.

@Test
public void testContextProperties() throws Exception {
    JAXBDataBinding db = new JAXBDataBinding();
    Map<String, String> nsMap = new HashMap<>();
    nsMap.put("uri:ultima:thule", "");
    db.setNamespaceMap(nsMap);
    Map<String, Object> contextProperties = new HashMap<>();
    contextProperties.put("com.sun.xml.bind.defaultNamespaceRemap", "uri:ultima:thule");
    db.setContextProperties(contextProperties);
    Set<Class<?>> classes = new HashSet<Class<?>>();
    classes.add(UnqualifiedBean.class);
    db.setContext(db.createJAXBContext(classes));
    DataWriter<XMLStreamWriter> writer = db.createWriter(XMLStreamWriter.class);
    XMLOutputFactory writerFactory = XMLOutputFactory.newInstance();
    StringWriter stringWriter = new StringWriter();
    XMLStreamWriter xmlWriter = writerFactory.createXMLStreamWriter(stringWriter);
    UnqualifiedBean bean = new UnqualifiedBean();
    bean.setAriadne("spider");
    writer.write(bean, xmlWriter);
    xmlWriter.flush();
    String xml = stringWriter.toString();
    assertTrue(xml, xml.contains("uri:ultima:thule"));
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) HashMap(java.util.HashMap) UnqualifiedBean(org.apache.cxf.jaxb.fortest.unqualified.UnqualifiedBean) StringWriter(java.io.StringWriter) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1 UnqualifiedBean (org.apache.cxf.jaxb.fortest.unqualified.UnqualifiedBean)1 Test (org.junit.Test)1