Search in sources :

Example 21 with RestLiCallback

use of com.linkedin.restli.internal.server.RestLiCallback in project rest.li by linkedin.

the class TestRestLiMethodInvocation method testAsyncBatchUpdateComplexKeyResource.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "asyncBatchUpdateComplexKey")
public void testAsyncBatchUpdateComplexKeyResource(ProtocolVersion version, String uri, String body) throws Exception {
    ResourceModel discoveredResourceModel = buildResourceModel(AsyncDiscoveredItemsResource.class);
    RestLiCallback<?> callback = getCallback();
    ResourceMethodDescriptor methodDescriptor;
    AsyncDiscoveredItemsResource discoveredResource;
    methodDescriptor = discoveredResourceModel.findMethod(ResourceMethod.BATCH_UPDATE);
    discoveredResource = getMockResource(AsyncDiscoveredItemsResource.class);
    @SuppressWarnings("unchecked") BatchUpdateRequest<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem> mockBatchUpdateReq = (BatchUpdateRequest<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>) EasyMock.anyObject();
    discoveredResource.batchUpdate(mockBatchUpdateReq, EasyMock.<Callback<BatchUpdateResult<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>>>anyObject());
    EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {

        @Override
        public Object answer() throws Throwable {
            @SuppressWarnings("unchecked") Callback<BatchUpdateResult<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>> callback = (Callback<BatchUpdateResult<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>>) EasyMock.getCurrentArguments()[1];
            callback.onSuccess(null);
            return null;
        }
    });
    EasyMock.replay(discoveredResource);
    checkAsyncInvocation(discoveredResource, callback, methodDescriptor, "PUT", version, uri, body, buildBatchPathKeys(getDiscoveredItemComplexKey(1, 1, 1), getDiscoveredItemComplexKey(2, 2, 2), getDiscoveredItemComplexKey(3, 3, 3)));
}
Also used : AsyncDiscoveredItemsResource(com.linkedin.restli.server.twitter.AsyncDiscoveredItemsResource) BatchUpdateRequest(com.linkedin.restli.server.BatchUpdateRequest) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) Callback(com.linkedin.common.callback.Callback) RestLiCallback(com.linkedin.restli.internal.server.RestLiCallback) FilterChainCallback(com.linkedin.restli.internal.server.filter.FilterChainCallback) RequestExecutionCallback(com.linkedin.restli.server.RequestExecutionCallback) DiscoveredItemKeyParams(com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItemKeyParams) BatchUpdateResult(com.linkedin.restli.server.BatchUpdateResult) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) DiscoveredItem(com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItem) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiTestHelper.buildResourceModel(com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel) EasyMock.anyObject(org.easymock.EasyMock.anyObject) DiscoveredItemKey(com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItemKey) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 22 with RestLiCallback

use of com.linkedin.restli.internal.server.RestLiCallback in project rest.li by linkedin.

the class TestRestLiMethodInvocation method testInvokeWithInvalidAcceptMimeType.

@Test
public void testInvokeWithInvalidAcceptMimeType() throws Exception {
    RestRequestBuilder builder = new RestRequestBuilder(new URI("")).addHeaderValue("Accept", "foo").setHeader(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, version.toString());
    RestRequest request = builder.build();
    final CountDownLatch latch = new CountDownLatch(1);
    RestLiResponseHandler restLiResponseHandler = new RestLiResponseHandler.Builder().build();
    RequestExecutionCallback<RestResponse> executionCallback = new RequestExecutionCallback<RestResponse>() {

        @Override
        public void onError(Throwable e, RequestExecutionReport executionReport, RestLiAttachmentReader requestAttachmentReader, RestLiResponseAttachments responseAttachments) {
            latch.countDown();
            Assert.assertTrue(e instanceof RestException);
            RestException ex = (RestException) e;
            Assert.assertEquals(ex.getResponse().getStatus(), HttpStatus.S_400_BAD_REQUEST.getCode());
        }

        @Override
        public void onSuccess(RestResponse result, RequestExecutionReport executionReport, RestLiResponseAttachments responseAttachments) {
        }
    };
    ServerResourceContext context = new ResourceContextImpl();
    try {
        RoutingResult routingResult = new RoutingResult(context, null);
        RestUtils.validateRequestHeadersAndUpdateResourceContext(request.getHeaders(), (ServerResourceContext) routingResult.getContext());
        FilterChainCallback filterChainCallback = new FilterChainCallbackImpl(null, _invoker, null, null, null, restLiResponseHandler, executionCallback);
        final RestLiCallback<Object> callback = new RestLiCallback<Object>(null, new RestLiFilterResponseContextFactory<Object>(request, null, restLiResponseHandler), new RestLiFilterChain(null, filterChainCallback));
        _invoker.invoke(null, routingResult, null, callback, null);
        latch.await();
    } catch (Exception e) {
        // exception is expected
        Assert.assertTrue(e instanceof RestLiServiceException);
    }
    Assert.assertNull(context.getResponseMimeType());
}
Also used : URI(java.net.URI) RestLiFilterChain(com.linkedin.restli.internal.server.filter.RestLiFilterChain) RequestExecutionCallback(com.linkedin.restli.server.RequestExecutionCallback) RoutingResult(com.linkedin.restli.internal.server.RoutingResult) FilterChainCallback(com.linkedin.restli.internal.server.filter.FilterChainCallback) RestLiResponseHandler(com.linkedin.restli.internal.server.response.RestLiResponseHandler) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) FilterChainCallbackImpl(com.linkedin.restli.internal.server.filter.FilterChainCallbackImpl) RestLiCallback(com.linkedin.restli.internal.server.RestLiCallback) RestLiResponseAttachments(com.linkedin.restli.server.RestLiResponseAttachments) ResourceContextImpl(com.linkedin.restli.internal.server.ResourceContextImpl) RestResponse(com.linkedin.r2.message.rest.RestResponse) RestException(com.linkedin.r2.message.rest.RestException) CountDownLatch(java.util.concurrent.CountDownLatch) RequestExecutionReport(com.linkedin.restli.server.RequestExecutionReport) RestException(com.linkedin.r2.message.rest.RestException) URISyntaxException(java.net.URISyntaxException) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) RoutingException(com.linkedin.restli.server.RoutingException) RestLiSyntaxException(com.linkedin.restli.internal.server.util.RestLiSyntaxException) RestRequest(com.linkedin.r2.message.rest.RestRequest) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) EasyMock.anyObject(org.easymock.EasyMock.anyObject) RestLiAttachmentReader(com.linkedin.restli.common.attachments.RestLiAttachmentReader) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 23 with RestLiCallback

