use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class TestSetTextQName method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element = factory.createOMElement("TestElement", null);
QName qname = new QName("urn:ns1", "test", "ns");
element.setText(qname);
boolean foundNamespace = false;
for (Iterator<OMNamespace> it = element.getAllDeclaredNamespaces(); it.hasNext(); ) {
OMNamespace ns = it.next();
if ("urn:ns1".equals(ns.getNamespaceURI()) && "ns".equals(ns.getPrefix())) {
foundNamespace = true;
}
}
assertTrue("Namespace of the text is not defined in the parent element", foundNamespace);
assertTrue(element.toString().contains("ns:test"));
assertEquals("ns:test", element.getText());
assertEquals(qname, element.getTextAsQName());
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class TestSetTextQNameWithEmptyPrefix method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element = factory.createOMElement("test", null);
QName qname = new QName("urn:test", "test");
element.setText(qname);
Iterator<OMNamespace> it = element.getAllDeclaredNamespaces();
assertTrue(it.hasNext());
OMNamespace ns = it.next();
assertEquals("urn:test", ns.getNamespaceURI());
String prefix = ns.getPrefix();
assertTrue(prefix.length() > 0);
assertEquals(prefix + ":test", element.getText());
assertFalse(it.hasNext());
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class TestCreateOMElementWithDefaultNamespace method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element = variant.createOMElement(factory, parentSupplier.createParent(factory), "test", "urn:ns", "");
assertTrue(element.isComplete());
assertEquals("test", element.getLocalName());
OMNamespace ns = factory.createOMNamespace("urn:ns", "");
assertEquals(ns, element.getNamespace());
Iterator<OMNamespace> it = element.getAllDeclaredNamespaces();
assertTrue(it.hasNext());
assertEquals(ns, it.next());
assertFalse(it.hasNext());
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class TestCreateOMElementWithGeneratedPrefix method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element = variant.createOMElement(factory, parentSupplier.createParent(factory), "test", "urn:test", null);
assertEquals("test", element.getLocalName());
OMNamespace ns = element.getNamespace();
assertNotNull(ns);
assertEquals("urn:test", ns.getNamespaceURI());
// Axiom auto-generates a prefix here
assertTrue(ns.getPrefix().length() != 0);
Iterator<OMNamespace> it = element.getAllDeclaredNamespaces();
assertTrue(it.hasNext());
assertEquals(ns, it.next());
assertFalse(it.hasNext());
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class TestCreateOMElementWithNamespaceInScope1 method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement parent = factory.createOMElement("parent", "urn:test", "p");
OMElement child = variant.createOMElement(factory, parent, "child", "urn:test", null);
assertTrue(child.isComplete());
assertEquals("child", child.getLocalName());
OMNamespace ns = factory.createOMNamespace("urn:test", "p");
assertEquals(ns, child.getNamespace());
Iterator<OMNamespace> it = child.getAllDeclaredNamespaces();
assertFalse(it.hasNext());
}
Aggregations