Search in sources :

Example 1 with BatchCreateRequest

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

the class TestRestLiMethodInvocation method testPromiseBatchCreate.

@Test
@SuppressWarnings({ "unchecked" })
public void testPromiseBatchCreate() throws Exception {
    ResourceModel statusResourceModel = buildResourceModel(PromiseStatusCollectionResource.class);
    ResourceModel discoveredItemsResourceModel = buildResourceModel(PromiseDiscoveredItemsResource.class);
    ResourceMethodDescriptor methodDescriptor;
    PromiseStatusCollectionResource statusResource;
    PromiseDiscoveredItemsResource discoveredItemsResource;
    // #1 Batch create on collection resource
    methodDescriptor = statusResourceModel.findMethod(ResourceMethod.BATCH_CREATE);
    statusResource = getMockResource(PromiseStatusCollectionResource.class);
    @SuppressWarnings("rawtypes") BatchCreateRequest batchCreateRequest = (BatchCreateRequest) EasyMock.anyObject();
    EasyMock.expect(statusResource.batchCreate(batchCreateRequest)).andReturn(Promises.<BatchCreateResult<Long, Status>>value(null)).once();
    String body = RestLiTestHelper.doubleQuote("{'elements':[{},{}]}");
    checkInvocation(statusResource, methodDescriptor, "POST", version, "/promisestatuses", body, buildBatchPathKeys());
    // #2 Batch create on complex-key resource
    methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.BATCH_CREATE);
    discoveredItemsResource = getMockResource(PromiseDiscoveredItemsResource.class);
    batchCreateRequest = (BatchCreateRequest) EasyMock.anyObject();
    EasyMock.expect(discoveredItemsResource.batchCreate(batchCreateRequest)).andReturn(Promises.<BatchCreateResult<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>>value(null)).once();
    checkInvocation(discoveredItemsResource, methodDescriptor, "POST", version, "/promisediscovereditems", body, buildBatchPathKeys());
}
Also used : BatchCreateRequest(com.linkedin.restli.server.BatchCreateRequest) PromiseStatusCollectionResource(com.linkedin.restli.server.twitter.PromiseStatusCollectionResource) DiscoveredItemKeyParams(com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItemKeyParams) 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) BatchCreateResult(com.linkedin.restli.server.BatchCreateResult) PromiseDiscoveredItemsResource(com.linkedin.restli.server.twitter.PromiseDiscoveredItemsResource) ByteString(com.linkedin.data.ByteString) CustomString(com.linkedin.restli.server.custom.types.CustomString) DiscoveredItemKey(com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItemKey) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 2 with BatchCreateRequest

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

the class TestRestLiMethodInvocation method testAsyncBatchCreateComplexKeyResource.

@Test
public void testAsyncBatchCreateComplexKeyResource() throws Exception {
    ResourceModel discoveredResourceModel = buildResourceModel(AsyncDiscoveredItemsResource.class);
    RestLiCallback<?> callback = getCallback();
    ResourceMethodDescriptor methodDescriptor;
    AsyncDiscoveredItemsResource discoveredResource;
    methodDescriptor = discoveredResourceModel.findMethod(ResourceMethod.BATCH_CREATE);
    discoveredResource = getMockResource(AsyncDiscoveredItemsResource.class);
    @SuppressWarnings("unchecked") BatchCreateRequest<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem> mockBatchCreateReq = (BatchCreateRequest<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>) EasyMock.anyObject();
    discoveredResource.batchCreate(mockBatchCreateReq, EasyMock.<Callback<BatchCreateResult<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>>>anyObject());
    EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {

        @Override
        public Object answer() throws Throwable {
            @SuppressWarnings("unchecked") Callback<BatchCreateResult<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>> callback = (Callback<BatchCreateResult<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>>) EasyMock.getCurrentArguments()[1];
            callback.onSuccess(null);
            return null;
        }
    });
    EasyMock.replay(discoveredResource);
    String uri = "/asyncdiscovereditems";
    String entityBody = "{}";
    checkAsyncInvocation(discoveredResource, callback, methodDescriptor, "POST", version, uri, entityBody, buildBatchPathKeys());
}
Also used : BatchCreateRequest(com.linkedin.restli.server.BatchCreateRequest) 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) 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) BatchCreateResult(com.linkedin.restli.server.BatchCreateResult) 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 3 with BatchCreateRequest

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

