Search in sources :

Example 1 with RoutingResult

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

the class RestLiArgumentBuilderTestHelper method getMockRoutingResult.

public static RoutingResult getMockRoutingResult(ResourceMethodDescriptor descriptor, int getResourceMethodCount, ResourceContext context, int getContextCount) {
    RoutingResult mockRoutingResult = createMock(RoutingResult.class);
    if (descriptor != null) {
        expect(mockRoutingResult.getResourceMethod()).andReturn(descriptor).times(getResourceMethodCount);
    }
    if (context != null) {
        expect(mockRoutingResult.getContext()).andReturn(context).times(getContextCount);
    }
    replay(mockRoutingResult);
    return mockRoutingResult;
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult)

Example 2 with RoutingResult

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

the class TestBatchUpdateResponseBuilder method testUpdateStatusInstantiation.

@Test(dataProvider = "updateStatusInstantiation")
public void testUpdateStatusInstantiation(RestLiResponseData responseData, UpdateStatus expectedResult) {
    ResourceContext mockContext = getMockResourceContext(AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), null);
    ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor(null);
    RoutingResult routingResult = new RoutingResult(mockContext, mockDescriptor);
    PartialRestResponse response = new BatchUpdateResponseBuilder(new ErrorResponseBuilder()).buildResponse(routingResult, responseData);
    Assert.assertEquals(((BatchResponse) response.getEntity()).getResults().get("key"), expectedResult);
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) ResourceContext(com.linkedin.restli.server.ResourceContext) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) BatchResponse(com.linkedin.restli.common.BatchResponse) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) Test(org.testng.annotations.Test)

Example 3 with RoutingResult

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

the class TestBatchUpdateResponseBuilder method unsupportedNullKeyMapTest.

/* Note that we use also need to test using java.util.concurrent.ConcurrentHashMap. This is because rest.li checks
  * for the presence of nulls returned from maps which are returned from resource methods. The checking for nulls
  * is prone to a NullPointerException since contains(null) can throw an NPE from certain map implementations such as
  * java.util.concurrent.ConcurrentHashMap. We want to make sure our check for the presence of nulls is done in a
  * way that doesn't throw an NullPointerException.
  */
@Test(dataProvider = "unsupportedNullKeyMapData")
@SuppressWarnings("unchecked")
public void unsupportedNullKeyMapTest(Object results, ProtocolVersion protocolVersion, Map<String, UpdateStatus> expectedResults) {
    ResourceContext mockContext = getMockResourceContext(protocolVersion, null);
    ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor(null);
    RoutingResult routingResult = new RoutingResult(mockContext, mockDescriptor);
    Map<String, String> headers = ResponseBuilderUtil.getHeaders();
    BatchUpdateResponseBuilder batchUpdateResponseBuilder = new BatchUpdateResponseBuilder(new ErrorResponseBuilder());
    RestLiResponseData responseData = batchUpdateResponseBuilder.buildRestLiResponseData(null, routingResult, results, headers, Collections.<HttpCookie>emptyList());
    PartialRestResponse restResponse = batchUpdateResponseBuilder.buildResponse(routingResult, responseData);
    BatchResponse<UpdateStatus> batchResponse = (BatchResponse<UpdateStatus>) restResponse.getEntity();
    EasyMock.verify(mockContext, mockDescriptor);
    ResponseBuilderUtil.validateHeaders(restResponse, headers);
    Assert.assertEquals(batchResponse.getResults(), expectedResults);
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) ResourceContext(com.linkedin.restli.server.ResourceContext) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) UpdateStatus(com.linkedin.restli.common.UpdateStatus) BatchResponse(com.linkedin.restli.common.BatchResponse) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) RestLiResponseData(com.linkedin.restli.server.RestLiResponseData) Test(org.testng.annotations.Test)

Example 4 with RoutingResult

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

the class TestCreateResponseBuilder method testProjectionInBuildRestliResponseData.

@Test
public void testProjectionInBuildRestliResponseData() throws URISyntaxException {
    MaskTree maskTree = new MaskTree();
    maskTree.addOperation(new PathSpec("fruitsField"), MaskOperation.POSITIVE_MASK_OP);
    ServerResourceContext mockContext = EasyMock.createMock(ServerResourceContext.class);
    EasyMock.expect(mockContext.getProjectionMask()).andReturn(maskTree);
    EasyMock.expect(mockContext.getProjectionMode()).andReturn(ProjectionMode.AUTOMATIC);
    EasyMock.replay(mockContext);
    RoutingResult routingResult = new RoutingResult(mockContext, null);
    Foo value = new Foo().setStringField("value").setFruitsField(Fruits.APPLE);
    CreateKVResponse<Integer, Foo> values = new CreateKVResponse<Integer, Foo>(null, value);
    CreateResponseBuilder responseBuilder = new CreateResponseBuilder();
    RestLiResponseData envelope = responseBuilder.buildRestLiResponseData(new RestRequestBuilder(new URI("/foo")).build(), routingResult, values, Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList());
    RecordTemplate record = envelope.getRecordResponseEnvelope().getRecord();
    Assert.assertEquals(record.data().size(), 1);
    Assert.assertEquals(record.data().get("fruitsField"), Fruits.APPLE.toString());
    Assert.assertTrue(envelope.getCreateResponseEnvelope().isGetAfterCreate());
    EasyMock.verify(mockContext);
}
Also used : Foo(com.linkedin.pegasus.generator.examples.Foo) RestLiResponseData(com.linkedin.restli.server.RestLiResponseData) PathSpec(com.linkedin.data.schema.PathSpec) URI(java.net.URI) RoutingResult(com.linkedin.restli.internal.server.RoutingResult) MaskTree(com.linkedin.data.transform.filter.request.MaskTree) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) RecordTemplate(com.linkedin.data.template.RecordTemplate) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) CreateKVResponse(com.linkedin.restli.server.CreateKVResponse) Test(org.testng.annotations.Test)

Example 5 with RoutingResult

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

Aggregations

RoutingResult (com.linkedin.restli.internal.server.RoutingResult)114 Test (org.testng.annotations.Test)89 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)72 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)71 RestRequest (com.linkedin.r2.message.rest.RestRequest)56 RestLiRequestData (com.linkedin.restli.server.RestLiRequestData)29 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)28 RequestContext (com.linkedin.r2.message.RequestContext)24 ResourceContextImpl (com.linkedin.restli.internal.server.ResourceContextImpl)20 URI (java.net.URI)20 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)19 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)18 RoutingException (com.linkedin.restli.server.RoutingException)18 HashMap (java.util.HashMap)17 DataMap (com.linkedin.data.DataMap)16 Foo (com.linkedin.pegasus.generator.examples.Foo)16 RestLiResponse (com.linkedin.restli.internal.server.response.RestLiResponse)14 Parameter (com.linkedin.restli.internal.server.model.Parameter)12 RestLiTestHelper.buildResourceModel (com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel)11 Callback (com.linkedin.common.callback.Callback)10