use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor in project rest.li by linkedin.
the class TestErrorResponseBuilder method testBuilder.
@Test(dataProvider = "testData")
public void testBuilder(ProtocolVersion protocolVersion) {
Map<String, String> headers = ResponseBuilderUtil.getHeaders();
Map<String, String> expectedHeaders = new HashMap<String, String>(headers);
expectedHeaders.put(HeaderUtil.getErrorResponseHeaderName(protocolVersion), RestConstants.HEADER_VALUE_ERROR);
ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor();
RoutingResult routingResult = new RoutingResult(null, mockDescriptor);
RuntimeException runtimeException = new RuntimeException("Internal server error!");
RestLiServiceException serviceException = new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR, runtimeException);
ErrorResponseBuilder errorResponseBuilder = new ErrorResponseBuilder();
RestLiResponseData responseData = errorResponseBuilder.buildRestLiResponseData(null, routingResult, serviceException, headers, Collections.<HttpCookie>emptyList());
PartialRestResponse restResponse = errorResponseBuilder.buildResponse(routingResult, responseData);
EasyMock.verify(mockDescriptor);
ErrorResponse errorResponse = (ErrorResponse) restResponse.getEntity();
Assert.assertEquals(errorResponse.getStatus(), new Integer(500));
Assert.assertTrue(errorResponse.getMessage().contains(runtimeException.getMessage()));
}
use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor in project rest.li by linkedin.
the class TestErrorResponseBuilder method getMockResourceMethodDescriptor.
private ResourceMethodDescriptor getMockResourceMethodDescriptor() {
ResourceMethodDescriptor mockDescriptor = EasyMock.createMock(ResourceMethodDescriptor.class);
EasyMock.expect(mockDescriptor.getMethodType()).andReturn(ResourceMethod.GET);
EasyMock.replay(mockDescriptor);
return mockDescriptor;
}
use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor in project rest.li by linkedin.
the class TestGetResponseBuilder method testBuilder.
@Test(dataProvider = "testData")
public void testBuilder(Object record, HttpStatus expectedHttpStatus, MaskTree maskTree, ProjectionMode projectionMode) {
Map<String, String> headers = ResponseBuilderUtil.getHeaders();
ResourceContext mockContext = getMockResourceContext(maskTree, projectionMode);
ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor();
RoutingResult routingResult = new RoutingResult(mockContext, mockDescriptor);
GetResponseBuilder getResponseBuilder = new GetResponseBuilder();
RestLiResponseData responseData = getResponseBuilder.buildRestLiResponseData(null, routingResult, record, headers, Collections.<HttpCookie>emptyList());
PartialRestResponse partialRestResponse = getResponseBuilder.buildResponse(null, responseData);
EasyMock.verify(mockContext, mockDescriptor);
ResponseBuilderUtil.validateHeaders(partialRestResponse, headers);
Assert.assertEquals(partialRestResponse.getStatus(), expectedHttpStatus);
if (maskTree == null || projectionMode == ProjectionMode.MANUAL) {
Assert.assertEquals(partialRestResponse.getEntity(), getRecord());
} else {
Assert.assertEquals(partialRestResponse.getEntity(), getProjectedRecord());
}
}
use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor in project rest.li by linkedin.
the class TestGetResponseBuilder method getMockResourceMethodDescriptor.
private static ResourceMethodDescriptor getMockResourceMethodDescriptor() {
ResourceMethodDescriptor mockDescriptor = EasyMock.createMock(ResourceMethodDescriptor.class);
EasyMock.replay(mockDescriptor);
return mockDescriptor;
}
use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor in project rest.li by linkedin.
the class TestUpdateArgumentBuilder method testArgumentBuilderSuccess.
@Test(dataProvider = "argumentData")
public void testArgumentBuilderSuccess(List<Parameter<?>> params, Key key, String keyName, Object keyValue) {
RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, "{\"a\":\"xyz\",\"b\":123}", 1);
ResourceModel model = RestLiArgumentBuilderTestHelper.getMockResourceModel(MyComplexKey.class, key, true);
ResourceMethodDescriptor descriptor;
if (key != null) {
descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, 3, params);
} else {
descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, 2, params);
}
ResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(keyName, keyValue, null, true);
RoutingResult routingResult;
if (key != null) {
routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 4, context, 2);
} else {
routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 3, context, 1);
}
RestLiArgumentBuilder argumentBuilder = new UpdateArgumentBuilder();
RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, request);
Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
if (keyValue != null) {
assertEquals(args.length, 2);
assertEquals(args[0], keyValue);
}
assertTrue(args[args.length - 1] instanceof MyComplexKey);
assertEquals(((MyComplexKey) args[args.length - 1]).getA(), "xyz");
assertEquals((long) ((MyComplexKey) args[args.length - 1]).getB(), 123L);
verify(request, model, descriptor, context, routingResult);
}
Aggregations