use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class TestGetChildrenRemove3 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();
while (iter.hasNext()) {
iter.next();
iter.remove();
}
iter = elt.getChildren();
if (iter.hasNext()) {
//we shouldn't reach here!
fail("No children should remain after removing all!");
}
elt.close(false);
}
use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class TestGetChildrenRemove4 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 firstChildrenCount = 0;
int secondChildrenCount = 0;
while (iter.hasNext()) {
assertNotNull(iter.next());
firstChildrenCount++;
}
//remove the last node
iter.remove();
//reloop and check the count
//Note- here we should get a fresh iterator since there is no method to
//reset the iterator
//reset the iterator
iter = elt.getChildren();
while (iter.hasNext()) {
assertNotNull(iter.next());
secondChildrenCount++;
}
assertEquals("children count must reduce from 1", firstChildrenCount - 1, secondChildrenCount);
elt.close(false);
}
use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class TestGetChildrenWithLocalName method runTest.
@Override
protected void runTest() throws Throwable {
OMElement elt = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), XMLSample.SIMPLE.getInputStream()).getDocumentElement().getFirstElement();
Iterator<OMElement> it = elt.getChildrenWithLocalName("subelement");
assertThat(it.hasNext()).isTrue();
OMElement child = it.next();
assertThat(child.getQName()).isEqualTo(new QName("urn:ns2", "subelement"));
assertThat(it.hasNext()).isFalse();
elt.close(false);
}
use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class TestIsCompleteAfterAddingIncompleteChild method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement incompleteElement = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<elem>text</elem>")).getDocumentElement(true);
OMElement root = factory.createOMElement("root", null);
assertTrue(root.isComplete());
root.addChild(incompleteElement);
assertFalse(root.isComplete());
}
use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class TestRemoveAttribute method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element = factory.createOMElement("test", null);
OMAttribute attr1 = element.addAttribute("attr1", "value1", null);
OMAttribute attr2 = element.addAttribute("attr2", "value2", null);
element.removeAttribute(attr1);
assertNull(attr1.getOwner());
Iterator<OMAttribute> it = element.getAllAttributes();
assertTrue(it.hasNext());
assertSame(attr2, it.next());
assertFalse(it.hasNext());
}
Aggregations