use of org.apache.axiom.om.ds.StringOMDataSource in project webservices-axiom by apache.
the class TestCloneWithSourcedElement1 method runTest.
@Override
protected void runTest() throws Throwable {
SOAPEnvelope sourceEnv = soapFactory.getDefaultEnvelope();
SOAPBody body = sourceEnv.getBody();
// Create a payload
OMDataSource bads = new StringOMDataSource("<tns:payload xmlns:tns=\"urn://test\">Hello World</tns:payload>");
OMNamespace ns = body.getOMFactory().createOMNamespace("urn://test", "tns");
OMSourcedElement omse = body.getOMFactory().createOMElement(bads, "payload", ns);
body.addChild(omse);
copyAndCheck(sourceEnv);
assertFalse(omse.isExpanded());
}
use of org.apache.axiom.om.ds.StringOMDataSource in project webservices-axiom by apache.
the class TestHasFaultWithOMSEUnknownName method runTest.
@Override
protected void runTest() throws Throwable {
SOAPEnvelope envelope = soapFactory.getDefaultEnvelope();
SOAPBody body = envelope.getBody();
OMSourcedElement element = soapFactory.createOMElement(new StringOMDataSource("<ns:root xmlns:ns='urn:ns'/>"));
body.addChild(element);
assertFalse(body.hasFault());
assertFalse(element.isExpanded());
}
use of org.apache.axiom.om.ds.StringOMDataSource in project webservices-axiom by apache.
the class TestSerializeModifiedOMSEWithNonDestructiveDataSource method runTest.
@Override
protected void runTest() throws Throwable {
OMDataSourceExt ds = new StringOMDataSource("<element><child/></element>");
assertFalse(ds.isDestructiveWrite());
OMFactory f = metaFactory.getOMFactory();
OMElement element = f.createOMElement(ds, "element", null);
element.getFirstElement().setText("TEST");
StringWriter sw = new StringWriter();
element.serialize(sw);
assertTrue(sw.toString().indexOf("TEST") != -1);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
element.serialize(baos);
assertTrue(new String(baos.toByteArray(), "UTF-8").indexOf("TEST") != -1);
assertTrue(element.toString().indexOf("TEST") != -1);
}
use of org.apache.axiom.om.ds.StringOMDataSource 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.ds.StringOMDataSource in project webservices-axiom by apache.
the class TestCloneUnknownName method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMDataSource ds = new StringOMDataSource("<p:element xmlns:p='urn:ns'>test</p:element>");
OMSourcedElement element = factory.createOMElement(ds);
OMCloneOptions options = new OMCloneOptions();
options.setCopyOMDataSources(true);
OMElement clone = (OMElement) element.clone(options);
assertTrue(clone instanceof OMSourcedElement);
assertFalse(element.isExpanded());
OMNamespace expectedNS = factory.createOMNamespace("urn:ns", "p");
assertEquals("element", element.getLocalName());
assertEquals("element", clone.getLocalName());
assertEquals(expectedNS, element.getNamespace());
assertEquals(expectedNS, clone.getNamespace());
}
Aggregations