Search in sources :

Example 6 with RoutingResult

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

the class TestUpdateResponseBuilder method testBuilderException.

@Test
public void testBuilderException() {
    UpdateResponse updateResponse = new UpdateResponse(null);
    Map<String, String> headers = ResponseBuilderUtil.getHeaders();
    UpdateResponseBuilder updateResponseBuilder = new UpdateResponseBuilder();
    ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor();
    RoutingResult routingResult = new RoutingResult(null, mockDescriptor);
    try {
        updateResponseBuilder.buildRestLiResponseData(null, routingResult, updateResponse, headers, Collections.<HttpCookie>emptyList());
        Assert.fail("buildRestLiResponseData should have failed because of a null HTTP status!");
    } catch (RestLiServiceException e) {
        Assert.assertTrue(e.getMessage().contains("Unexpected null encountered. HttpStatus is null inside of a UpdateResponse returned by the resource method: "));
    }
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) UpdateResponse(com.linkedin.restli.server.UpdateResponse) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) Test(org.testng.annotations.Test)

Example 7 with RoutingResult

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

the class TestRestLiRouting method testRoutingDetailsSimpleGet.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "routingDetailsSimple")
public void testRoutingDetailsSimpleGet(ProtocolVersion version, String uri) throws Exception {
    Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(TrendingResource.class);
    _router = new RestLiRouter(pathRootResourceMap);
    RestRequest request = createRequest(uri, "GET", version);
    RoutingResult result = _router.process(request, new RequestContext(), null);
    assertNotNull(result);
    ResourceMethodDescriptor resourceMethodDescriptor = result.getResourceMethod();
    assertNotNull(resourceMethodDescriptor);
    assertEquals(resourceMethodDescriptor.getType(), ResourceMethod.GET);
    assertNull(resourceMethodDescriptor.getActionName());
    assertNull(resourceMethodDescriptor.getFinderName());
    assertEquals(resourceMethodDescriptor.getMethod().getDeclaringClass(), TrendingResource.class);
    assertEquals(resourceMethodDescriptor.getMethod().getName(), "get");
    assertEquals(resourceMethodDescriptor.getMethod().getParameterTypes(), new Class<?>[] {});
    assertEquals(resourceMethodDescriptor.getResourceModel().getName(), "trending");
    assertNotNull(result.getContext());
    PathKeys keys = result.getContext().getPathKeys();
    assertNull(keys.getBatchIds());
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) PathKeys(com.linkedin.restli.server.PathKeys) RestLiRouter(com.linkedin.restli.internal.server.RestLiRouter) RestRequest(com.linkedin.r2.message.rest.RestRequest) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RequestContext(com.linkedin.r2.message.RequestContext) Test(org.testng.annotations.Test)

Example 8 with RoutingResult

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

the class TestRestLiRouting method testRoutingDetailsCollectionUpdate.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "routingDetailsCollectionEntity")
public void testRoutingDetailsCollectionUpdate(ProtocolVersion version, String uri) throws Exception {
    Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(StatusCollectionResource.class);
    _router = new RestLiRouter(pathRootResourceMap);
    RestRequest request = createRequest(uri, "PUT", version);
    RoutingResult result = _router.process(request, new RequestContext(), null);
    assertNotNull(result);
    ResourceMethodDescriptor resourceMethodDescriptor = result.getResourceMethod();
    assertNotNull(resourceMethodDescriptor);
    assertEquals(resourceMethodDescriptor.getType(), ResourceMethod.UPDATE);
    assertNull(resourceMethodDescriptor.getActionName());
    assertNull(resourceMethodDescriptor.getFinderName());
    assertEquals(resourceMethodDescriptor.getMethod().getDeclaringClass(), StatusCollectionResource.class);
    assertEquals(resourceMethodDescriptor.getMethod().getName(), "update");
    assertEquals(resourceMethodDescriptor.getMethod().getParameterTypes(), new Class<?>[] { Long.class, Status.class });
    assertEquals(resourceMethodDescriptor.getResourceModel().getName(), "statuses");
    assertNotNull(result.getContext());
    PathKeys keys = result.getContext().getPathKeys();
    assertEquals(keys.getAsLong("statusID"), new Long(1));
    assertNull(keys.getAsString("foo"));
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) PathKeys(com.linkedin.restli.server.PathKeys) RestLiRouter(com.linkedin.restli.internal.server.RestLiRouter) RestRequest(com.linkedin.r2.message.rest.RestRequest) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RequestContext(com.linkedin.r2.message.RequestContext) Test(org.testng.annotations.Test)