use of com.linkedin.restli.internal.server.RestLiCallback in project rest.li by linkedin.

the class TestRestLiMethodInvocation method testAsyncBatchDeleteComplexResource.

@Test
public void testAsyncBatchDeleteComplexResource() throws Exception {
    ResourceModel discoveredResourceModel = buildResourceModel(AsyncDiscoveredItemsResource.class);
    RestLiCallback<?> callback = getCallback();
    ResourceMethodDescriptor methodDescriptor;
    AsyncDiscoveredItemsResource discoveredResource;
    methodDescriptor = discoveredResourceModel.findMethod(ResourceMethod.BATCH_DELETE);
    discoveredResource = getMockResource(AsyncDiscoveredItemsResource.class);
    @SuppressWarnings("unchecked") BatchDeleteRequest<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem> mockBatchDeleteReq = (BatchDeleteRequest<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>) EasyMock.anyObject();
    discoveredResource.batchDelete(mockBatchDeleteReq, EasyMock.<Callback<BatchUpdateResult<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>>>anyObject());
    EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {

        @Override
        public Object answer() throws Throwable {
            @SuppressWarnings("unchecked") Callback<BatchUpdateResult<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>> callback = (Callback<BatchUpdateResult<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>>) EasyMock.getCurrentArguments()[1];
            callback.onSuccess(null);
            return null;
        }
    });
    EasyMock.replay(discoveredResource);
    String uri = "/asyncdiscovereditems?ids=List((itemId:1,type:1,userId:1),(itemId:2,type:2,userId:2),(itemId:3,type:3,userId:3))";
    checkAsyncInvocation(discoveredResource, callback, methodDescriptor, "DELETE", version, uri, buildBatchPathKeys(getDiscoveredItemComplexKey(1, 1, 1), getDiscoveredItemComplexKey(2, 2, 2), getDiscoveredItemComplexKey(3, 3, 3)));
}
Also used : AsyncDiscoveredItemsResource(com.linkedin.restli.server.twitter.AsyncDiscoveredItemsResource) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ByteString(com.linkedin.data.ByteString) CustomString(com.linkedin.restli.server.custom.types.CustomString) Callback(com.linkedin.common.callback.Callback) RestLiCallback(com.linkedin.restli.internal.server.RestLiCallback) FilterChainCallback(com.linkedin.restli.internal.server.filter.FilterChainCallback) RequestExecutionCallback(com.linkedin.restli.server.RequestExecutionCallback) DiscoveredItemKeyParams(com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItemKeyParams) BatchUpdateResult(com.linkedin.restli.server.BatchUpdateResult) BatchDeleteRequest(com.linkedin.restli.server.BatchDeleteRequest) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) DiscoveredItem(com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItem) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiTestHelper.buildResourceModel(com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel) EasyMock.anyObject(org.easymock.EasyMock.anyObject) DiscoveredItemKey(com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItemKey) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 24 with RestLiCallback

use of com.linkedin.restli.internal.server.RestLiCallback in project rest.li by linkedin.

