Search in sources :

Example 16 with BatchUpdateResult

use of com.linkedin.restli.server.BatchUpdateResult 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);
}
Also used : UpdateStatus(com.linkedin.restli.common.UpdateStatus) CreateStatus(com.linkedin.restli.common.CreateStatus) Status(com.linkedin.restli.server.twitter.TwitterTestDataModels.Status) HttpStatus(com.linkedin.restli.common.HttpStatus) CreateStatus(com.linkedin.restli.common.CreateStatus) UpdateStatus(com.linkedin.restli.common.UpdateStatus) HashMap(java.util.HashMap) RestResponse(com.linkedin.r2.message.rest.RestResponse) PartialRestResponse(com.linkedin.restli.internal.server.response.PartialRestResponse) BatchResponse(com.linkedin.restli.common.BatchResponse) CreateResponse(com.linkedin.restli.server.CreateResponse) CollectionResponse(com.linkedin.restli.common.CollectionResponse) ArrayList(java.util.ArrayList) UpdateResponse(com.linkedin.restli.server.UpdateResponse) BatchUpdateResult(com.linkedin.restli.server.BatchUpdateResult) BatchCreateResult(com.linkedin.restli.server.BatchCreateResult) Test(org.testng.annotations.Test)

Example 17 with BatchUpdateResult

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

the class TestRestLiMethodInvocation method testPromiseBatchPatch.

@Test
@SuppressWarnings({ "unchecked" })
public void testPromiseBatchPatch() throws Exception {
    ResourceModel statusResourceModel = buildResourceModel(PromiseStatusCollectionResource.class);
    ResourceMethodDescriptor methodDescriptor = statusResourceModel.findMethod(ResourceMethod.BATCH_PARTIAL_UPDATE);
    PromiseStatusCollectionResource statusResource = getMockResource(PromiseStatusCollectionResource.class);
    @SuppressWarnings("rawtypes") BatchPatchRequest batchPatchRequest = (BatchPatchRequest) EasyMock.anyObject();
    EasyMock.expect(statusResource.batchUpdate(batchPatchRequest)).andReturn(Promises.<BatchUpdateResult<Long, Status>>value(null)).once();
    String body = RestLiTestHelper.doubleQuote("{'entities':{'1':{},'2':{}}}");
    checkInvocation(statusResource, methodDescriptor, "POST", version, "/promisestatuses?ids=List(1,2)", body, buildBatchPathKeys(1L, 2L));
}
Also used : PromiseStatusCollectionResource(com.linkedin.restli.server.twitter.PromiseStatusCollectionResource) BatchUpdateResult(com.linkedin.restli.server.BatchUpdateResult) BatchPatchRequest(com.linkedin.restli.server.BatchPatchRequest) 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) 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 18 with BatchUpdateResult

use of com.linkedin.restli.server.BatchUpdateResult 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));
}
Also used : Status(com.linkedin.restli.server.twitter.TwitterTestDataModels.Status) HttpStatus(com.linkedin.restli.common.HttpStatus) BatchUpdateRequest(com.linkedin.restli.server.BatchUpdateRequest) 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) BatchUpdateResult(com.linkedin.restli.server.BatchUpdateResult) 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)

Example 19 with BatchUpdateResult

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

the class AutomaticValidationDemoResource method batchUpdate.

@RestMethod.BatchUpdate
public BatchUpdateResult<Integer, ValidationDemo> batchUpdate(final BatchUpdateRequest<Integer, ValidationDemo> entities) {
    Map<Integer, UpdateResponse> results = new HashMap<Integer, UpdateResponse>();
    Map<Integer, RestLiServiceException> errors = new HashMap<Integer, RestLiServiceException>();
    for (Map.Entry<Integer, ValidationDemo> entry : entities.getData().entrySet()) {
        Integer key = entry.getKey();
        ValidationDemo entity = entry.getValue();
        results.put(key, new UpdateResponse(HttpStatus.S_204_NO_CONTENT));
    }
    return new BatchUpdateResult<Integer, ValidationDemo>(results, errors);
}
Also used : UpdateResponse(com.linkedin.restli.server.UpdateResponse) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) BatchUpdateResult(com.linkedin.restli.server.BatchUpdateResult) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo)

Example 20 with BatchUpdateResult

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

the class ChainedTyperefResource method batchUpdate.

@Override
public BatchUpdateResult<CompoundKey, Greeting> batchUpdate(BatchUpdateRequest<CompoundKey, Greeting> entities) {
    Set<CompoundKey> keys = entities.getData().keySet();
    Map<CompoundKey, UpdateResponse> responseMap = new HashMap<CompoundKey, UpdateResponse>();
    Map<CompoundKey, RestLiServiceException> errorMap = new HashMap<CompoundKey, RestLiServiceException>();
    for (CompoundKey key : keys) {
        responseMap.put(key, new UpdateResponse(HttpStatus.S_201_CREATED));
    }
    return new BatchUpdateResult<CompoundKey, Greeting>(responseMap);
}
Also used : UpdateResponse(com.linkedin.restli.server.UpdateResponse) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) BatchUpdateResult(com.linkedin.restli.server.BatchUpdateResult) CompoundKey(com.linkedin.restli.common.CompoundKey) HashMap(java.util.HashMap)

Aggregations

BatchUpdateResult (com.linkedin.restli.server.BatchUpdateResult)33 UpdateResponse (com.linkedin.restli.server.UpdateResponse)19 HashMap (java.util.HashMap)19 Test (org.testng.annotations.Test)15 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)14 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)14 RestLiTestHelper.buildResourceModel (com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel)14 AfterTest (org.testng.annotations.AfterTest)14 BeforeTest (org.testng.annotations.BeforeTest)14 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)11 Map (java.util.Map)10 Callback (com.linkedin.common.callback.Callback)9 CompoundKey (com.linkedin.restli.common.CompoundKey)9 RestLiCallback (com.linkedin.restli.internal.server.RestLiCallback)9 FilterChainCallback (com.linkedin.restli.internal.server.filter.FilterChainCallback)9 RequestExecutionCallback (com.linkedin.restli.server.RequestExecutionCallback)9 EasyMock.anyObject (org.easymock.EasyMock.anyObject)9 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)8 BatchPatchRequest (com.linkedin.restli.server.BatchPatchRequest)8 DiscoveredItemKey (com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItemKey)5