use of com.linkedin.multipart.utils.MIMEDataPart in project rest.li by linkedin.
the class TestMIMEIntegrationReaderWriter method executeRequestAndAssert.
// /////////////////////////////////////////////////////////////////////////////////////
// This method will execute a StreamRequest using a payload comprised of the provided MultiPartMIMEWriter. The request
// makes its way to a server which will read all the parts one by one and store them in a list. Subsequently,
// an assertion is performed to make sure that each part was read and saved properly on the server.
private void executeRequestAndAssert(final MultiPartMIMEWriter requestWriter, final List<MIMEDataPart> expectedParts) throws Exception {
final StreamRequest streamRequest = MultiPartMIMEStreamRequestFactory.generateMultiPartMIMEStreamRequest(Bootstrap.createHttpURI(PORT, SERVER_URI), "mixed", requestWriter, Collections.<String, String>emptyMap());
final AtomicInteger status = new AtomicInteger(-1);
final CountDownLatch latch = new CountDownLatch(1);
Callback<StreamResponse> callback = expectSuccessCallback(latch, status, new HashMap<>());
_client.streamRequest(streamRequest, callback);
latch.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS);
Assert.assertEquals(status.get(), RestStatus.OK);
List<SinglePartMIMEReaderCallbackImpl> singlePartMIMEReaderCallbacks = _mimeServerRequestHandler.getTestMultiPartMIMEReaderCallback().getSinglePartMIMEReaderCallbacks();
_mimeServerRequestHandler.getTestMultiPartMIMEReaderCallback().getSinglePartMIMEReaderCallbacks();
Assert.assertEquals(singlePartMIMEReaderCallbacks.size(), expectedParts.size());
for (int i = 0; i < singlePartMIMEReaderCallbacks.size(); i++) {
// Actual
final SinglePartMIMEReaderCallbackImpl currentCallback = singlePartMIMEReaderCallbacks.get(i);
// Expected
final MIMEDataPart currentExpectedPart = expectedParts.get(i);
Assert.assertEquals(currentCallback.getHeaders(), currentExpectedPart.getPartHeaders());
Assert.assertEquals(currentCallback.getFinishedData(), currentExpectedPart.getPartData());
}
}
Aggregations