use of javax.mail.internet.MimeBodyPart in project rest.li by linkedin.
the class TestMIMEIntegrationReaderDrain method testSingleAlternate.
@Test(dataProvider = "allTypesOfBodiesDataSource")
public void testSingleAlternate(final int chunkSize, final List<MimeBodyPart> bodyPartList) throws Exception {
//Execute the request, verify the correct header came back to ensure the server took the proper draining actions
//and return the payload so we can assert deeper.
MimeMultipart mimeMultipart = executeRequestWithDrainStrategy(chunkSize, bodyPartList, SINGLE_ALTERNATE, "onFinished");
//Single part alternates between consumption and draining for all 12 parts.
//This means that parts 0, 2, 4, etc.. will be consumed and parts 1, 3, 5, etc... will be drained.
List<SinglePartMIMEDrainReaderCallbackImpl> singlePartMIMEReaderCallbacks = _mimeServerRequestDrainHandler.getTestMultiPartMIMEReaderCallback().getSinglePartMIMEReaderCallbacks();
Assert.assertEquals(singlePartMIMEReaderCallbacks.size(), 12);
//First the consumed
for (int i = 0; i < singlePartMIMEReaderCallbacks.size(); i = i + 2) {
//Actual
final SinglePartMIMEDrainReaderCallbackImpl currentCallback = singlePartMIMEReaderCallbacks.get(i);
//Expected
final BodyPart currentExpectedPart = mimeMultipart.getBodyPart(i);
//Construct expected headers and verify they match
final Map<String, String> expectedHeaders = new HashMap<String, String>();
@SuppressWarnings("unchecked") final Enumeration<Header> allHeaders = currentExpectedPart.getAllHeaders();
while (allHeaders.hasMoreElements()) {
final Header header = allHeaders.nextElement();
expectedHeaders.put(header.getName(), header.getValue());
}
Assert.assertEquals(currentCallback._headers, expectedHeaders);
//Verify the body matches
if (currentExpectedPart.getContent() instanceof byte[]) {
Assert.assertEquals(currentCallback._finishedData.copyBytes(), currentExpectedPart.getContent());
} else {
//Default is String
Assert.assertEquals(new String(currentCallback._finishedData.copyBytes()), currentExpectedPart.getContent());
}
}
//Then the drained
for (int i = 1; i < singlePartMIMEReaderCallbacks.size(); i = i + 2) {
//Actual
final SinglePartMIMEDrainReaderCallbackImpl currentCallback = singlePartMIMEReaderCallbacks.get(i);
//Expected
final BodyPart currentExpectedPart = mimeMultipart.getBodyPart(i);
//Construct expected headers and verify they match
final Map<String, String> expectedHeaders = new HashMap<String, String>();
@SuppressWarnings("unchecked") final Enumeration<Header> allHeaders = currentExpectedPart.getAllHeaders();
while (allHeaders.hasMoreElements()) {
final Header header = allHeaders.nextElement();
expectedHeaders.put(header.getName(), header.getValue());
}
Assert.assertEquals(currentCallback._headers, expectedHeaders);
//Verify that the bodies are empty
Assert.assertEquals(currentCallback._finishedData, ByteString.empty());
}
}
use of javax.mail.internet.MimeBodyPart in project rest.li by linkedin.
the class MIMETestUtils method createSmallDataSource.
private static final MimeBodyPart createSmallDataSource() {
try {
//Small body.
final String body = "A small body";
final MimeBodyPart dataPart = new MimeBodyPart();
final ContentType contentType = new ContentType(TEXT_PLAIN_CONTENT_TYPE);
dataPart.setContent(body, contentType.getBaseType());
dataPart.setHeader(HEADER_CONTENT_TYPE, contentType.toString());
dataPart.setHeader("SomeCustomHeader", "SomeCustomValue");
return dataPart;
} catch (Exception exception) {
Assert.fail();
}
return null;
}
use of javax.mail.internet.MimeBodyPart in project rest.li by linkedin.
the class MIMETestUtils method createBodyLessBody.
private static final MimeBodyPart createBodyLessBody() {
try {
//Body-less body. This has no body but does have headers, some of which are folded.
final MimeBodyPart dataPart = new MimeBodyPart();
final ParameterList parameterList = new ParameterList();
parameterList.set("AVeryVeryVeryVeryLongHeader", "AVeryVeryVeryVeryLongValue");
parameterList.set("AVeryVeryVeryVeryLongHeader2", "AVeryVeryVeryVeryLongValue2");
parameterList.set("AVeryVeryVeryVeryLongHeader3", "AVeryVeryVeryVeryLongValue3");
parameterList.set("AVeryVeryVeryVeryLongHeader4", "AVeryVeryVeryVeryLongValue4");
final ContentType contentType = new ContentType("text", "plain", parameterList);
dataPart.setContent("", contentType.getBaseType());
dataPart.setHeader(HEADER_CONTENT_TYPE, contentType.toString());
dataPart.setHeader("YetAnotherCustomHeader", "YetAnotherCustomValue");
return dataPart;
} catch (Exception exception) {
Assert.fail();
}
return null;
}
use of javax.mail.internet.MimeBodyPart in project rest.li by linkedin.
the class MIMETestUtils method createBytesBody.
private static final MimeBodyPart createBytesBody() {
try {
//Bytes body. A body that uses a content type different then just text/plain.
final byte[] body = new byte[20];
for (int i = 0; i < body.length; i++) {
body[i] = (byte) i;
}
final MimeBodyPart dataPart = new MimeBodyPart();
final ContentType contentType = new ContentType(BINARY_CONTENT_TYPE);
dataPart.setContent(body, contentType.getBaseType());
dataPart.setHeader(HEADER_CONTENT_TYPE, contentType.toString());
return dataPart;
} catch (Exception exception) {
Assert.fail();
}
return null;
}
use of javax.mail.internet.MimeBodyPart in project rest.li by linkedin.
the class MIMETestUtils method createPurelyEmptyBody.
private static final MimeBodyPart createPurelyEmptyBody() {
try {
//Purely empty body. This has no body or headers.
final MimeBodyPart dataPart = new MimeBodyPart();
final ContentType contentType = new ContentType(TEXT_PLAIN_CONTENT_TYPE);
//Mail requires content so we do a bit of a hack here.
dataPart.setContent("", contentType.getBaseType());
return dataPart;
} catch (Exception exception) {
Assert.fail();
}
return null;
}
Aggregations