use of org.apache.axiom.testutils.io.InstrumentedInputStream in project webservices-axiom by apache.
the class TestBuilderDetach method runTest.
@Override
protected void runTest() throws Throwable {
MTOMSample sample = MTOMSample.SAMPLE1;
InstrumentedInputStream in = new InstrumentedInputStream(sample.getInputStream());
MultipartBody mb = MultipartBody.builder().setInputStream(in).setContentType(sample.getContentType()).build();
SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, mb);
SOAPEnvelope envelope = builder.getSOAPEnvelope();
long countBeforeDetach = in.getCount();
builder.detach();
assertThat(in.getCount()).isGreaterThan(countBeforeDetach);
assertThat(in.isClosed()).isFalse();
int binaryCount = 0;
for (Iterator<OMNode> it = envelope.getDescendants(false); it.hasNext(); ) {
OMNode node = it.next();
if (node instanceof OMText) {
OMText text = (OMText) node;
if (text.isBinary()) {
IOTestUtils.compareStreams(sample.getPart(text.getContentID()), text.getDataHandler().getInputStream());
binaryCount++;
}
}
}
assertThat(binaryCount).isGreaterThan(0);
in.close();
}
use of org.apache.axiom.testutils.io.InstrumentedInputStream in project webservices-axiom by apache.
the class TestBuild method runTest.
@Override
protected void runTest() throws Throwable {
InstrumentedInputStream in = new InstrumentedInputStream(XMLSample.LARGE.getInputStream());
OMDocument doc = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), in).getDocument();
assertFalse(doc.isComplete());
long countBeforeBuild = in.getCount();
doc.build();
assertTrue(doc.isComplete());
long countAfterBuild = in.getCount();
assertTrue(countAfterBuild > countBeforeBuild);
OMNode node = doc.getFirstOMChild();
while (node != null) {
node = node.getNextOMSibling();
}
assertEquals(countAfterBuild, in.getCount());
}
use of org.apache.axiom.testutils.io.InstrumentedInputStream in project webservices-axiom by apache.
the class TestRootPartStreaming method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
// Programmatically create the message
OMElement orgRoot = factory.createOMElement("root", null);
for (int i = 0; i < 10000; i++) {
factory.createOMElement("child", null, orgRoot).setText("Some text content");
}
// Serialize the message as XOP even if there will be no attachment parts
OMOutputFormat format = new OMOutputFormat();
format.setDoOptimize(true);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
orgRoot.serialize(baos, format);
// Parse the message and monitor the number of bytes read
InstrumentedInputStream in = new InstrumentedInputStream(new ByteArrayInputStream(baos.toByteArray()));
OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(factory, StAXParserConfiguration.DEFAULT, MultipartBody.builder().setInputStream(in).setContentType(format.getContentType()).build());
OMElement root = builder.getDocumentElement();
long count1 = in.getCount();
XMLStreamReader reader = root.getXMLStreamReader(false);
while (reader.hasNext()) {
reader.next();
}
long count2 = in.getCount();
// We expect that after requesting the document element, only a small part (corresponding to
// the size of the parser buffer) should have been read:
assertTrue(count1 < count2 / 2);
}
use of org.apache.axiom.testutils.io.InstrumentedInputStream in project webservices-axiom by apache.
the class TestReadFrom method runTest.
@Override
protected void runTest(WritableBlob blob) throws Throwable {
Random random = new Random();
byte[] data = new byte[size];
random.nextBytes(data);
InstrumentedInputStream in = new InstrumentedInputStream(new ByteArrayInputStream(data));
assertThat(blob.readFrom(in)).isEqualTo(size);
assertThat(in.isClosed()).isFalse();
InputStream in2 = blob.getInputStream();
try {
assertThat(IOUtils.toByteArray(in2)).isEqualTo(data);
} finally {
in2.close();
}
}
use of org.apache.axiom.testutils.io.InstrumentedInputStream in project webservices-axiom by apache.
the class TestCloseWithoutCaching method runTest.
@Override
protected void runTest() throws Throwable {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Writer writer = new OutputStreamWriter(baos, "UTF-8");
writer.write("<root><a>");
for (int i = 0; i < 20000; i++) {
writer.write('a');
}
writer.write("</a></root>");
writer.close();
InstrumentedInputStream in = new InstrumentedInputStream(new ByteArrayInputStream(baos.toByteArray()));
OMDocument doc = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), in).getDocument();
XMLStreamReader reader = doc.getXMLStreamReaderWithoutCaching();
reader.next();
reader.next();
long count = in.getCount();
reader.close();
assertEquals(count, in.getCount());
}
Aggregations