use of org.apache.axiom.testutils.io.ExceptionInputStream in project webservices-axiom by apache.
the class AttachmentsTest method testIOExceptionInPartHeaders.
public void testIOExceptionInPartHeaders() throws Exception {
InputStream in = MTOMSample.SAMPLE1.getInputStream();
try {
Attachments attachments = new Attachments(new ExceptionInputStream(in, 1050), MTOMSample.SAMPLE1.getContentType());
// TODO: decide what exception should be thrown exactly here
try {
attachments.getDataHandler("1.urn:uuid:A3ADBAEE51A1A87B2A11443668160943@apache.org");
fail("Expected exception");
} catch (MIMEException ex) {
// Expected
}
} finally {
in.close();
}
}
use of org.apache.axiom.testutils.io.ExceptionInputStream in project webservices-axiom by apache.
the class AttachmentsTest method testIOExceptionInPartContent.
public void testIOExceptionInPartContent() throws Exception {
InputStream in = MTOMSample.SAMPLE1.getInputStream();
try {
Attachments attachments = new Attachments(new ExceptionInputStream(in, 1500), MTOMSample.SAMPLE1.getContentType());
DataHandler dh = attachments.getDataHandler("1.urn:uuid:A3ADBAEE51A1A87B2A11443668160943@apache.org");
// TODO: decide what exception should be thrown exactly here
try {
dh.getInputStream();
fail("Expected exception");
} catch (MIMEException ex) {
// Expected
}
} finally {
in.close();
}
}
use of org.apache.axiom.testutils.io.ExceptionInputStream in project webservices-axiom by apache.
the class TestIOExceptionInGetText method runTest.
@Override
protected void runTest() throws Throwable {
// Construct a stream that will throw an exception in the middle of a text node.
// We need to create a very large document, because some parsers (such as some
// versions of XLXP) have a large input buffer and would throw an exception already
// when the XMLStreamReader is created.
StringBuffer xml = new StringBuffer("<root>");
for (int i = 0; i < 100000; i++) {
xml.append('x');
}
InputStream in = new ExceptionInputStream(new ByteArrayInputStream(xml.toString().getBytes("ASCII")));
XMLStreamReader originalReader = StAXUtils.createXMLStreamReader(in);
InvocationCounter invocationCounter = new InvocationCounter();
XMLStreamReader reader = (XMLStreamReader) invocationCounter.createProxy(originalReader);
OMElement element = OMXMLBuilderFactory.createStAXOMBuilder(metaFactory.getOMFactory(), reader).getDocumentElement();
try {
element.getNextOMSibling();
fail("Expected exception");
} catch (Exception ex) {
// Expected
}
assertTrue(invocationCounter.getInvocationCount() > 0);
invocationCounter.reset();
try {
element.getNextOMSibling();
fail("Expected exception");
} catch (Exception ex) {
// Expected
}
assertEquals(0, invocationCounter.getInvocationCount());
}
use of org.apache.axiom.testutils.io.ExceptionInputStream in project webservices-axiom by apache.
the class TestReadFromWithError method runTest.
@Override
protected void runTest(WritableBlob blob) throws Throwable {
ExceptionInputStream in = new ExceptionInputStream(new NullInputStream(1000), 500);
try {
blob.readFrom(in);
fail("Expected StreamCopyException");
} catch (StreamCopyException ex) {
assertThat(ex.getOperation()).isEqualTo(StreamCopyException.READ);
assertThat(ex.getCause()).isSameAs(in.getException());
}
}
Aggregations