use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestAppendChildIncomplete method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
Document document = (Document) OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<root><a/><b/></root>")).getDocument();
Element parent = document.getDocumentElement();
parent.appendChild(document.createElementNS(null, "c"));
NodeList children = parent.getChildNodes();
assertEquals(3, children.getLength());
assertEquals("a", children.item(0).getLocalName());
assertEquals("b", children.item(1).getLocalName());
assertEquals("c", children.item(2).getLocalName());
}
use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestInsertBeforeIncomplete method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
Document document = (Document) OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<root><a/><b/></root>")).getDocument();
Element parent = document.getDocumentElement();
parent.insertBefore(document.createElementNS(null, "c"), null);
NodeList children = parent.getChildNodes();
assertEquals(3, children.getLength());
assertEquals("a", children.item(0).getLocalName());
assertEquals("b", children.item(1).getLocalName());
assertEquals("c", children.item(2).getLocalName());
}
use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestRemoveAttributeNSNamespaceDeclaration method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element = factory.createOMElement("test", null);
element.declareNamespace("urn:test", "ns");
((Element) element).removeAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "ns");
assertFalse(element.getAllDeclaredNamespaces().hasNext());
}
use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class JAXBTest method test.
@Test
public void test() throws Exception {
OMFactory factory = OMAbstractFactory.getOMFactory();
JAXBContext context = JAXBContext.newInstance(DummyBean.class);
OMSourcedElement element = factory.createOMElement(new JAXBOMDataSource(context, new DummyBean()));
element.serialize(new ByteArrayOutputStream());
}
use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class SetNamespaceTestCase method runTest.
@Override
protected final void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element;
OMNamedInformationItem node;
if (context()) {
// To avoid collisions if prefixInScope is the empty string
OMNamespace dummyNS = factory.createOMNamespace("__dummy__", "__dummy__");
OMElement parent = factory.createOMElement("parent", dummyNS);
element = factory.createOMElement("test", dummyNS, parent);
if (prefixInScope != null) {
if (prefixInScope.length() == 0) {
parent.declareDefaultNamespace(namespaceURI);
} else {
parent.declareNamespace(namespaceURI, prefixInScope);
}
}
} else {
element = null;
}
node = node(factory, element);
OMNamespace ns = namespaceURI == null ? null : factory.createOMNamespace(namespaceURI, prefix);
try {
setNamespace(node, ns);
if (invalid) {
fail("Expected IllegalArgumentException");
}
} catch (IllegalArgumentException ex) {
if (invalid) {
return;
} else {
throw ex;
}
}
String expectedPrefix;
if (this.expectedPrefix == null) {
expectedPrefix = node.getPrefix();
assertNotNull(expectedPrefix);
assertFalse(expectedPrefix.length() == 0);
} else {
expectedPrefix = this.expectedPrefix;
if (expectedPrefix.length() == 0) {
assertNull(node.getPrefix());
} else {
assertEquals(expectedPrefix, node.getPrefix());
}
}
if (namespaceURI == null || namespaceURI.length() == 0) {
assertNull(node.getNamespace());
} else {
OMNamespace actualNS = node.getNamespace();
assertEquals(expectedPrefix, actualNS.getPrefix());
assertEquals(namespaceURI, actualNS.getNamespaceURI());
}
if (namespaceURI == null || namespaceURI.length() == 0) {
assertNull(node.getNamespaceURI());
} else {
assertEquals(namespaceURI, node.getNamespaceURI());
}
QName qname = node.getQName();
assertEquals(expectedPrefix, qname.getPrefix());
assertEquals(namespaceURI == null ? "" : namespaceURI, qname.getNamespaceURI());
if (element != null) {
Iterator<OMNamespace> it = element.getAllDeclaredNamespaces();
if (expectNSDecl) {
assertTrue(it.hasNext());
OMNamespace decl = it.next();
assertEquals(expectedPrefix, decl.getPrefix());
assertEquals(namespaceURI == null ? "" : namespaceURI, decl.getNamespaceURI());
}
assertFalse(it.hasNext());
}
}
Aggregations