Search in sources :

Example 16 with RoutingResult

use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.

the class TestBatchGetResponseBuilder method testContextErrors.

@Test
public void testContextErrors() {
    BatchGetResponseBuilder builder = new BatchGetResponseBuilder(new ErrorResponseBuilder());
    ServerResourceContext context = EasyMock.createMock(ServerResourceContext.class);
    Map<Object, RestLiServiceException> errors = new HashMap<Object, RestLiServiceException>();
    RestLiServiceException exception = new RestLiServiceException(HttpStatus.S_402_PAYMENT_REQUIRED);
    errors.put("foo", exception);
    EasyMock.expect(context.hasParameter("altkey")).andReturn(false);
    EasyMock.expect(context.getBatchKeyErrors()).andReturn(errors);
    EasyMock.replay(context);
    RoutingResult routingResult = new RoutingResult(context, null);
    RestLiResponseData responseData = builder.buildRestLiResponseData(null, routingResult, new BatchResult<Object, EmptyRecord>(Collections.<Object, EmptyRecord>emptyMap(), Collections.<Object, RestLiServiceException>emptyMap()), Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList());
    Assert.assertEquals(responseData.getBatchResponseEnvelope().getBatchResponseMap().get("foo").getException(), exception);
    Assert.assertEquals(responseData.getBatchResponseEnvelope().getBatchResponseMap().size(), 1);
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) EmptyRecord(com.linkedin.restli.common.EmptyRecord) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RestLiResponseData(com.linkedin.restli.server.RestLiResponseData) Test(org.testng.annotations.Test)

Example 17 with RoutingResult

use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.

the class TestActionArgumentBuilder method testArgumentBuilderSuccess.

@Test(dataProvider = "successData")
public void testArgumentBuilderSuccess(String entity, List<Parameter<?>> params, Object[] expectedArgs) {
    RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, entity, 3);
    ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(null, params, null, null);
    ResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(null, null, null, true);
    RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 2, context, 1);
    RestLiArgumentBuilder argumentBuilder = new ActionArgumentBuilder();
    RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, request);
    Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
    assertEquals(args, expectedArgs);
    verify(request, descriptor, routingResult);
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) RestRequest(com.linkedin.r2.message.rest.RestRequest) ResourceContext(com.linkedin.restli.server.ResourceContext) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) RestLiRequestData(com.linkedin.restli.server.RestLiRequestData) Test(org.testng.annotations.Test)

Example 18 with RoutingResult

use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.

the class TestBatchCreateArgumentBuilder method testArgumentBuilderSuccess.

@Test
public void testArgumentBuilderSuccess() {
    RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, "{\"elements\":[{\"b\":123,\"a\":\"abc\"},{\"b\":5678,\"a\":\"xyzw\"}]}", 1);
    ResourceModel model = RestLiArgumentBuilderTestHelper.getMockResourceModel(MyComplexKey.class, null, false);
    @SuppressWarnings("rawtypes") Parameter<BatchCreateRequest> param = new Parameter<BatchCreateRequest>("", BatchCreateRequest.class, null, false, null, Parameter.ParamType.BATCH, false, new AnnotationSet(new Annotation[] {}));
    ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, param);
    ResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(null, null, null, true);
    RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 2, context, 1);
    RestLiArgumentBuilder argumentBuilder = new BatchCreateArgumentBuilder();
    RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, request);
    Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
    assertEquals(args.length, 1);
    assertTrue(args[0] instanceof BatchCreateRequest);
    @SuppressWarnings("unchecked") List<MyComplexKey> entities = ((BatchCreateRequest<Integer, MyComplexKey>) args[0]).getInput();
    assertEquals(entities.size(), 2);
    assertEquals(entities.get(0).getA(), "abc");
    assertEquals((long) entities.get(0).getB(), 123L);
    assertEquals(entities.get(1).getA(), "xyzw");
    assertEquals((long) entities.get(1).getB(), 5678L);
    verify(request, model, descriptor, context, routingResult);
}
Also used : BatchCreateRequest(com.linkedin.restli.server.BatchCreateRequest) ResourceContext(com.linkedin.restli.server.ResourceContext) MyComplexKey(com.linkedin.restli.common.test.MyComplexKey) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) AnnotationSet(com.linkedin.restli.internal.server.model.AnnotationSet) Annotation(java.lang.annotation.Annotation) RoutingResult(com.linkedin.restli.internal.server.RoutingResult) RestRequest(com.linkedin.r2.message.rest.RestRequest) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) Parameter(com.linkedin.restli.internal.server.model.Parameter) RestLiRequestData(com.linkedin.restli.server.RestLiRequestData) Test(org.testng.annotations.Test)

Example 19 with RoutingResult

use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.

the class TestBatchGetArgumentBuilder method testArgumentBuilderSuccess.

@Test(dataProvider = "argumentData")
public void testArgumentBuilderSuccess(Set<Object> batchKeys) {
    @SuppressWarnings("rawtypes") Parameter<Set> param = new Parameter<Set>("", Set.class, null, false, null, Parameter.ParamType.BATCH, false, new AnnotationSet(new Annotation[] {}));
    ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(null, param);
    ResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(null, null, batchKeys, true);
    RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 1, context, 2);
    RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, null, 0);
    RestLiArgumentBuilder argumentBuilder = new BatchGetArgumentBuilder();
    RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, request);
    Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
    Object[] expectedArgs = new Object[] { batchKeys };
    assertEquals(args, expectedArgs);
    verify(descriptor, context, routingResult, request);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) AnnotationSet(com.linkedin.restli.internal.server.model.AnnotationSet) ResourceContext(com.linkedin.restli.server.ResourceContext) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) AnnotationSet(com.linkedin.restli.internal.server.model.AnnotationSet) Annotation(java.lang.annotation.Annotation) RoutingResult(com.linkedin.restli.internal.server.RoutingResult) RestRequest(com.linkedin.r2.message.rest.RestRequest) Parameter(com.linkedin.restli.internal.server.model.Parameter) RestLiRequestData(com.linkedin.restli.server.RestLiRequestData) Test(org.testng.annotations.Test)

Example 20 with RoutingResult

use of com.linkedin.restli.internal.server.RoutingResult 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)

Aggregations

RoutingResult (com.linkedin.restli.internal.server.RoutingResult)93 Test (org.testng.annotations.Test)78 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)66 RestRequest (com.linkedin.r2.message.rest.RestRequest)58 ResourceContext (com.linkedin.restli.server.ResourceContext)39 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)38 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)38 RequestContext (com.linkedin.r2.message.RequestContext)27 RestLiRequestData (com.linkedin.restli.server.RestLiRequestData)24 RestLiResponseData (com.linkedin.restli.server.RestLiResponseData)22 RoutingException (com.linkedin.restli.server.RoutingException)18 ResourceContextImpl (com.linkedin.restli.internal.server.ResourceContextImpl)15 RestLiRouter (com.linkedin.restli.internal.server.RestLiRouter)14 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)13 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)13 HashMap (java.util.HashMap)13 Foo (com.linkedin.pegasus.generator.examples.Foo)11 Parameter (com.linkedin.restli.internal.server.model.Parameter)11 PathKeys (com.linkedin.restli.server.PathKeys)11 URI (java.net.URI)11