Search in sources :

Example 51 with ResourceMethodDescriptor

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);
}
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 52 with ResourceMethodDescriptor

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

Example 53 with ResourceMethodDescriptor

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;
}
Also used : FieldDef(com.linkedin.data.template.FieldDef) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)

Example 54 with ResourceMethodDescriptor

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);
}
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 55 with ResourceMethodDescriptor

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

Aggregations

ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)195 Test (org.testng.annotations.Test)171 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)140 RestLiTestHelper.buildResourceModel (com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel)116 AfterTest (org.testng.annotations.AfterTest)105 BeforeTest (org.testng.annotations.BeforeTest)105 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)66 PromiseStatusCollectionResource (com.linkedin.restli.server.twitter.PromiseStatusCollectionResource)47 RestRequest (com.linkedin.r2.message.rest.RestRequest)41 ByteString (com.linkedin.data.ByteString)40 AsyncStatusCollectionResource (com.linkedin.restli.server.twitter.AsyncStatusCollectionResource)38 ResourceContext (com.linkedin.restli.server.ResourceContext)37 CustomString (com.linkedin.restli.server.custom.types.CustomString)37 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)31 RestLiCallback (com.linkedin.restli.internal.server.RestLiCallback)27 FilterChainCallback (com.linkedin.restli.internal.server.filter.FilterChainCallback)27 EasyMock.anyObject (org.easymock.EasyMock.anyObject)27 Callback (com.linkedin.common.callback.Callback)26 RequestExecutionCallback (com.linkedin.restli.server.RequestExecutionCallback)26 CustomStatusCollectionResource (com.linkedin.restli.server.twitter.CustomStatusCollectionResource)26