use of com.linkedin.restli.server.RoutingException in project rest.li by linkedin.
the class TestBatchPatchArgumentBuilder method testFailure.
@Test(dataProvider = "failureData")
public void testFailure(ProtocolVersion version, Key primaryKey, Key[] associationKeys, String requestEntity, Object[] keys, String errorMessage) {
Set<Object> batchKeys = new HashSet<Object>(Arrays.asList(keys));
RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(requestEntity, version);
ResourceModel model = RestLiArgumentBuilderTestHelper.getMockResourceModel(MyComplexKey.class, primaryKey, associationKeys, batchKeys);
ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model);
ResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(batchKeys, false, false);
RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, context);
RestLiArgumentBuilder argumentBuilder = new BatchPatchArgumentBuilder();
try {
argumentBuilder.extractRequestData(routingResult, request);
fail("Expected RoutingException");
} catch (RoutingException e) {
assertTrue(e.getMessage().contains(errorMessage));
}
verify(request, context, routingResult);
}
use of com.linkedin.restli.server.RoutingException in project rest.li by linkedin.
the class TestBatchUpdateArgumentBuilder method testFailure.
@Test(dataProvider = "failureData")
public void testFailure(ProtocolVersion version, Key primaryKey, Key[] associationKeys, String requestEntity, Object[] keys, String errorMessage) {
Set<Object> batchKeys = new HashSet<Object>(Arrays.asList(keys));
RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(requestEntity, version);
ResourceModel model = RestLiArgumentBuilderTestHelper.getMockResourceModel(MyComplexKey.class, primaryKey, associationKeys, batchKeys);
ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model);
ResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(batchKeys, false, false);
RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, context);
RestLiArgumentBuilder argumentBuilder = new BatchUpdateArgumentBuilder();
try {
argumentBuilder.extractRequestData(routingResult, request);
fail("Expected RoutingException");
} catch (RoutingException e) {
assertTrue(e.getMessage().contains(errorMessage));
}
verify(request, model, descriptor, context, routingResult);
}
use of com.linkedin.restli.server.RoutingException 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.server.RoutingException 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.server.RoutingException in project rest.li by linkedin.
the class TestCollectionArgumentBuilder method testArrayArgumentFailure.
@Test(dataProvider = "arrayArgumentFailure")
public void testArrayArgumentFailure(Parameter<?> param, String parameterKey, List<String> parameterValues, String errorMessage) {
ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(null, param);
//We cannot use RestLiArgumentBuilderTestHelper's getMockResourceContext since this is a failure scenario and
//getRequestAttachmentReader() will not be called.
ServerResourceContext context = createMock(ServerResourceContext.class);
expect(context.getParameter(parameterKey)).andReturn(parameterValues.get(0));
expect(context.getParameterValues(parameterKey)).andReturn(parameterValues);
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);
}
Aggregations