the class TestBatchCreateArgumentBuilder method testArgumentBuilderSuccess.

@Test
public void testArgumentBuilderSuccess() {
    RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, "{\"elements\":[{\"b\":123,\"a\":\"abc\"},{\"b\":5678,\"a\":\"xyzw\"}]}", 1);
    ResourceModel model = RestLiArgumentBuilderTestHelper.getMockResourceModel(MyComplexKey.class, null, false);
    @SuppressWarnings("rawtypes") Parameter<BatchCreateRequest> param = new Parameter<BatchCreateRequest>("", BatchCreateRequest.class, null, false, null, Parameter.ParamType.BATCH, false, new AnnotationSet(new Annotation[] {}));
    ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, param);
    ResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(null, null, null, true);
    RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 2, context, 1);
    RestLiArgumentBuilder argumentBuilder = new BatchCreateArgumentBuilder();
    RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, request);
    Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
    assertEquals(args.length, 1);
    assertTrue(args[0] instanceof BatchCreateRequest);
    @SuppressWarnings("unchecked") List<MyComplexKey> entities = ((BatchCreateRequest<Integer, MyComplexKey>) args[0]).getInput();
    assertEquals(entities.size(), 2);
    assertEquals(entities.get(0).getA(), "abc");
    assertEquals((long) entities.get(0).getB(), 123L);
    assertEquals(entities.get(1).getA(), "xyzw");
    assertEquals((long) entities.get(1).getB(), 5678L);
    verify(request, model, descriptor, context, routingResult);
}
Also used : BatchCreateRequest(com.linkedin.restli.server.BatchCreateRequest) ResourceContext(com.linkedin.restli.server.ResourceContext) MyComplexKey(com.linkedin.restli.common.test.MyComplexKey) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) AnnotationSet(com.linkedin.restli.internal.server.model.AnnotationSet) Annotation(java.lang.annotation.Annotation) RoutingResult(com.linkedin.restli.internal.server.RoutingResult) RestRequest(com.linkedin.r2.message.rest.RestRequest) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) Parameter(com.linkedin.restli.internal.server.model.Parameter) RestLiRequestData(com.linkedin.restli.server.RestLiRequestData) Test(org.testng.annotations.Test)

Example 4 with BatchCreateRequest

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

the class TestRestLiMethodInvocation method testBatchCreate.

@Test
@SuppressWarnings({ "unchecked" })
public void testBatchCreate() throws Exception {
    ResourceModel statusResourceModel = buildResourceModel(StatusCollectionResource.class);
    ResourceModel discoveredItemsResourceModel = buildResourceModel(DiscoveredItemsResource.class);
    ResourceMethodDescriptor methodDescriptor;
    StatusCollectionResource statusResource;
    DiscoveredItemsResource discoveredItemsResource;
    // #1 Batch create on collection resource
    methodDescriptor = statusResourceModel.findMethod(ResourceMethod.BATCH_CREATE);
    statusResource = getMockResource(StatusCollectionResource.class);
    @SuppressWarnings("rawtypes") BatchCreateRequest batchCreateRequest = (BatchCreateRequest) EasyMock.anyObject();
    EasyMock.expect(statusResource.batchCreate(batchCreateRequest)).andReturn(null).once();
    String body = RestLiTestHelper.doubleQuote("{'elements':[{},{}]}");
    checkInvocation(statusResource, methodDescriptor, "POST", version, "/statuses", body, buildBatchPathKeys());
    // #2 Batch create on complex-key resource
    methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.BATCH_CREATE);
    discoveredItemsResource = getMockResource(DiscoveredItemsResource.class);
    batchCreateRequest = (BatchCreateRequest) EasyMock.anyObject();
    EasyMock.expect(discoveredItemsResource.batchCreate(batchCreateRequest)).andReturn(null).once();
    checkInvocation(discoveredItemsResource, methodDescriptor, "POST", version, "/discovereditems", body, buildBatchPathKeys());
}
Also used : BatchCreateRequest(com.linkedin.restli.server.BatchCreateRequest) 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) TaskStatusCollectionResource(com.linkedin.restli.server.twitter.TaskStatusCollectionResource) StatusCollectionResource(com.linkedin.restli.server.twitter.StatusCollectionResource) AsyncStatusCollectionResource(com.linkedin.restli.server.twitter.AsyncStatusCollectionResource) CustomStatusCollectionResource(com.linkedin.restli.server.twitter.CustomStatusCollectionResource) PromiseStatusCollectionResource(com.linkedin.restli.server.twitter.PromiseStatusCollectionResource) AsyncDiscoveredItemsResource(com.linkedin.restli.server.twitter.AsyncDiscoveredItemsResource) PromiseDiscoveredItemsResource(com.linkedin.restli.server.twitter.PromiseDiscoveredItemsResource) DiscoveredItemsResource(com.linkedin.restli.server.twitter.DiscoveredItemsResource) ByteString(com.linkedin.data.ByteString) CustomString(com.linkedin.restli.server.custom.types.CustomString) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 5 with BatchCreateRequest

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

