use of com.linkedin.restli.server.twitter.FeedDownloadResourceReactive in project rest.li by linkedin.
the class TestRestLiServer method testValidReactiveUnstructuredDataRequest.
@Test(dataProvider = "validClientProtocolVersionDataStreamOnly")
public void testValidReactiveUnstructuredDataRequest(RestLiServer server, ProtocolVersion clientProtocolVersion, String headerConstant) throws URISyntaxException, IOException {
StreamRequest streamRequest = new StreamRequestBuilder(new URI("/reactiveFeedDownloads/1")).setHeader(headerConstant, clientProtocolVersion.toString()).build(EntityStreams.emptyStream());
final FeedDownloadResourceReactive resource = getMockResource(FeedDownloadResourceReactive.class);
resource.get(eq(1L), anyObject());
EasyMock.expectLastCall().andDelegateTo(new FeedDownloadResourceReactive()).once();
replay(resource);
@SuppressWarnings("unchecked") Callback<StreamResponse> r2Callback = createMock(Callback.class);
final Capture<StreamResponse> streamResponse = EasyMock.newCapture();
r2Callback.onSuccess(capture(streamResponse));
expectLastCall().once();
replay(r2Callback);
RequestContext requestContext = new RequestContext();
server.handleRequest(streamRequest, requestContext, r2Callback);
verify(resource);
verify(r2Callback);
assertNotNull(streamResponse);
assertEquals(streamResponse.getValue().getHeader(RestConstants.HEADER_CONTENT_TYPE), FeedDownloadResourceReactive.CONTENT_TYPE);
FullEntityReader fullEntityReader = new FullEntityReader(new Callback<ByteString>() {
@Override
public void onError(Throwable e) {
fail("Error inside callback!! Failed to read response data from stream!", e);
}
@Override
public void onSuccess(ByteString result) {
assertEquals(result, FeedDownloadResourceReactive.CONTENT);
}
});
streamResponse.getValue().getEntityStream().setReader(fullEntityReader);
}
Aggregations