Example 9 with RoutingResult

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

the class TestBatchCreateResponseBuilder method testCreateResultBuilder.

@Test(dataProvider = "createResultBuilderTestData")
@SuppressWarnings("unchecked")
public void testCreateResultBuilder(String altKeyName, Map<String, AlternativeKey<?, ?>> alternativeKeyMap, List<CreateIdStatus<Object>> expectedStatuses) {
    List<CreateResponse> createResponses = Arrays.asList(new CreateResponse(1L), new CreateResponse(2L));
    BatchCreateResult<Long, Foo> results = new BatchCreateResult<Long, Foo>(createResponses);
    Map<String, String> headers = ResponseBuilderUtil.getHeaders();
    ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor(alternativeKeyMap);
    ResourceContext mockContext = getMockResourceContext(altKeyName);
    RoutingResult routingResult = new RoutingResult(mockContext, mockDescriptor);
    BatchCreateResponseBuilder responseBuilder = new BatchCreateResponseBuilder(null);
    RestLiResponseData responseData = responseBuilder.buildRestLiResponseData(null, routingResult, results, headers, Collections.<HttpCookie>emptyList());
    PartialRestResponse restResponse = responseBuilder.buildResponse(routingResult, responseData);
    EasyMock.verify(mockDescriptor);
    ResponseBuilderUtil.validateHeaders(restResponse, headers);
    Assert.assertFalse(responseData.getBatchCreateResponseEnvelope().isGetAfterCreate());
    List<com.linkedin.restli.common.CreateIdStatus<Object>> items = new ArrayList<CreateIdStatus<Object>>();
    for (BatchCreateResponseEnvelope.CollectionCreateResponseItem item : responseData.getBatchCreateResponseEnvelope().getCreateResponses()) {
        items.add((CreateIdStatus<Object>) item.getRecord());
    }
    Assert.assertEquals(restResponse.getEntity(), new BatchCreateIdResponse<Object>(items));
    Assert.assertEquals(expectedStatuses, items);
    Assert.assertEquals(restResponse.getStatus(), HttpStatus.S_200_OK);
}
Also used : ResourceContext(com.linkedin.restli.server.ResourceContext) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) CreateResponse(com.linkedin.restli.server.CreateResponse) Foo(com.linkedin.pegasus.generator.examples.Foo) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) RestLiResponseData(com.linkedin.restli.server.RestLiResponseData) ArrayList(java.util.ArrayList) CreateIdStatus(com.linkedin.restli.common.CreateIdStatus) RoutingResult(com.linkedin.restli.internal.server.RoutingResult) BatchCreateResult(com.linkedin.restli.server.BatchCreateResult) Test(org.testng.annotations.Test)

Example 10 with RoutingResult

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

the class TestBatchCreateResponseBuilder method testBuilderExceptions.

@Test(dataProvider = "exceptionTestData")
public void testBuilderExceptions(Object result, String expectedErrorMessage) {
    Map<String, String> headers = ResponseBuilderUtil.getHeaders();
    ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor(null);
    ResourceContext mockContext = getMockResourceContext(null);
    RoutingResult routingResult = new RoutingResult(mockContext, mockDescriptor);
    BatchCreateResponseBuilder responseBuilder = new BatchCreateResponseBuilder(null);
    try {
        responseBuilder.buildRestLiResponseData(null, routingResult, result, headers, Collections.<HttpCookie>emptyList());
        Assert.fail("buildRestLiResponseData should have thrown an exception because of null elements");
    } catch (RestLiServiceException e) {
        Assert.assertTrue(e.getMessage().contains(expectedErrorMessage));
    }
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) ResourceContext(com.linkedin.restli.server.ResourceContext) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) 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