use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class TestAddAttributeGeneratedPrefix method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMNamespace otherNS = factory.createOMNamespace("urn:ns2", "p");
OMElement parent = factory.createOMElement("parent", otherNS);
if (defaultNamespaceInScope) {
parent.declareDefaultNamespace("urn:test");
}
OMElement element = factory.createOMElement("test", otherNS, parent);
OMAttribute attr = element.addAttribute("attr", "value", factory.createOMNamespace("urn:test", null));
OMNamespace ns = attr.getNamespace();
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 TestAddAttributeReplace method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
// Use same namespace URI but different prefixes
OMNamespace ns1 = factory.createOMNamespace("urn:ns", "p1");
OMNamespace ns2 = factory.createOMNamespace("urn:ns", "p2");
OMElement element = factory.createOMElement(new QName("test"));
OMAttribute att1 = strategy.addAttribute(element, "test", ns1, "value1");
OMAttribute att2 = strategy.addAttribute(element, "test", ns2, "value2");
Iterator<OMAttribute> it = element.getAllAttributes();
assertThat(it.hasNext()).isTrue();
assertThat(it.next()).isSameAs(att2);
assertThat(it.hasNext()).isFalse();
assertThat(att1.getOwner()).isNull();
assertThat(att2.getOwner()).isSameAs(element);
assertThat(att1).hasValue("value1");
assertThat(att2).hasValue("value2");
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class TestAddAttributeWithExistingNamespaceDeclarationInScope method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement root = factory.createOMElement(new QName("test"));
OMNamespace ns = factory.createOMNamespace("urn:ns", "p");
root.declareNamespace(ns);
OMElement child = factory.createOMElement(new QName("test"), root);
strategy.addAttribute(child, "test", ns, "test");
Iterator<OMNamespace> it = child.getAllDeclaredNamespaces();
assertFalse(it.hasNext());
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class TestFindNamespaceURIWithPrefixUndeclaring method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement parent = factory.createOMElement("parent", null);
OMElement child = factory.createOMElement("child", null, parent);
OMNamespace ns = parent.declareNamespace("urn:test", "p");
child.undeclarePrefix("p");
assertEquals(ns, parent.findNamespaceURI("p"));
assertNull(child.findNamespaceURI("p"));
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class TestDeclareNamespaceWithEmptyPrefix method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element = factory.createOMElement(new QName("test"));
OMNamespace ns = element.declareNamespace("urn:ns", "");
assertThat(ns.getNamespaceURI()).isEqualTo("urn:ns");
assertThat(ns.getPrefix()).isEmpty();
Iterator<OMNamespace> it = element.getAllDeclaredNamespaces();
assertThat(it.hasNext()).isTrue();
OMNamespace ns2 = it.next();
assertThat(ns2).isEqualTo(ns);
assertThat(it.hasNext()).isFalse();
}
Aggregations