use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestSetTextQNameWithExistingChildren method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element = factory.createOMElement("TestElement", null);
// Add some children of various types
factory.createOMText(element, "some text");
factory.createOMText(element, "cdata section", OMNode.CDATA_SECTION_NODE);
factory.createOMComment(element, "comment");
factory.createOMProcessingInstruction(element, "piTarget", "piData");
factory.createOMElement("child", null, element);
QName qname = new QName("urn:ns1", "test", "ns");
element.setText(qname);
assertEquals("ns:test", element.getText());
// Check that OMElement#setText() has created the expected nodes
OMNode child = element.getFirstOMChild();
assertTrue(child instanceof OMText);
assertSame(element, child.getParent());
assertEquals("ns:test", ((OMText) child).getText());
assertNull(child.getNextOMSibling());
}
use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestSetTextQNameWithoutNamespace method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element = factory.createOMElement("test", null);
QName qname = new QName("test");
element.setText(qname);
assertFalse(element.getAllDeclaredNamespaces().hasNext());
assertEquals("test", element.getText());
}
use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestUnmarshalWithDataHandler method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
DocumentBean orgBean = new DocumentBean();
orgBean.setId("AB23498");
orgBean.setContent(new DataHandler("test content", "text/plain"));
OMElement element = factory.createOMElement(new JAXBOMDataSource(context, orgBean));
DocumentBean bean = (DocumentBean) element.unmarshal(context, null, true);
assertEquals(orgBean.getId(), bean.getId());
assertEquals(orgBean.getContent(), bean.getContent());
}
use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestWriteTextTo method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element = factory.createOMElement(new QName("a"));
factory.createOMText(element, "test");
StringWriter sw = new StringWriter();
InstrumentedWriter out = new InstrumentedWriter(sw);
element.writeTextTo(out, true);
assertEquals(element.getText(), sw.toString());
assertFalse(out.isClosed());
}
use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestCreateOMElementWithDefaultNamespace method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element = variant.createOMElement(factory, parentSupplier.createParent(factory), "test", "urn:ns", "");
assertTrue(element.isComplete());
assertEquals("test", element.getLocalName());
OMNamespace ns = factory.createOMNamespace("urn:ns", "");
assertEquals(ns, element.getNamespace());
Iterator<OMNamespace> it = element.getAllDeclaredNamespaces();
assertTrue(it.hasNext());
assertEquals(ns, it.next());
assertFalse(it.hasNext());
}
Aggregations