the class TestRestLiMethodInvocation method testAsyncBatchCreate.

@Test
public void testAsyncBatchCreate() throws Exception {
    ResourceModel statusResourceModel = buildResourceModel(AsyncStatusCollectionResource.class);
    RestLiCallback<?> callback = getCallback();
    ResourceMethodDescriptor methodDescriptor;
    AsyncStatusCollectionResource statusResource;
    methodDescriptor = statusResourceModel.findMethod(ResourceMethod.BATCH_CREATE);
    statusResource = getMockResource(AsyncStatusCollectionResource.class);
    @SuppressWarnings("unchecked") BatchCreateRequest<Long, Status> mockBatchCreateReq = (BatchCreateRequest<Long, Status>) EasyMock.anyObject();
    statusResource.batchCreate(mockBatchCreateReq, EasyMock.<Callback<BatchCreateResult<Long, Status>>>anyObject());
    EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {

        @Override
        public Object answer() throws Throwable {
            @SuppressWarnings("unchecked") Callback<BatchCreateResult<Long, Status>> callback = (Callback<BatchCreateResult<Long, Status>>) EasyMock.getCurrentArguments()[1];
            callback.onSuccess(null);
            return null;
        }
    });
    EasyMock.replay(statusResource);
    checkAsyncInvocation(statusResource, callback, methodDescriptor, "POST", version, "/asyncstatuses", "{}", null);
}
Also used : Status(com.linkedin.restli.server.twitter.TwitterTestDataModels.Status) HttpStatus(com.linkedin.restli.common.HttpStatus) BatchCreateRequest(com.linkedin.restli.server.BatchCreateRequest) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) AsyncStatusCollectionResource(com.linkedin.restli.server.twitter.AsyncStatusCollectionResource) 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) CustomLong(com.linkedin.restli.server.custom.types.CustomLong) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiTestHelper.buildResourceModel(com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel) BatchCreateResult(com.linkedin.restli.server.BatchCreateResult) EasyMock.anyObject(org.easymock.EasyMock.anyObject) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

BatchCreateRequest (com.linkedin.restli.server.BatchCreateRequest)7 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)6 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)6 Test (org.testng.annotations.Test)6 RestLiTestHelper.buildResourceModel (com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel)5 AfterTest (org.testng.annotations.AfterTest)5 BeforeTest (org.testng.annotations.BeforeTest)5 ByteString (com.linkedin.data.ByteString)4 CustomString (com.linkedin.restli.server.custom.types.CustomString)4 BatchCreateResult (com.linkedin.restli.server.BatchCreateResult)3 Callback (com.linkedin.common.callback.Callback)2 RestLiCallback (com.linkedin.restli.internal.server.RestLiCallback)2 FilterChainCallback (com.linkedin.restli.internal.server.filter.FilterChainCallback)2 RequestExecutionCallback (com.linkedin.restli.server.RequestExecutionCallback)2 AsyncDiscoveredItemsResource (com.linkedin.restli.server.twitter.AsyncDiscoveredItemsResource)2 AsyncStatusCollectionResource (com.linkedin.restli.server.twitter.AsyncStatusCollectionResource)2 PromiseDiscoveredItemsResource (com.linkedin.restli.server.twitter.PromiseDiscoveredItemsResource)2 PromiseStatusCollectionResource (com.linkedin.restli.server.twitter.PromiseStatusCollectionResource)2 DiscoveredItemKey (com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItemKey)2 DiscoveredItemKeyParams (com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItemKeyParams)2