Search in sources :

Example 11 with RoutingException

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);
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) RoutingException(com.linkedin.restli.server.RoutingException) RestRequest(com.linkedin.r2.message.rest.RestRequest) ResourceContext(com.linkedin.restli.server.ResourceContext) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 12 with RoutingException

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);
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) RoutingException(com.linkedin.restli.server.RoutingException) RestRequest(com.linkedin.r2.message.rest.RestRequest) ResourceContext(com.linkedin.restli.server.ResourceContext) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 13 with RoutingException

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);
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) RoutingException(com.linkedin.restli.server.RoutingException) RestRequest(com.linkedin.r2.message.rest.RestRequest) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) Test(org.testng.annotations.Test)

Example 14 with RoutingException

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);
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) RoutingException(com.linkedin.restli.server.RoutingException) RestRequest(com.linkedin.r2.message.rest.RestRequest) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) RestLiRequestData(com.linkedin.restli.server.RestLiRequestData) Test(org.testng.annotations.Test)

Example 15 with RoutingException

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);
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) RoutingException(com.linkedin.restli.server.RoutingException) RestRequest(com.linkedin.r2.message.rest.RestRequest) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) RestLiRequestData(com.linkedin.restli.server.RestLiRequestData) Test(org.testng.annotations.Test)

Aggregations

RoutingException (com.linkedin.restli.server.RoutingException)41 RestRequest (com.linkedin.r2.message.rest.RestRequest)15 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)15 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)15 Test (org.testng.annotations.Test)15 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)12 DataMap (com.linkedin.data.DataMap)7 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)7 TemplateRuntimeException (com.linkedin.data.template.TemplateRuntimeException)6 ResourceContext (com.linkedin.restli.server.ResourceContext)6 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)6 RequestContext (com.linkedin.r2.message.RequestContext)5 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)5 CompoundKey (com.linkedin.restli.common.CompoundKey)5 RestLiRequestData (com.linkedin.restli.server.RestLiRequestData)5 ByteString (com.linkedin.data.ByteString)4 ResourceContextImpl (com.linkedin.restli.internal.server.ResourceContextImpl)4 RestLiInternalException (com.linkedin.restli.internal.server.RestLiInternalException)4 CustomString (com.linkedin.restli.server.custom.types.CustomString)4 RestLiTestHelper.buildResourceModel (com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel)4