use of org.apache.axiom.om.OMFactory 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.OMFactory in project webservices-axiom by apache.
the class TestCreateOMElementWithInvalidNamespace method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
try {
variant.createOMElement(factory, parentSupplier.createParent(factory), "test", "", "p");
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException ex) {
// Expected
}
}
use of org.apache.axiom.om.OMFactory 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());
}
use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestCreateOMElementWithNamespaceInScope2 method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement parent = factory.createOMElement("parent", "urn:test", "p1");
OMElement child = variant.createOMElement(factory, parent, "child", "urn:test", "p2");
OMNamespace ns = factory.createOMNamespace("urn:test", "p2");
assertEquals(ns, child.getNamespace());
Iterator<OMNamespace> it = child.getAllDeclaredNamespaces();
assertTrue(it.hasNext());
}
use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestRemoveChildren method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<root><a>A</a><b>B</b></root>")).getDocumentElement();
if (complete) {
element.build();
}
OMElement firstChild = (OMElement) element.getFirstOMChild();
assertEquals(complete, element.isComplete());
assertEquals(complete, firstChild.isComplete());
element.removeChildren();
// We still need to be able to get the content of the child we retrieved before
// calling removeChildren.
assertEquals("A", firstChild.getText());
// Test that the child has been detached correctly.
assertNull(firstChild.getParent());
assertNull(firstChild.getPreviousOMSibling());
assertNull(firstChild.getNextOMSibling());
// Test that the element is now empty.
assertNull(element.getFirstOMChild());
// Check that the element is in a clean state and that we are able to add
// new children.
element.addChild(factory.createOMElement("c", null));
assertAbout(xml()).that(xml(OMElement.class, element)).hasSameContentAs("<root><c/></root>");
}
Aggregations