use of org.apache.axiom.om.OMNode 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());
}
use of org.apache.axiom.om.OMNode in project webservices-axiom by apache.
the class TestBlobOMDataSource method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
String localName = "myPayload";
String encoding = "utf-8";
String payload = "<tns:myPayload xmlns:tns=\"urn://test\">Payload One</tns:myPayload>";
OMNamespace ns = factory.createOMNamespace("urn://test", "tns");
BlobOMDataSource ds = new BlobOMDataSource(Blobs.createBlob(payload.getBytes(encoding)), encoding);
OMElement parent = factory.createOMElement("root", null);
OMSourcedElement omse = factory.createOMElement(ds, localName, ns);
parent.addChild(omse);
OMNode firstChild = parent.getFirstOMChild();
assertTrue("Expected OMSourcedElement child", firstChild instanceof OMSourcedElement);
OMSourcedElement child = (OMSourcedElement) firstChild;
assertTrue("OMSourcedElement is expanded. This is unexpected", !child.isExpanded());
assertThat(child.getDataSource()).isSameAs(ds);
// A BlobOMDataSource does not consume the backing object when read.
// Thus getting the XMLStreamReader of the BlobOMDataSource should not
// cause expansion of the OMSourcedElement.
XMLStreamReader reader = child.getXMLStreamReader();
reader.next();
assertTrue("OMSourcedElement is expanded. This is unexpected", !child.isExpanded());
// Likewise, a BlobOMDataSource does not consume the backing object when
// written. Thus serializing the OMSourcedElement should not cause the expansion
// of the OMSourcedElement.
assertTrue("The payload was not present in the output", parent.toString().indexOf(payload) > 0);
assertTrue("OMSourcedElement is expanded. This is unexpected", !child.isExpanded());
// If a consumer calls build or buildWithAttachments on the tree, the
// tree should not be expanded.
parent.build();
assertTrue("OMSourcedElement is expanded after build(). This is unexpected", !child.isExpanded());
parent.buildWithAttachments();
assertTrue("OMSourcedElement is expanded after buildWithAttachments(). This is unexpected", !child.isExpanded());
// Test getting the raw bytes from the BlobOMDataSource.
assertThat(child.getDataSource()).isSameAs(ds);
}
use of org.apache.axiom.om.OMNode in project webservices-axiom by apache.
the class TestGetNextOMSiblingAfterDiscard method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<element><!--comment--><a/><!--comment--></element>")).getDocumentElement();
OMNode child = element.getFirstOMChild();
element.discard();
try {
child.getNextOMSibling();
fail("Expected NodeUnavailableException");
} catch (NodeUnavailableException ex) {
// Expected
}
}
use of org.apache.axiom.om.OMNode in project webservices-axiom by apache.
the class TestDetachFirstChild method runTest.
@Override
protected void runTest() throws Throwable {
OMElement root = AXIOMUtil.stringToOM(metaFactory.getOMFactory(), "<root><a/><b/></root>");
if (build) {
root.build();
} else {
assertFalse(root.isComplete());
}
OMNode oldFirstChild = root.getFirstOMChild();
assertNotNull(oldFirstChild);
oldFirstChild.detach();
OMNode newFirstChild = root.getFirstOMChild();
assertNotNull(newFirstChild);
assertNotSame(oldFirstChild, newFirstChild);
}
use of org.apache.axiom.om.OMNode in project webservices-axiom by apache.
the class TestInsertSiblingAfterSameParent 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);
text1.insertSiblingAfter(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