use of com.linkedin.restli.server.BatchCreateResult in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testAsyncBatchPatch.
@Test
public void testAsyncBatchPatch() throws Exception {
ResourceModel statusResourceModel = buildResourceModel(AsyncStatusCollectionResource.class);
RestLiCallback<?> callback = getCallback();
ResourceMethodDescriptor methodDescriptor;
AsyncStatusCollectionResource statusResource;
methodDescriptor = statusResourceModel.findMethod(ResourceMethod.BATCH_PARTIAL_UPDATE);
statusResource = getMockResource(AsyncStatusCollectionResource.class);
@SuppressWarnings("unchecked") BatchPatchRequest<Long, Status> mockBatchPatchReq = (BatchPatchRequest<Long, Status>) EasyMock.anyObject();
statusResource.batchUpdate(mockBatchPatchReq, EasyMock.<Callback<BatchUpdateResult<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?ids=List(1,2,3)", "{\"entities\": {\"1\": {}, \"2\": {}, \"3\": {}}}", buildBatchPathKeys(1L, 2L, 3L));
}
use of com.linkedin.restli.server.BatchCreateResult in project rest.li by linkedin.
the class TestRestLiResponseHandler method testBatchResponses.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "basicData")
public void testBatchResponses(AcceptTypeData acceptTypeData, ProtocolVersion protocolVersion, String errorResponseHeaderName) throws Exception {
RestResponse response;
// #4 batch
Map<Long, Status> map = new HashMap<Long, Status>();
map.put(1L, buildStatusRecord());
map.put(2L, buildStatusRecord());
map.put(3L, buildStatusRecord());
response = invokeResponseHandler("/test", map, ResourceMethod.BATCH_GET, acceptTypeData.acceptHeaders, protocolVersion);
checkResponse(response, 200, 2, acceptTypeData.responseContentType, BatchResponse.class.getName(), Status.class.getName(), true, errorResponseHeaderName);
Map<Long, UpdateResponse> updateStatusMap = new HashMap<Long, UpdateResponse>();
updateStatusMap.put(1L, new UpdateResponse(HttpStatus.S_204_NO_CONTENT));
updateStatusMap.put(2L, new UpdateResponse(HttpStatus.S_204_NO_CONTENT));
updateStatusMap.put(3L, new UpdateResponse(HttpStatus.S_204_NO_CONTENT));
BatchUpdateResult<Long, Status> batchUpdateResult = new BatchUpdateResult<Long, Status>(updateStatusMap);
response = invokeResponseHandler("/test", batchUpdateResult, ResourceMethod.BATCH_UPDATE, acceptTypeData.acceptHeaders, protocolVersion);
checkResponse(response, 200, 2, acceptTypeData.responseContentType, BatchResponse.class.getName(), UpdateStatus.class.getName(), true, errorResponseHeaderName);
response = invokeResponseHandler("/test", batchUpdateResult, ResourceMethod.BATCH_PARTIAL_UPDATE, acceptTypeData.acceptHeaders, protocolVersion);
checkResponse(response, 200, 2, acceptTypeData.responseContentType, BatchResponse.class.getName(), UpdateStatus.class.getName(), true, errorResponseHeaderName);
response = invokeResponseHandler("/test", batchUpdateResult, ResourceMethod.BATCH_DELETE, acceptTypeData.acceptHeaders, protocolVersion);
checkResponse(response, 200, 2, acceptTypeData.responseContentType, BatchResponse.class.getName(), UpdateStatus.class.getName(), true, errorResponseHeaderName);
List<CreateResponse> createResponses = new ArrayList<CreateResponse>();
createResponses.add(new CreateResponse("42", HttpStatus.S_204_NO_CONTENT));
createResponses.add(new CreateResponse(HttpStatus.S_400_BAD_REQUEST));
createResponses.add(new CreateResponse(HttpStatus.S_500_INTERNAL_SERVER_ERROR));
BatchCreateResult<Long, Status> batchCreateResult = new BatchCreateResult<Long, Status>(createResponses);
// here
response = invokeResponseHandler("/test", batchCreateResult, ResourceMethod.BATCH_CREATE, acceptTypeData.acceptHeaders, protocolVersion);
checkResponse(response, 200, 2, acceptTypeData.responseContentType, CollectionResponse.class.getName(), CreateStatus.class.getName(), true, errorResponseHeaderName);
}
use of com.linkedin.restli.server.BatchCreateResult 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);
}
use of com.linkedin.restli.server.BatchCreateResult in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testAsyncBatchUpdate.
@Test
public void testAsyncBatchUpdate() throws Exception {
ResourceModel statusResourceModel = buildResourceModel(AsyncStatusCollectionResource.class);
RestLiCallback<?> callback = getCallback();
ResourceMethodDescriptor methodDescriptor;
AsyncStatusCollectionResource statusResource;
methodDescriptor = statusResourceModel.findMethod(ResourceMethod.BATCH_UPDATE);
statusResource = getMockResource(AsyncStatusCollectionResource.class);
@SuppressWarnings("unchecked") BatchUpdateRequest<Long, Status> mockBatchUpdateReq = (BatchUpdateRequest<Long, Status>) EasyMock.anyObject();
statusResource.batchUpdate(mockBatchUpdateReq, EasyMock.<Callback<BatchUpdateResult<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, "PUT", version, "/asyncstatuses?ids=List(1,2,3)", "{\"entities\": {\"1\": {}, \"2\": {}, \"3\": {}}}", buildBatchPathKeys(1L, 2L, 3L));
}
use of com.linkedin.restli.server.BatchCreateResult in project rest.li by linkedin.
the class ComplexKeysResource method batchCreate.
@Override
public BatchCreateResult<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> batchCreate(final BatchCreateRequest<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> entities) {
List<CreateResponse> createResponses = new ArrayList<CreateResponse>(entities.getInput().size());
for (Message message : entities.getInput()) {
ComplexResourceKey<TwoPartKey, TwoPartKey> key = _dataProvider.create(message);
CreateResponse createResponse = new CreateResponse(key);
createResponses.add(createResponse);
}
return new BatchCreateResult<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message>(createResponses);
}
Aggregations