use of javax.activation.DataHandler in project webservices-axiom by apache.
the class AttachmentsTest method testRemoveDataHandlerNonExistingWithoutStream.
/**
* Tests that {@link Attachments#removeDataHandler(String)} returns silently if no data handler
* with the given content ID has been added to the object.
*/
public void testRemoveDataHandlerNonExistingWithoutStream() {
Attachments attachments = new Attachments();
attachments.addDataHandler("id@apache.org", new DataHandler("test", "text/plain"));
attachments.removeDataHandler("non-existing@apache.org");
assertEquals(1, attachments.getContentIDSet().size());
}
use of javax.activation.DataHandler in project webservices-axiom by apache.
the class AttachmentsTest method testGetAllContentIDsWithoutStream.
public void testGetAllContentIDsWithoutStream() {
Attachments attachments = new Attachments();
// The choice of content IDs here makes sure that we test that the attachments are returned
// in the order in which they have been added (instead of sorted by content ID as in
// earlier Axiom versions)
attachments.addDataHandler("contentB@apache.org", new DataHandler("content1", "text/plain"));
attachments.addDataHandler("contentA@apache.org", new DataHandler("content2", "text/plain"));
String[] contentIDs = attachments.getAllContentIDs();
assertEquals(2, contentIDs.length);
assertEquals("contentB@apache.org", contentIDs[0]);
assertEquals("contentA@apache.org", contentIDs[1]);
}
use of javax.activation.DataHandler in project webservices-axiom by apache.
the class AttachmentsTest method testZeroLengthAttachment.
/**
* Tests that {@link Attachments} can successfully read an attachment with zero length. This is
* a regression test for
* <a href="https://issues.apache.org/jira/browse/AXIOM-383">AXIOM-383</a>.
*
* @throws Exception
*/
public void testZeroLengthAttachment() throws Exception {
InputStream in = getTestResource("mtom/zero-length-attachment.bin");
try {
Attachments attachments = new Attachments(in, "multipart/related; " + "boundary=MIMEBoundaryurn_uuid_0549F3F826EC3041861188639371825; " + "type=\"application/xop+xml\"; " + "start=\"0.urn:uuid:0549F3F826EC3041861188639371826@apache.org\"; " + "start-info=\"application/soap+xml\"; action=\"urn:test\"");
DataHandler dh = attachments.getDataHandler("1.urn:uuid:0549F3F826EC3041861188639371827@apache.org");
InputStream content = dh.getInputStream();
assertEquals(-1, content.read());
} finally {
in.close();
}
}
use of javax.activation.DataHandler 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 javax.activation.DataHandler 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);
}
Aggregations