use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class TestGetNamespacesInScopeWithDefaultNamespace method runTest.
@Override
protected void runTest() throws Throwable {
OMElement element = AXIOMUtil.stringToOM(metaFactory.getOMFactory(), "<a xmlns='urn:test'><b/></a>");
Iterator<OMNamespace> it = element.getFirstElement().getNamespacesInScope();
assertTrue(it.hasNext());
OMNamespace ns = it.next();
assertEquals("", ns.getPrefix());
assertEquals("urn:test", ns.getNamespaceURI());
assertFalse(it.hasNext());
}
use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class TestGetNamespacesInScope method runTest.
@Override
protected void runTest() throws Throwable {
OMElement element = AXIOMUtil.stringToOM(metaFactory.getOMFactory(), "<a xmlns:ns1='urn:ns1'><b xmlns:ns2='urn:ns2'/></a>");
boolean ns1seen = false;
boolean ns2seen = false;
Iterator<OMNamespace> it = element.getFirstElement().getNamespacesInScope();
int count = 0;
while (it.hasNext()) {
OMNamespace ns = it.next();
count++;
if (ns.getPrefix().equals("ns1")) {
ns1seen = true;
assertEquals("urn:ns1", ns.getNamespaceURI());
} else if (ns.getPrefix().equals("ns2")) {
ns2seen = true;
assertEquals("urn:ns2", ns.getNamespaceURI());
} else {
fail("Unexpected prefix: " + ns.getPrefix());
}
}
assertEquals("Number of namespaces in scope", 2, count);
assertTrue(ns1seen);
assertTrue(ns2seen);
}
use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class TestGetPrefixWithDefaultNamespace method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element = factory.createOMElement("test", factory.createOMNamespace("urn:ns", ""));
assertNull(element.getPrefix());
}
use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class TestGetPrefixWithoutNamespace method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element = factory.createOMElement(new QName("test"));
assertNull(element.getPrefix());
}
use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class TestGetChildrenRemove2 method runTest.
@Override
protected void runTest() throws Throwable {
OMElement elt = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StringReader("<root><child1/><child2/></root>")).getDocumentElement();
Iterator<OMNode> iter = elt.getChildren();
if (iter.hasNext()) {
iter.next();
}
iter.remove();
//this call must generate an exception
try {
iter.remove();
fail("calling remove twice without a call to next is prohibited");
} catch (IllegalStateException e) {
//ok if we come here :)
}
elt.close(false);
}
Aggregations