use of org.apache.axiom.testutils.activation.RandomDataSource in project webservices-axiom by apache.
the class TestBase64StreamingWithGetSAXSource method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement elem = factory.createOMElement("test", null);
// Create a data source that would eat up all memory when loaded. If the test
// doesn't fail with an OutOfMemoryError, we know that the OMText implementation
// supports streaming.
DataSource ds = new RandomDataSource(654321L, Runtime.getRuntime().maxMemory());
OMText text = factory.createOMText(new DataHandler(ds), false);
elem.addChild(text);
SAXSource saxSource = elem.getSAXSource(true);
XMLReader xmlReader = saxSource.getXMLReader();
xmlReader.setContentHandler(new Base64Comparator(ds.getInputStream()));
xmlReader.parse(saxSource.getInputSource());
}
use of org.apache.axiom.testutils.activation.RandomDataSource in project webservices-axiom by apache.
the class TestRegisterCustomBuilderForPayloadJAXBPlain method runTest.
@Override
protected void runTest() throws Throwable {
DataHandler dh = new DataHandler(new RandomDataSource(10000));
MemoryBlob blob = Blobs.createMemoryBlob();
OutputStream out = blob.getOutputStream();
createTestDocument(dh).serialize(out);
out.close();
test(dh, OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), blob.getInputStream()), false);
}
use of org.apache.axiom.testutils.activation.RandomDataSource in project webservices-axiom by apache.
the class TestRegisterCustomBuilderForPayloadJAXBWithXOP method runTest.
@Override
protected void runTest() throws Throwable {
DataHandler dh = new DataHandler(new RandomDataSource(10000));
MemoryBlob blob = Blobs.createMemoryBlob();
OutputStream out = blob.getOutputStream();
OMOutputFormat format = new OMOutputFormat();
format.setDoOptimize(true);
createTestDocument(dh).serialize(out, format);
out.close();
MultipartBody mb = MultipartBody.builder().setInputStream(blob.getInputStream()).setContentType(format.getContentType()).build();
test(dh, OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), StAXParserConfiguration.DEFAULT, mb), false);
}
use of org.apache.axiom.testutils.activation.RandomDataSource in project webservices-axiom by apache.
the class TestGetDataHandlerFromElement method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
RandomDataSource orgDS = new RandomDataSource(64 * 1024);
OMElement orgRoot = factory.createOMElement(new QName("root"));
OMElement orgChild = factory.createOMElement(new QName("child"), orgRoot);
orgChild.addChild(factory.createOMText(new DataHandler(orgDS), false));
OMElement root = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader(orgRoot.toString())).getDocumentElement();
XMLStreamReader reader = root.getXMLStreamReader(cache);
assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
DataSource ds = XMLStreamReaderUtils.getDataHandlerFromElement(reader).getDataSource();
IOTestUtils.compareStreams(orgDS.getInputStream(), ds.getInputStream());
}
use of org.apache.axiom.testutils.activation.RandomDataSource in project webservices-axiom by apache.
the class TestReadAttachmentBeforeRootPartComplete method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
// Programmatically create the message
OMElement orgRoot = factory.createOMElement("root", null);
OMElement orgChild1 = factory.createOMElement("child1", null, orgRoot);
DataSource ds = new RandomDataSource(54321, 4096);
orgChild1.addChild(factory.createOMText(new DataHandler(ds), true));
// Create a child with a large text content and insert it after the binary node.
// If we don't do this, then the root part may be buffered entirely by the parser,
// and the test would not be effective.
OMElement orgChild2 = factory.createOMElement("child2", null, orgRoot);
String s = RandomUtils.randomString(128 * 1024);
orgChild2.setText(s);
// Serialize the message
OMOutputFormat format = new OMOutputFormat();
format.setDoOptimize(true);
MemoryBlob blob = Blobs.createMemoryBlob();
OutputStream out = blob.getOutputStream();
orgRoot.serialize(out, format);
out.close();
// Parse the message
OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(factory, StAXParserConfiguration.NON_COALESCING, MultipartBody.builder().setInputStream(blob.getInputStream()).setContentType(format.getContentType()).build());
OMElement root = builder.getDocumentElement();
OMElement child1 = (OMElement) root.getFirstOMChild();
OMText text = (OMText) child1.getFirstOMChild();
assertTrue(text.isBinary());
// Access the DataHandler
DataHandler dh = text.getDataHandler();
IOTestUtils.compareStreams(ds.getInputStream(), dh.getInputStream());
OMElement child2 = (OMElement) child1.getNextOMSibling();
assertFalse(child2.isComplete());
assertEquals(s, child2.getText());
}
Aggregations