use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class TestDeclareNamespaceWithGeneratedPrefix3 method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element = factory.createOMElement(new QName("test"));
OMNamespace ns = element.declareNamespace("urn:ns", null);
assertEquals("urn:ns", ns.getNamespaceURI());
assertNotNull(ns.getPrefix());
assertTrue(ns.getPrefix().length() > 0);
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 TestFindNamespaceByPrefix method runTest.
@Override
protected void runTest() throws Throwable {
OMElement root = AXIOMUtil.stringToOM(metaFactory.getOMFactory(), "<a:root xmlns:a='urn:a'><child/></a:root>");
OMNamespace ns = root.getFirstElement().findNamespace(null, "a");
assertNotNull(ns);
assertEquals("urn:a", ns.getNamespaceURI());
root.close(false);
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class TestName1DefaultPrefix method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory f = metaFactory.getOMFactory();
// Create OMSE with an unknown prefix
OMNamespace rootNS = f.createOMNamespace("http://sampleroot", "rootPrefix");
OMNamespace ns = f.createOMNamespace("http://www.sosnoski.com/uwjws/library", null);
OMElement element = f.createOMElement(new PullOMDataSource(TestDocument.DOCUMENT1.getContent()), "library", ns);
OMElement root = f.createOMElement("root", rootNS);
root.addChild(element);
// Test getting the local name and namespace URI. This should used not result in expansion
assertTrue(element.getLocalName().equals("library"));
assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
// Serialize and cache. This should cause expansion. The prefix should be updated to match the testDocument string
StringWriter writer = new StringWriter();
root.serialize(writer);
String result = writer.toString();
assertTrue(element.getLocalName().equals("library"));
assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
assertTrue(element.getNamespace().getPrefix().equals(""));
assertTrue(element.getDefaultNamespace() != null);
assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
// Serialize again
writer = new StringWriter();
root.serialize(writer);
result = writer.toString();
assertTrue(element.getLocalName().equals("library"));
assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
assertTrue(element.getNamespace().getPrefix().equals(""));
assertTrue(element.getDefaultNamespace() != null);
assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class TestStringOMDataSource method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
String localName = "myPayload";
String payload1 = "<tns:myPayload xmlns:tns=\"urn://test\">Payload One</tns:myPayload>";
OMNamespace ns = factory.createOMNamespace("urn://test", "tns");
StringOMDataSource somds = new StringOMDataSource(payload1);
OMElement parent = factory.createOMElement("root", null);
OMSourcedElement omse = factory.createOMElement(somds, localName, ns);
parent.addChild(omse);
OMNode firstChild = parent.getFirstOMChild();
assertTrue("Expected OMSourcedElement child", firstChild instanceof OMSourcedElement);
OMSourcedElement child = (OMSourcedElement) firstChild;
assertTrue("OMSourcedElement is expanded. This is unexpected", !child.isExpanded());
assertThat(child.getDataSource()).isInstanceOf(StringOMDataSource.class);
// A StringOMDataSource does not consume the backing object when read.
// Thus getting the XMLStreamReader of the StringOMDataSource should not
// cause expansion of the OMSourcedElement.
XMLStreamReader reader = child.getXMLStreamReader();
reader.next();
assertTrue("OMSourcedElement is expanded. This is unexpected", !child.isExpanded());
// Likewise, a StringOMDataSource does not consume the backing object when
// written. Thus serializing the OMSourcedElement should not cause the expansion
// of the OMSourcedElement.
StringWriter out = new StringWriter();
parent.serialize(out);
// System.out.println(output);
assertTrue("The payload was not present in the output", out.toString().indexOf(payload1) > 0);
assertTrue("OMSourcedElement is expanded. This is unexpected", !child.isExpanded());
// Test getting the raw content from the StringOMDataSource.
StringOMDataSource ds = (StringOMDataSource) child.getDataSource();
assertThat(ds.getObject()).isEqualTo(payload1);
// Validate close
ds.close();
assertTrue("Close should free the resource", ds.getObject() == null);
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class TestBlobOMDataSource method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
String localName = "myPayload";
String encoding = "utf-8";
String payload = "<tns:myPayload xmlns:tns=\"urn://test\">Payload One</tns:myPayload>";
OMNamespace ns = factory.createOMNamespace("urn://test", "tns");
BlobOMDataSource ds = new BlobOMDataSource(Blobs.createBlob(payload.getBytes(encoding)), encoding);
OMElement parent = factory.createOMElement("root", null);
OMSourcedElement omse = factory.createOMElement(ds, localName, ns);
parent.addChild(omse);
OMNode firstChild = parent.getFirstOMChild();
assertTrue("Expected OMSourcedElement child", firstChild instanceof OMSourcedElement);
OMSourcedElement child = (OMSourcedElement) firstChild;
assertTrue("OMSourcedElement is expanded. This is unexpected", !child.isExpanded());
assertThat(child.getDataSource()).isSameAs(ds);
// A BlobOMDataSource does not consume the backing object when read.
// Thus getting the XMLStreamReader of the BlobOMDataSource should not
// cause expansion of the OMSourcedElement.
XMLStreamReader reader = child.getXMLStreamReader();
reader.next();
assertTrue("OMSourcedElement is expanded. This is unexpected", !child.isExpanded());
// Likewise, a BlobOMDataSource does not consume the backing object when
// written. Thus serializing the OMSourcedElement should not cause the expansion
// of the OMSourcedElement.
assertTrue("The payload was not present in the output", parent.toString().indexOf(payload) > 0);
assertTrue("OMSourcedElement is expanded. This is unexpected", !child.isExpanded());
// If a consumer calls build or buildWithAttachments on the tree, the
// tree should not be expanded.
parent.build();
assertTrue("OMSourcedElement is expanded after build(). This is unexpected", !child.isExpanded());
parent.buildWithAttachments();
assertTrue("OMSourcedElement is expanded after buildWithAttachments(). This is unexpected", !child.isExpanded());
// Test getting the raw bytes from the BlobOMDataSource.
assertThat(child.getDataSource()).isSameAs(ds);
}
Aggregations