use of com.linkedin.restli.server.UpdateResponse in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testAsyncPut.
@SuppressWarnings("unchecked")
@Test
public void testAsyncPut() throws Exception {
Map<String, ResourceModel> resourceModelMap = buildResourceModels(AsyncStatusCollectionResource.class, AsyncLocationResource.class, AsyncDiscoveredItemsResource.class);
ResourceModel statusResourceModel = resourceModelMap.get("/asyncstatuses");
ResourceModel locationResourceModel = statusResourceModel.getSubResource("asynclocation");
ResourceModel followsAssociationResourceModel = buildResourceModel(AsyncFollowsAssociativeResource.class);
ResourceModel discoveredItemsResourceModel = resourceModelMap.get("/asyncdiscovereditems");
RestLiCallback callback = getCallback();
ResourceMethodDescriptor methodDescriptor;
AsyncStatusCollectionResource statusResource;
AsyncFollowsAssociativeResource followsResource;
AsyncLocationResource locationResource;
AsyncDiscoveredItemsResource discoveredItemsResource;
// #1 Update on collection resource
methodDescriptor = statusResourceModel.findMethod(ResourceMethod.UPDATE);
statusResource = getMockResource(AsyncStatusCollectionResource.class);
long id = eq(1L);
Status status = EasyMock.anyObject();
statusResource.update(id, status, EasyMock.anyObject());
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
@SuppressWarnings("unchecked") Callback<UpdateResponse> callback = (Callback<UpdateResponse>) EasyMock.getCurrentArguments()[2];
callback.onSuccess(null);
return null;
}
});
EasyMock.replay(statusResource);
checkAsyncInvocation(statusResource, callback, methodDescriptor, "PUT", version, "/asyncstatuses/1", "{}", buildPathKeys("statusID", 1L));
// #2 Update on association resource
methodDescriptor = followsAssociationResourceModel.findMethod(ResourceMethod.UPDATE);
followsResource = getMockResource(AsyncFollowsAssociativeResource.class);
CompoundKey rawKey = new CompoundKey();
rawKey.append("followerID", 1L);
rawKey.append("followeeID", 2L);
CompoundKey key = eq(rawKey);
Followed followed = EasyMock.anyObject();
followsResource.update(key, followed, (Callback<UpdateResponse>) EasyMock.anyObject());
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
Callback<UpdateResponse> callback = (Callback<UpdateResponse>) EasyMock.getCurrentArguments()[2];
callback.onSuccess(null);
return null;
}
});
EasyMock.replay(followsResource);
checkAsyncInvocation(followsResource, callback, methodDescriptor, "PUT", version, "/asyncfollows/(followerID:1,followeeID:2)", "{}", buildPathKeys("followerID", 1L, "followeeID", 2L, followsAssociationResourceModel.getKeyName(), rawKey));
// #3 Update on simple resource
methodDescriptor = locationResourceModel.findMethod(ResourceMethod.UPDATE);
locationResource = getMockResource(AsyncLocationResource.class);
Location location = EasyMock.anyObject();
locationResource.update(location, EasyMock.anyObject());
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
@SuppressWarnings("unchecked") Callback<UpdateResponse> callback = (Callback<UpdateResponse>) EasyMock.getCurrentArguments()[1];
callback.onSuccess(null);
return null;
}
});
EasyMock.replay(locationResource);
checkAsyncInvocation(locationResource, callback, methodDescriptor, "PUT", version, "/asyncstatuses/1/asynclocation", "{}", buildPathKeys("statusID", 1L));
// #4 Update on complex-key resource
methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.UPDATE);
discoveredItemsResource = getMockResource(AsyncDiscoveredItemsResource.class);
ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams> complexKey = getDiscoveredItemComplexKey(1L, 2, 3L);
discoveredItemsResource.update(eq(complexKey), EasyMock.anyObject(DiscoveredItem.class), EasyMock.anyObject());
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
@SuppressWarnings("unchecked") Callback<UpdateResponse> callback = (Callback<UpdateResponse>) EasyMock.getCurrentArguments()[2];
callback.onSuccess(null);
return null;
}
});
EasyMock.replay(discoveredItemsResource);
checkAsyncInvocation(discoveredItemsResource, callback, methodDescriptor, "PUT", version, "/asyncdiscovereditems/(itemId:1,type:2,userId:3)", "{}", buildPathKeys("asyncDiscoveredItemId", complexKey));
}
use of com.linkedin.restli.server.UpdateResponse 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 {
RestLiResponse response;
// #4 batch
Map<Long, Status> map = new HashMap<>();
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, 1, true, errorResponseHeaderName);
Map<Long, UpdateResponse> updateStatusMap = new HashMap<>();
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<>(updateStatusMap);
response = invokeResponseHandler("/test", batchUpdateResult, ResourceMethod.BATCH_UPDATE, acceptTypeData.acceptHeaders, protocolVersion);
checkResponse(response, 200, 1, true, errorResponseHeaderName);
response = invokeResponseHandler("/test", batchUpdateResult, ResourceMethod.BATCH_PARTIAL_UPDATE, acceptTypeData.acceptHeaders, protocolVersion);
checkResponse(response, 200, 1, true, errorResponseHeaderName);
response = invokeResponseHandler("/test", batchUpdateResult, ResourceMethod.BATCH_DELETE, acceptTypeData.acceptHeaders, protocolVersion);
checkResponse(response, 200, 1, true, errorResponseHeaderName);
List<CreateResponse> createResponses = new ArrayList<>();
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<>(createResponses);
// here
response = invokeResponseHandler("/test", batchCreateResult, ResourceMethod.BATCH_CREATE, acceptTypeData.acceptHeaders, protocolVersion);
checkResponse(response, 200, 1, true, errorResponseHeaderName);
}
use of com.linkedin.restli.server.UpdateResponse in project rest.li by linkedin.
the class TestUpdateResponseBuilder method testBuilder.
@Test
public void testBuilder() {
HttpStatus status = HttpStatus.S_200_OK;
UpdateResponse updateResponse = new UpdateResponse(status);
Map<String, String> headers = ResponseBuilderUtil.getHeaders();
ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor();
RoutingResult routingResult = new RoutingResult(null, mockDescriptor);
UpdateResponseBuilder updateResponseBuilder = new UpdateResponseBuilder();
RestLiResponseData responseData = updateResponseBuilder.buildRestLiResponseData(null, routingResult, updateResponse, headers, Collections.<HttpCookie>emptyList());
PartialRestResponse partialRestResponse = updateResponseBuilder.buildResponse(routingResult, responseData);
EasyMock.verify(mockDescriptor);
ResponseBuilderUtil.validateHeaders(partialRestResponse, headers);
Assert.assertEquals(partialRestResponse.getStatus(), status);
}
use of com.linkedin.restli.server.UpdateResponse in project incubator-gobblin by apache.
the class FlowConfigsResource method delete.
/**
* Delete a configured flow. Running flows are not affected. The schedule will be removed for scheduled flows.
* @param key composite key containing flow group and flow name that identifies the flow to remove from the
* {@link FlowCatalog}
* @return {@link UpdateResponse}
*/
@Override
public UpdateResponse delete(ComplexResourceKey<FlowId, EmptyRecord> key) {
String flowGroup = key.getKey().getFlowGroup();
String flowName = key.getKey().getFlowName();
URI flowUri = null;
LOG.info("Delete called with flowGroup " + flowGroup + " flowName " + flowName);
try {
URI flowCatalogURI = new URI("gobblin-flow", null, "/", null, null);
flowUri = new URI(flowCatalogURI.getScheme(), flowCatalogURI.getAuthority(), "/" + flowGroup + "/" + flowName, null, null);
getFlowCatalog().remove(flowUri);
return new UpdateResponse(HttpStatus.S_200_OK);
} catch (URISyntaxException e) {
logAndThrowRestLiServiceException(HttpStatus.S_400_BAD_REQUEST, "bad URI " + flowUri, e);
}
return null;
}
use of com.linkedin.restli.server.UpdateResponse in project rest.li by linkedin.
the class GroupsResource2 method update.
@Override
public UpdateResponse update(Integer id, PatchRequest<Group> patch) {
Group group = get(id);
try {
PatchApplier.applyPatch(group, patch);
} catch (DataProcessingException e) {
return new UpdateResponse(HttpStatus.S_400_BAD_REQUEST);
}
boolean wasUpdated = getGroupMgr().update(id, group);
return new UpdateResponse(wasUpdated ? HttpStatus.S_204_NO_CONTENT : HttpStatus.S_404_NOT_FOUND);
}
Aggregations