use of org.apache.axiom.testutils.activation.RandomDataSource in project webservices-axiom by apache.
the class TestGetTextAsStreamWithoutCaching method runTest.
@Override
protected void runTest() throws Throwable {
Charset charset = Charset.forName("ascii");
OMFactory factory = metaFactory.getOMFactory();
DataSource ds = new RandomDataSource(654321, 64, 128, 20000000);
Vector<InputStream> v = new Vector<InputStream>();
v.add(new ByteArrayInputStream("<root><a>".getBytes(charset)));
v.add(ds.getInputStream());
v.add(new ByteArrayInputStream("</a><b/></root>".getBytes(charset)));
OMElement root = OMXMLBuilderFactory.createOMBuilder(factory, StAXParserConfiguration.NON_COALESCING, new SequenceInputStream(v.elements()), "ascii").getDocumentElement();
OMElement child = (OMElement) root.getFirstOMChild();
Reader in = child.getTextAsStream(false);
IOTestUtils.compareStreams(new InputStreamReader(ds.getInputStream(), charset), "expected", in, "actual");
in.close();
// No try to access subsequent nodes
child = (OMElement) child.getNextOMSibling();
assertThat(child.getLocalName()).isEqualTo("b");
}
use of org.apache.axiom.testutils.activation.RandomDataSource in project webservices-axiom by apache.
the class TestGetTextBinary method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
DataSource ds = new RandomDataSource(99999, 1000);
OMElement element = factory.createOMElement("elem", null);
element.addChild(factory.createOMText(new DataHandler(ds), false));
if (compact) {
// Only the builder can create a compact element containing a DataHandler
element = OMXMLBuilderFactory.createStAXOMBuilder(factory, element.getXMLStreamReader()).getDocumentElement();
element.build();
}
IOTestUtils.compareStreams(ds.getInputStream(), new ByteArrayInputStream(Base64.decodeBase64(element.getText())));
}
use of org.apache.axiom.testutils.activation.RandomDataSource 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.testutils.activation.RandomDataSource in project webservices-axiom by apache.
the class TestCloneBinary method runTest.
@Override
protected void runTest() throws Throwable {
DataHandler dh = new DataHandler(new RandomDataSource(600613L, 4096));
StringReader rootPart = new StringReader("<root><xop:Include xmlns:xop='http://www.w3.org/2004/08/xop/include' href='cid:123456@example.org'/></root>");
DummyAttachmentAccessor attachmentAccessor = new DummyAttachmentAccessor("123456@example.org", dh);
OMElement root = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StreamSource(rootPart), attachmentAccessor).getDocumentElement();
OMText text = (OMText) root.getFirstOMChild();
OMCloneOptions options = new OMCloneOptions();
options.setFetchDataHandlers(fetch);
OMText clone = (OMText) text.clone(options);
assertTrue(clone.isBinary());
assertEquals(fetch, attachmentAccessor.isLoaded());
assertSame(dh, clone.getDataHandler());
}
use of org.apache.axiom.testutils.activation.RandomDataSource 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