use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class WriteNamespaceScenario method validate.
@Override
public void validate(OMElement element, boolean dataHandlersPreserved) throws Throwable {
OMNamespace decl = null;
Iterator<OMNamespace> it = element.getAllDeclaredNamespaces();
while (it.hasNext()) {
OMNamespace ns = it.next();
if (!ns.getPrefix().equals("_p_")) {
if (decl != null) {
Assert.fail("Found unexpected namespace declaration");
} else {
decl = ns;
}
}
}
Assert.assertNotNull(decl);
Assert.assertEquals(prefix, decl.getPrefix());
Assert.assertEquals(namespaceURI, decl.getNamespaceURI());
}
use of org.apache.axiom.om.OMNamespace 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());
}
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class TestGetAttributeTypeDefault method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMNamespace ns = factory.createOMNamespace("http://www.me.com", "axiom");
OMAttribute at = factory.createOMAttribute("id", ns, "value");
assertEquals("CDATA", at.getAttributeType());
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class OMElementTest method testChildDetachment.
public void testChildDetachment() {
OMNamespace testNamespace2 = factory.createOMNamespace("ftp://anotherTest.ws.org", "ws");
secondElement.detach();
assertTrue("OMElement children detachment has not worked properly", !secondElement.equals(firstElement.getFirstElement()));
assertNull("First Element should not contain elements after detaching. ", firstElement.getFirstElement());
assertNull("First Element should not contain elements after detaching. ", firstElement.getFirstOMChild());
assertNull(secondElement.findNamespace(testNamespace2.getNamespaceURI(), testNamespace2.getPrefix()));
firstElement.addChild(secondElement);
factory.createOMText(firstElement, "Some Sample Text");
assertTrue("First added child must be the first child", secondElement.equals(firstElement.getFirstOMChild()));
Iterator children = firstElement.getChildren();
int childCount = 0;
while (children.hasNext()) {
children.next();
childCount++;
}
assertEquals("Children count should be two", childCount, 2);
secondElement.detach();
assertTrue("First child should be the text child", firstElement.getFirstOMChild() instanceof OMText);
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class TestExtractAllHeaderBlocks method runTest.
@Override
protected void runTest() throws Throwable {
SOAPEnvelope envelope = soapFactory.createSOAPEnvelope();
SOAPHeader header = soapFactory.createSOAPHeader(envelope);
OMNamespace ns = soapFactory.createOMNamespace("urn:ns", "p");
SOAPHeaderBlock h1 = header.addHeaderBlock("header1", ns);
SOAPHeaderBlock h2 = header.addHeaderBlock("header2", ns);
Iterator<SOAPHeaderBlock> it = header.extractAllHeaderBlocks();
assertTrue(it.hasNext());
assertSame(h1, it.next());
assertTrue(it.hasNext());
assertSame(h2, it.next());
assertFalse(it.hasNext());
}
Aggregations