use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class TestGetNamespaceURI method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMNamespace ns = factory.createOMNamespace("http://www.w3.org/XML/1998/namespace", "xml");
assertEquals("http://www.w3.org/XML/1998/namespace", ns.getNamespaceURI());
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class TestGetPrefix method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMNamespace ns = factory.createOMNamespace("http://www.w3.org/XML/1998/namespace", "xml");
assertEquals("xml", ns.getPrefix());
ns = factory.createOMNamespace("", null);
assertNull(ns.getPrefix());
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class TestCloneOMElementNamespaceRepairing method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
// Create a root element on which we declare the namespaces
OMElement root = factory.createOMElement("root", null);
OMNamespace ns1 = root.declareNamespace("urn:ns1", "ns1");
OMNamespace ns2 = root.declareNamespace("urn:ns2", "ns2");
root.declareNamespace("urn:ns3", "ns3");
// Create a child that uses these namespaces (in the element name and in the name of an attribute)
OMElement child = factory.createOMElement("child", ns1, root);
child.addAttribute("attr", "value", ns2);
// Check that the child has no namespace declarations (to validate the correctness of the test)
assertFalse(child.getAllDeclaredNamespaces().hasNext());
// Clone the child and check that namespace declarations have been generated automatically
OMElement clone = child.cloneOMElement();
Set<OMNamespace> expectedNSDecls = new HashSet<>();
expectedNSDecls.add(ns1);
expectedNSDecls.add(ns2);
Set<OMNamespace> actualNSDecls = new HashSet<>();
for (Iterator<OMNamespace> it = clone.getAllDeclaredNamespaces(); it.hasNext(); ) {
actualNSDecls.add(it.next());
}
assertEquals(expectedNSDecls, actualNSDecls);
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class TestDeclareNamespace1 method runTest.
@Override
protected void runTest() throws Throwable {
OMElement element = metaFactory.getOMFactory().createOMElement(new QName("test"));
OMNamespace ns = element.declareNamespace("urn:ns1", "ns1");
assertEquals("urn:ns1", ns.getNamespaceURI());
assertEquals("ns1", ns.getPrefix());
Iterator<OMNamespace> it = element.getAllDeclaredNamespaces();
assertTrue(it.hasNext());
OMNamespace ns2 = it.next();
assertEquals(ns, ns2);
assertFalse(it.hasNext());
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class TestAddAttributeMultiple method runTest.
@Override
protected void runTest() throws Throwable {
String expectedXML = "<AttributeTester xmlns:myAttr2NS=\"http://test-attributes-2.org\" " + "xmlns:myAttr1NS=\"http://test-attributes-1.org\" myAttr2NS:attrNumber=\"2\" myAttr1NS:attrNumber=\"1\" />";
OMFactory omFactory = metaFactory.getOMFactory();
OMNamespace attrNS1 = omFactory.createOMNamespace("http://test-attributes-1.org", "myAttr1NS");
OMNamespace attrNS2 = omFactory.createOMNamespace("http://test-attributes-2.org", "myAttr2NS");
OMElement omElement = omFactory.createOMElement("AttributeTester", null);
strategy.addAttribute(omElement, "attrNumber", attrNS1, "1");
strategy.addAttribute(omElement, "attrNumber", attrNS2, "2");
assertAbout(xml()).that(xml(OMElement.class, omElement)).hasSameContentAs(expectedXML);
}
Aggregations