use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.
the class TestBatchCreateArgumentBuilder method testFailure.
@Test(dataProvider = "failureData")
public void testFailure(String entity, String expectedExceptionMessage) {
RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, entity, 1);
ResourceModel model = RestLiArgumentBuilderTestHelper.getMockResourceModel(MyComplexKey.class, null, false);
ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, 1, null);
RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 1, null, 0);
RestLiArgumentBuilder argumentBuilder = new BatchCreateArgumentBuilder();
try {
argumentBuilder.extractRequestData(routingResult, request);
fail("Expected RestLiInternalException or ClassCastException");
} catch (RestLiInternalException e) {
assertTrue(e.getMessage().contains(expectedExceptionMessage));
} catch (ClassCastException e) {
assertTrue(e.getMessage().contains("java.lang.Integer cannot be cast to com.linkedin.data.DataList"));
}
verify(request, model, descriptor, routingResult);
}
use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.
the class RestLiArgumentBuilderTestHelper method getMockRoutingResult.
static RoutingResult getMockRoutingResult(ResourceMethodDescriptor descriptor, ResourceContext context) {
RoutingResult mockRoutingResult = createMock(RoutingResult.class);
if (descriptor != null) {
expect(mockRoutingResult.getResourceMethod()).andReturn(descriptor).anyTimes();
}
if (context != null) {
expect(mockRoutingResult.getContext()).andReturn(context).anyTimes();
}
replay(mockRoutingResult);
return mockRoutingResult;
}
use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.
the class TestBatchUpdateResponseBuilder method testBuilder.
@Test(dataProvider = "testData")
@SuppressWarnings("unchecked")
public void testBuilder(Object results, ProtocolVersion protocolVersion, String altKeyName, Map<String, AlternativeKey<?, ?>> alternativeKeyMap, Map<String, UpdateStatus> expectedResults, Map<String, ErrorResponse> expectedErrors) {
ResourceContext mockContext = getMockResourceContext(protocolVersion, altKeyName);
ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor(alternativeKeyMap);
RoutingResult routingResult = new RoutingResult(mockContext, mockDescriptor);
Map<String, String> headers = ResponseBuilderUtil.getHeaders();
BatchUpdateResponseBuilder batchUpdateResponseBuilder = new BatchUpdateResponseBuilder(new ErrorResponseBuilder());
RestLiResponseData responseData = batchUpdateResponseBuilder.buildRestLiResponseData(null, routingResult, results, headers, Collections.<HttpCookie>emptyList());
PartialRestResponse restResponse = batchUpdateResponseBuilder.buildResponse(routingResult, responseData);
BatchResponse<UpdateStatus> batchResponse = (BatchResponse<UpdateStatus>) restResponse.getEntity();
EasyMock.verify(mockContext, mockDescriptor);
ResponseBuilderUtil.validateHeaders(restResponse, headers);
Assert.assertEquals(batchResponse.getResults(), expectedResults);
Assert.assertEquals(batchResponse.getErrors().size(), expectedErrors.size());
for (Map.Entry<String, ErrorResponse> entry : batchResponse.getErrors().entrySet()) {
String key = entry.getKey();
ErrorResponse value = entry.getValue();
Assert.assertEquals(value.getStatus(), expectedErrors.get(key).getStatus());
}
}
use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.
the class TestCollectionResponseBuilder method testBuilder.
@SuppressWarnings("unchecked")
@Test(dataProvider = "testData")
public void testBuilder(Object results, DataMap expectedMetadata, List<Foo> expectedElements, CollectionMetadata expectedPaging, MaskTree dataMaskTree, MaskTree metaDataMaskTree, MaskTree pagingMaskTree, ProjectionMode dataProjectionMode, ProjectionMode metadataProjectionMode) throws URISyntaxException {
for (ResourceMethod resourceMethod : Arrays.asList(ResourceMethod.GET_ALL, ResourceMethod.FINDER)) {
Map<String, String> headers = ResponseBuilderUtil.getHeaders();
ResourceContext mockContext = getMockResourceContext(dataMaskTree, metaDataMaskTree, pagingMaskTree, dataProjectionMode, metadataProjectionMode);
ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor(resourceMethod);
RoutingResult routingResult = new RoutingResult(mockContext, mockDescriptor);
CollectionResponseBuilder responseBuilder = new CollectionResponseBuilder();
RestLiResponseData responseData = responseBuilder.buildRestLiResponseData(getRestRequest(), routingResult, results, headers, Collections.<HttpCookie>emptyList());
PartialRestResponse restResponse = responseBuilder.buildResponse(routingResult, responseData);
EasyMock.verify(mockContext, mockDescriptor);
ResponseBuilderUtil.validateHeaders(restResponse, headers);
CollectionResponse<Foo> actualResults = (CollectionResponse<Foo>) restResponse.getEntity();
Assert.assertEquals(actualResults.getElements(), expectedElements);
Assert.assertEquals(actualResults.getMetadataRaw(), expectedMetadata);
Assert.assertEquals(actualResults.getPaging(), expectedPaging);
EasyMock.verify(mockContext);
}
}
use of com.linkedin.restli.internal.server.RoutingResult 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);
}
Aggregations