the class TestRestLiMethodInvocation method testAsyncFinderOptionalBooleanParam.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "statusFinderOptionalBooleanParam")
@SuppressWarnings("unchecked")
public void testAsyncFinderOptionalBooleanParam(ProtocolVersion version, String query) throws Exception {
    RestLiCallback<?> callback = getCallback();
    ResourceModel statusResourceModel = buildResourceModel(AsyncStatusCollectionResource.class);
    ResourceMethodDescriptor methodDescriptor = statusResourceModel.findNamedMethod("user_timeline");
    AsyncStatusCollectionResource statusResource = getMockResource(AsyncStatusCollectionResource.class);
    statusResource.getUserTimeline((PagingContext) EasyMock.anyObject(), eq(false), (Callback<List<Status>>) EasyMock.anyObject());
    EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {

        @Override
        public Object answer() throws Throwable {
            @SuppressWarnings("unchecked") Callback<List<Status>> callback = (Callback<List<Status>>) EasyMock.getCurrentArguments()[2];
            callback.onSuccess(null);
            return null;
        }
    });
    EasyMock.replay(statusResource);
    checkAsyncInvocation(statusResource, callback, methodDescriptor, "GET", version, "/asyncstatuses" + query, null);
}
Also used : Status(com.linkedin.restli.server.twitter.TwitterTestDataModels.Status) HttpStatus(com.linkedin.restli.common.HttpStatus) Callback(com.linkedin.common.callback.Callback) RestLiCallback(com.linkedin.restli.internal.server.RestLiCallback) FilterChainCallback(com.linkedin.restli.internal.server.filter.FilterChainCallback) RequestExecutionCallback(com.linkedin.restli.server.RequestExecutionCallback) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiTestHelper.buildResourceModel(com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel) List(java.util.List) EasyMock.anyObject(org.easymock.EasyMock.anyObject) AsyncStatusCollectionResource(com.linkedin.restli.server.twitter.AsyncStatusCollectionResource) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 25 with RestLiCallback

use of com.linkedin.restli.internal.server.RestLiCallback in project rest.li by linkedin.

the class TestRestLiMethodInvocation method testAsyncFinder.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "statusFinder")
@SuppressWarnings("unchecked")
public void testAsyncFinder(ProtocolVersion version, String query) throws Exception {
    RestLiCallback<?> callback = getCallback();
    ResourceModel statusResourceModel = buildResourceModel(AsyncStatusCollectionResource.class);
    ResourceMethodDescriptor methodDescriptor = statusResourceModel.findNamedMethod("search");
    AsyncStatusCollectionResource statusResource = getMockResource(AsyncStatusCollectionResource.class);
    statusResource.search((PagingContext) EasyMock.anyObject(), eq("linkedin"), eq(1L), eq(StatusType.REPLY), (Callback<List<Status>>) EasyMock.anyObject());
    EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {

        @Override
        public Object answer() throws Throwable {
            @SuppressWarnings("unchecked") Callback<List<Status>> callback = (Callback<List<Status>>) EasyMock.getCurrentArguments()[4];
            callback.onSuccess(null);
            return null;
        }
    });
    EasyMock.replay(statusResource);
    checkAsyncInvocation(statusResource, callback, methodDescriptor, "GET", version, "/asyncstatuses" + query, null);
}
Also used : Status(com.linkedin.restli.server.twitter.TwitterTestDataModels.Status) HttpStatus(com.linkedin.restli.common.HttpStatus) Callback(com.linkedin.common.callback.Callback) RestLiCallback(com.linkedin.restli.internal.server.RestLiCallback) FilterChainCallback(com.linkedin.restli.internal.server.filter.FilterChainCallback) RequestExecutionCallback(com.linkedin.restli.server.RequestExecutionCallback) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiTestHelper.buildResourceModel(com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel) List(java.util.List) EasyMock.anyObject(org.easymock.EasyMock.anyObject) AsyncStatusCollectionResource(com.linkedin.restli.server.twitter.AsyncStatusCollectionResource) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

RestLiCallback (com.linkedin.restli.internal.server.RestLiCallback)29 FilterChainCallback (com.linkedin.restli.internal.server.filter.FilterChainCallback)29 EasyMock.anyObject (org.easymock.EasyMock.anyObject)29 RequestExecutionCallback (com.linkedin.restli.server.RequestExecutionCallback)28 AfterTest (org.testng.annotations.AfterTest)28 BeforeTest (org.testng.annotations.BeforeTest)28 Test (org.testng.annotations.Test)28 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)26 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)26 RestLiTestHelper.buildResourceModel (com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel)26 Callback (com.linkedin.common.callback.Callback)25 AsyncStatusCollectionResource (com.linkedin.restli.server.twitter.AsyncStatusCollectionResource)15 HttpStatus (com.linkedin.restli.common.HttpStatus)13 Status (com.linkedin.restli.server.twitter.TwitterTestDataModels.Status)13 AsyncDiscoveredItemsResource (com.linkedin.restli.server.twitter.AsyncDiscoveredItemsResource)11 ByteString (com.linkedin.data.ByteString)9 BatchUpdateResult (com.linkedin.restli.server.BatchUpdateResult)9 CustomString (com.linkedin.restli.server.custom.types.CustomString)9 DiscoveredItem (com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItem)9 DiscoveredItemKey (com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItemKey)9