use of org.apache.axiom.om.ds.WrappedTextNodeOMDataSourceFromDataSource in project webservices-axiom by apache.
the class TestGetObject method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
DataSource ds = new BlobDataSource(Blobs.createBlob("test".getBytes("utf-8")), "text/plain; charset=utf-8");
OMSourcedElement element = factory.createOMElement(new WrappedTextNodeOMDataSourceFromDataSource(new QName("wrapper"), ds, Charset.forName("utf-8")));
// getObject returns null if the data source is not of the expected type
assertNull(element.getObject(StringOMDataSource.class));
// Test with the right data source type
assertSame(ds, element.getObject(WrappedTextNodeOMDataSourceFromDataSource.class));
assertSame(ds, element.getObject(WrappedTextNodeOMDataSource.class));
// Now modify the content of the element
factory.createOMComment(element, "comment");
assertNull(element.getObject(WrappedTextNodeOMDataSourceFromDataSource.class));
}
use of org.apache.axiom.om.ds.WrappedTextNodeOMDataSourceFromDataSource in project webservices-axiom by apache.
the class TestCloneNonDestructive method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMDataSource ds = new WrappedTextNodeOMDataSourceFromDataSource(new QName("wrapper"), new ByteArrayDataSource("test".getBytes("utf-8")), Charset.forName("utf-8"));
OMSourcedElement element = factory.createOMElement(ds);
OMCloneOptions options = new OMCloneOptions();
options.setCopyOMDataSources(copyOMDataSources);
OMElement clone = (OMElement) element.clone(options);
if (copyOMDataSources) {
assertTrue(clone instanceof OMSourcedElement);
assertFalse(element.isExpanded());
} else {
assertFalse(clone instanceof OMSourcedElement);
assertTrue(clone.isComplete());
}
assertEquals("test", clone.getText());
assertEquals("wrapper", clone.getLocalName());
}
use of org.apache.axiom.om.ds.WrappedTextNodeOMDataSourceFromDataSource in project webservices-axiom by apache.
the class TestGetTextAsStreamWithNonDestructiveOMDataSource method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
DataSource ds = new RandomDataSource(445566, 32, 128, 20000000);
QName qname = new QName("a");
Charset cs = Charset.forName("ascii");
OMSourcedElement element = factory.createOMElement(new WrappedTextNodeOMDataSourceFromDataSource(qname, ds, cs), qname);
Reader in = element.getTextAsStream(true);
assertFalse(in instanceof StringReader);
IOTestUtils.compareStreams(new InputStreamReader(ds.getInputStream(), cs), in);
assertFalse(element.isExpanded());
}
use of org.apache.axiom.om.ds.WrappedTextNodeOMDataSourceFromDataSource in project webservices-axiom by apache.
the class TestWriteTextToWithNonDestructiveOMDataSource method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
DataSource ds = new RandomDataSource(665544, 32, 128, 20000000);
QName qname = new QName("a");
OMSourcedElement element = factory.createOMElement(new WrappedTextNodeOMDataSourceFromDataSource(qname, ds, Charset.forName("ascii")), qname);
Reader in = new InputStreamReader(ds.getInputStream(), "ascii");
Writer out = new CharacterStreamComparator(in);
// cache doesn't matter here
element.writeTextTo(out, true);
out.close();
assertFalse(element.isExpanded());
}
Aggregations