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());
}
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());
}
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);
}
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());
}
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);
}
Aggregations