use of com.linkedin.restli.server.twitter.FeedDownloadResource in project rest.li by linkedin.
the class TestRestLiServer method testValidUnstructuredDataRequestMissingHeader.
@Test(dataProvider = "validClientProtocolVersionDataStreamOnly")
public void testValidUnstructuredDataRequestMissingHeader(RestLiServer server, ProtocolVersion clientProtocolVersion, String headerConstant) throws URISyntaxException, IOException {
StreamRequest streamRequest = new StreamRequestBuilder(new URI("/feedDownloads/1")).setHeader(headerConstant, clientProtocolVersion.toString()).build(EntityStreams.emptyStream());
final FeedDownloadResource resource = getMockResource(FeedDownloadResource.class);
resource.get(eq(1L), anyObject(UnstructuredDataWriter.class));
EasyMock.expectLastCall().andDelegateTo(new FeedDownloadResource() {
@Override
public void get(Long key, UnstructuredDataWriter writer) {
// do nothing here, this should cause error
}
}).once();
replay(resource);
@SuppressWarnings("unchecked") Callback<StreamResponse> r2Callback = createMock(Callback.class);
r2Callback.onError(anyObject());
expectLastCall().once();
replay(r2Callback);
RequestContext requestContext = new RequestContext();
server.handleRequest(streamRequest, requestContext, r2Callback);
verify(resource);
verify(r2Callback);
}
use of com.linkedin.restli.server.twitter.FeedDownloadResource in project rest.li by linkedin.
the class TestRestLiServer method testValidUnstructuredDataRequest.
@Test(dataProvider = "validClientProtocolVersionDataStreamOnly")
public void testValidUnstructuredDataRequest(RestLiServer server, ProtocolVersion clientProtocolVersion, String headerConstant) throws URISyntaxException, IOException {
StreamRequest streamRequest = new StreamRequestBuilder(new URI("/feedDownloads/1")).setHeader(headerConstant, clientProtocolVersion.toString()).build(EntityStreams.emptyStream());
final FeedDownloadResource resource = getMockResource(FeedDownloadResource.class);
resource.get(eq(1L), anyObject(UnstructuredDataWriter.class));
EasyMock.expectLastCall().andDelegateTo(new FeedDownloadResource()).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), FeedDownloadResource.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.copyBytes(), FeedDownloadResource.CONTENT);
}
});
streamResponse.getValue().getEntityStream().setReader(fullEntityReader);
}
Aggregations