use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor in project rest.li by linkedin.
the class TestUpdateArgumentBuilder method testFailure.
@Test(dataProvider = "failureEntityData", dataProviderClass = RestLiArgumentBuilderTestHelper.class)
public void testFailure(String entity) {
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 UpdateArgumentBuilder();
try {
argumentBuilder.extractRequestData(routingResult, request);
fail("Expected RoutingException");
} catch (RoutingException e) {
assertTrue(e.getMessage().contains("Error parsing entity body"));
}
verify(request, model, descriptor, routingResult);
}
use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor in project rest.li by linkedin.
the class TestActionResponseBuilder method testBuilder.
@Test(dataProvider = "testData")
public void testBuilder(Object result, HttpStatus httpStatus, long returnValue) {
Map<String, String> headers = ResponseBuilderUtil.getHeaders();
ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor();
RoutingResult routingResult = new RoutingResult(null, mockDescriptor);
ActionResponseBuilder actionResponseBuilder = new ActionResponseBuilder();
RestLiResponseData responseData = actionResponseBuilder.buildRestLiResponseData(null, routingResult, result, headers, Collections.<HttpCookie>emptyList());
PartialRestResponse restResponse = actionResponseBuilder.buildResponse(routingResult, responseData);
EasyMock.verify(mockDescriptor);
ResponseBuilderUtil.validateHeaders(restResponse, headers);
Assert.assertEquals(restResponse.getStatus(), httpStatus);
Assert.assertEquals((restResponse.getEntity()), getActionResponse(returnValue));
}
use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor in project rest.li by linkedin.
the class TestActionResponseBuilder method getMockResourceMethodDescriptor.
@SuppressWarnings("unchecked")
private static ResourceMethodDescriptor getMockResourceMethodDescriptor() {
ResourceMethodDescriptor mockDescriptor = EasyMock.createMock(ResourceMethodDescriptor.class);
EasyMock.expect(mockDescriptor.getActionReturnRecordDataSchema()).andReturn(LONG_RETURN.getField().getRecord()).once();
EasyMock.expect(((FieldDef<Long>) mockDescriptor.getActionReturnFieldDef())).andReturn(LONG_RETURN).once();
EasyMock.replay(mockDescriptor);
return mockDescriptor;
}
use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor in project rest.li by linkedin.
the class TestCollectionArgumentBuilder method testFailure.
@Test(dataProvider = "failureData")
public void testFailure(List<Parameter<?>> params, Map<String, String> contextParams, String errorMessage) {
ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(null, 1, params);
//We cannot use RestLiArgumentBuilderTestHelper's getMockResourceContext since this is a failure scenario and
//getRequestAttachmentReader() will not be called.
ServerResourceContext context = createMock(ServerResourceContext.class);
for (String key : contextParams.keySet()) {
expect(context.getParameter(key)).andReturn(contextParams.get(key));
}
replay(context);
RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 1, context, 1);
RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, null, 0);
RestLiArgumentBuilder argumentBuilder = new CollectionArgumentBuilder();
RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, request);
try {
argumentBuilder.buildArguments(requestData, routingResult);
fail("Expected RoutingException");
} catch (RoutingException e) {
assertTrue(e.getMessage().contains(errorMessage));
}
verify(descriptor, context, routingResult, request);
}
use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor in project rest.li by linkedin.
the class TestCollectionArgumentBuilder method testComplexArrayArgument.
@Test(dataProvider = "complexArrayArgument")
public void testComplexArrayArgument(Parameter<?> param, String parameterKey, String parameterValue, Object structuredParameter, Object[] expectedArgs) {
ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(null, param);
ResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContextWithStructuredParameter(parameterKey, parameterValue, structuredParameter, true);
RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 1, context, 1);
RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, null, 0);
RestLiArgumentBuilder argumentBuilder = new CollectionArgumentBuilder();
RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, request);
Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
assertEquals(args, expectedArgs);
verify(descriptor, context, routingResult, request);
}
Aggregations