use of org.apache.axiom.om.OMText 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.OMText in project webservices-axiom by apache.
the class TestAddChild method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element = factory.createOMElement("test", null);
OMText text = factory.createOMText("test");
element.addChild(text);
assertSame(element, text.getParent());
assertSame(text, element.getFirstOMChild());
}
use of org.apache.axiom.om.OMText in project webservices-axiom by apache.
the class TestAddChildWithParent method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element1 = factory.createOMElement("test1", null);
OMElement element2 = factory.createOMElement("test2", null);
OMText text = factory.createOMText("test");
element1.addChild(text);
element2.addChild(text);
assertSame(element2, text.getParent());
assertNull(element1.getFirstOMChild());
assertSame(text, element2.getFirstOMChild());
}
use of org.apache.axiom.om.OMText in project webservices-axiom by apache.
the class TestDataHandlerExpansion method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
DataHandler dh = new DataHandler("some content", "text/plain");
DocumentBean object = new DocumentBean();
object.setId("123456");
object.setContent(dh);
OMElement element = factory.createOMElement(new JAXBOMDataSource(context, object));
OMElement child = (OMElement) element.getFirstOMChild();
assertEquals("id", child.getLocalName());
assertEquals("123456", child.getText());
child = (OMElement) child.getNextOMSibling();
assertEquals("content", child.getLocalName());
OMText content = (OMText) child.getFirstOMChild();
assertTrue(content.isBinary());
assertTrue(content.isOptimized());
assertSame(dh, content.getDataHandler());
}
use of org.apache.axiom.om.OMText in project webservices-axiom by apache.
the class TestInsertSiblingBeforeSameParent method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory fac = metaFactory.getOMFactory();
OMElement parent = fac.createOMElement("test", null);
OMText text1 = fac.createOMText("text1");
OMText text2 = fac.createOMText("text2");
OMText text3 = fac.createOMText("text3");
parent.addChild(text1);
parent.addChild(text2);
parent.addChild(text3);
text2.insertSiblingBefore(text3);
assertSame(parent, text3.getParent());
Iterator<OMNode> it = parent.getChildren();
assertSame(text1, it.next());
assertSame(text3, it.next());
assertSame(text2, it.next());
assertFalse(it.hasNext());
}
Aggregations