use of org.apache.axiom.om.OMNamespace 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.OMNamespace in project webservices-axiom by apache.
the class TestMultipleDefaultNS method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory omFactory = metaFactory.getOMFactory();
OMNamespace defaultNS1 = omFactory.createOMNamespace("http://defaultNS1.org", null);
OMNamespace defaultNS2 = omFactory.createOMNamespace("http://defaultNS2.org", null);
OMElement omElementOne = omFactory.createOMElement("DocumentElement", omFactory.createOMNamespace("http://defaultNS1.org", ""));
OMElement omElementOneChild = omFactory.createOMElement("ChildOne", null, omElementOne);
OMElement omElementTwo = omFactory.createOMElement("Foo", defaultNS2, omElementOne);
omElementTwo.declareDefaultNamespace("http://defaultNS2.org");
OMElement omElementTwoChild = omFactory.createOMElement("ChildOne", null, omElementTwo);
OMElement omElementThree = omFactory.createOMElement("Bar", defaultNS1, omElementTwo);
omElementThree.declareDefaultNamespace("http://defaultNS1.org");
OMNamespace omElementOneChildNS = omElementOneChild.getNamespace();
OMNamespace omElementTwoChildNS = omElementTwoChild.getNamespace();
// TODO: LLOM's and DOOM's behaviors are slightly different here; need to check if both are allowed
assertTrue(omElementOneChildNS == null || "".equals(omElementOneChildNS.getNamespaceURI()));
assertTrue(omElementTwoChildNS == null || "".equals(omElementTwoChildNS.getNamespaceURI()));
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class TestGetChildrenWithName3 method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMNamespace testNamespace = factory.createOMNamespace("http://test.ws.org", "test");
OMElement documentElement = factory.createOMElement("Employees", testNamespace);
documentElement.declareNamespace(testNamespace);
factory.createOMText(documentElement, " ");
OMElement e = factory.createOMElement("Employee", testNamespace, documentElement);
e.setText("Apache Developer");
Iterator<OMElement> childrenIter = documentElement.getChildrenWithName(new QName("http://test.ws.org", "Employee", "test"));
// should walk past OMText
OMElement employee = childrenIter.next();
assertEquals("Employee test was incorrect", employee.getText(), "Apache Developer");
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class TestGetChildrenWithName4 method runTest.
@Override
protected void runTest() throws Throwable {
// Create a document with 2 children, each named "sample" but
// have different namespaces.
OMFactory factory = metaFactory.getOMFactory();
OMNamespace a = factory.createOMNamespace(NS_A, "a");
OMNamespace b = factory.createOMNamespace(NS_B, "b");
OMElement documentElement = factory.createOMElement("Document", a);
factory.createOMElement("sample", a, documentElement);
factory.createOMElement("sample", b, documentElement);
// Test for fully qualified names
QName qName = new QName(NS_A, "sample");
assertThat(getChildrenCount(documentElement.getChildrenWithName(qName))).isEqualTo(1);
qName = new QName(NS_B, "sample");
assertThat(getChildrenCount(documentElement.getChildrenWithName(qName))).isEqualTo(1);
qName = new QName(NS_C, "sample");
assertThat(getChildrenCount(documentElement.getChildrenWithName(qName))).isEqualTo(0);
// Test for QName with no namespace.
// Axiom 1.2.x implemented a legacy behavior where an empty namespace URI was interpreted
// as a wildcard (see AXIOM-11). In Axiom 1.3.x, the matching is always strict.
qName = new QName("", "sample");
assertThat(getChildrenCount(documentElement.getChildrenWithName(qName))).isEqualTo(0);
// Now add an unqualified sample element to the documentElement
factory.createOMElement("sample", null, documentElement);
// Repeat the tests
qName = new QName(NS_A, "sample");
assertThat(getChildrenCount(documentElement.getChildrenWithName(qName))).isEqualTo(1);
qName = new QName(NS_B, "sample");
assertThat(getChildrenCount(documentElement.getChildrenWithName(qName))).isEqualTo(1);
qName = new QName(NS_C, "sample");
assertThat(getChildrenCount(documentElement.getChildrenWithName(qName))).isEqualTo(0);
// Since there actually is an unqualified element child, the most accurate
// interpretation of getChildrenWithName should be to return this one
// child
qName = new QName("", "sample");
assertThat(getChildrenCount(documentElement.getChildrenWithName(qName))).isEqualTo(1);
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class TestGetDefaultNamespace method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement parent = factory.createOMElement("parent", "urn:ns1", "");
OMElement child = factory.createOMElement(new QName("urn:ns2", "child", "p"), parent);
OMNamespace ns = child.getDefaultNamespace();
assertNotNull(ns);
assertEquals("", ns.getPrefix());
assertEquals("urn:ns1", ns.getNamespaceURI());
}
Aggregations