use of org.apache.axiom.om.OMNode in project webservices-axiom by apache.
the class TestGetChildrenWithName method runTest.
@Override
protected void runTest() throws Throwable {
OMElement elt = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), XMLSample.SIMPLE.getInputStream()).getDocumentElement().getFirstElement();
QName qname = new QName("urn:ns2", "subelement");
Iterator<OMElement> iter = elt.getChildrenWithName(qname);
int counter = 0;
while (iter.hasNext()) {
counter++;
Object o = iter.next();
assertNotNull("Must return not null objects!", o);
assertTrue("All these should be elements!", ((OMNode) o).getType() == OMNode.ELEMENT_NODE);
}
assertEquals("This element should contain only one element with the given QName ", 1, counter);
elt.close(false);
}
use of org.apache.axiom.om.OMNode in project webservices-axiom by apache.
the class TestGetDescendantsRemoveSubtree method runTest.
@Override
protected void runTest() throws Throwable {
OMElement root = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StringReader("<root><a><b/></a><c/></root>")).getDocumentElement();
Iterator<OMNode> it = root.getDescendants(false);
assertThat(((OMElement) it.next()).getLocalName()).isEqualTo("a");
it.remove();
assertThat(((OMElement) it.next()).getLocalName()).isEqualTo("c");
}
use of org.apache.axiom.om.OMNode in project webservices-axiom by apache.
the class TestGetDescendants method runTest.
@Override
protected void runTest() throws Throwable {
OMElement element = AXIOMUtil.stringToOM(metaFactory.getOMFactory(), "<root><a><b><c><d/><e/></c></b><f/></a><g/></root>");
// We intentionally get the descendants of <a> so that we can test containment
// (the iterator must never return <g>, which is a sibling of <a>).
Iterator<OMNode> it = element.getFirstElement().getDescendants(includeSelf);
if (includeSelf) {
assertEquals("a", ((OMElement) it.next()).getLocalName());
}
assertEquals("b", ((OMElement) it.next()).getLocalName());
assertEquals("c", ((OMElement) it.next()).getLocalName());
assertEquals("d", ((OMElement) it.next()).getLocalName());
assertEquals("e", ((OMElement) it.next()).getLocalName());
assertEquals("f", ((OMElement) it.next()).getLocalName());
assertFalse(it.hasNext());
}
use of org.apache.axiom.om.OMNode in project webservices-axiom by apache.
the class TestGetChildren method runTest.
@Override
protected void runTest() throws Throwable {
OMElement elt = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StringReader("<root>a<b/><!--c--><d/>e</root>")).getDocumentElement();
Iterator<OMNode> iter = elt.getChildren();
int counter = 0;
while (iter.hasNext()) {
counter++;
assertNotNull("Must return not null objects!", iter.next());
}
assertEquals("This element should contain only five children including the text ", 5, counter);
elt.close(false);
}
use of org.apache.axiom.om.OMNode in project webservices-axiom by apache.
the class TestGetChildrenConcurrentModification method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement parent = factory.createOMElement("parent", null);
factory.createOMElement("child1", null, parent);
factory.createOMElement("child2", null, parent);
factory.createOMElement("child3", null, parent);
Iterator<OMNode> it = parent.getChildren();
it.next();
OMElement child2 = (OMElement) it.next();
child2.detach();
try {
it.next();
fail("Expected ConcurrentModificationException");
} catch (ConcurrentModificationException ex) {
// Expected
}
}
Aggregations