Search in sources :

Example 1 with FeedDownloadResource

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);
}
Also used : StreamResponse(com.linkedin.r2.message.stream.StreamResponse) FilterRequestContext(com.linkedin.restli.server.filter.FilterRequestContext) RequestContext(com.linkedin.r2.message.RequestContext) StreamRequestBuilder(com.linkedin.r2.message.stream.StreamRequestBuilder) URI(java.net.URI) FeedDownloadResource(com.linkedin.restli.server.twitter.FeedDownloadResource) StreamRequest(com.linkedin.r2.message.stream.StreamRequest) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 2 with FeedDownloadResource

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);
}
Also used : ByteString(com.linkedin.data.ByteString) StreamResponse(com.linkedin.r2.message.stream.StreamResponse) StreamRequestBuilder(com.linkedin.r2.message.stream.StreamRequestBuilder) URI(java.net.URI) FeedDownloadResource(com.linkedin.restli.server.twitter.FeedDownloadResource) StreamRequest(com.linkedin.r2.message.stream.StreamRequest) FullEntityReader(com.linkedin.r2.message.stream.entitystream.FullEntityReader) FilterRequestContext(com.linkedin.restli.server.filter.FilterRequestContext) RequestContext(com.linkedin.r2.message.RequestContext) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

RequestContext (com.linkedin.r2.message.RequestContext)2 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)2 StreamRequestBuilder (com.linkedin.r2.message.stream.StreamRequestBuilder)2 StreamResponse (com.linkedin.r2.message.stream.StreamResponse)2 FilterRequestContext (com.linkedin.restli.server.filter.FilterRequestContext)2 FeedDownloadResource (com.linkedin.restli.server.twitter.FeedDownloadResource)2 URI (java.net.URI)2 AfterTest (org.testng.annotations.AfterTest)2 BeforeTest (org.testng.annotations.BeforeTest)2 Test (org.testng.annotations.Test)2 ByteString (com.linkedin.data.ByteString)1 FullEntityReader (com.linkedin.r2.message.stream.entitystream.FullEntityReader)1