Search in sources :

Example 91 with Request

use of com.linkedin.r2.message.Request in project rest.li by linkedin.

the class TestRestLiResponseHandler method testFieldProjection_batch.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "basicDataWithBatchUri")
public void testFieldProjection_batch(AcceptTypeData acceptTypeData, ProtocolVersion protocolVersion, String uri, String errorResponseHeaderName) throws Exception {
    RestResponse response;
    Map<Integer, Status> statusBatch = buildStatusBatchResponse(10, "f1", "f2", "f3");
    RestRequest request = buildRequest(uri, acceptTypeData.acceptHeaders, protocolVersion);
    response = _responseHandler.buildResponse(request, buildRoutingResult(ResourceMethod.BATCH_GET, request, acceptTypeData.acceptHeaders), statusBatch);
    checkResponse(response, 200, 2, acceptTypeData.responseContentType, BatchResponse.class.getName(), Status.class.getName(), true, errorResponseHeaderName);
    DataMap dataMap = acceptTypeData.dataCodec.readMap(response.getEntity().asInputStream());
    BatchResponse<Status> batchResponse = new BatchResponse<Status>(dataMap, Status.class);
    assertEquals(batchResponse.getResults().size(), 10);
    for (Status status : batchResponse.getResults().values()) {
        assertTrue(status.data().containsKey("f1"));
        assertTrue(status.data().containsKey("f2"));
        assertFalse(status.data().containsKey("f3"));
    }
    // ensure that output map was not modified by rest.li!
    Status status1 = statusBatch.get(1);
    assertNotNull(status1);
    assertTrue(status1.data().containsKey("f3"));
}
Also used : UpdateStatus(com.linkedin.restli.common.UpdateStatus) CreateStatus(com.linkedin.restli.common.CreateStatus) Status(com.linkedin.restli.server.twitter.TwitterTestDataModels.Status) HttpStatus(com.linkedin.restli.common.HttpStatus) RestRequest(com.linkedin.r2.message.rest.RestRequest) RestResponse(com.linkedin.r2.message.rest.RestResponse) PartialRestResponse(com.linkedin.restli.internal.server.response.PartialRestResponse) BatchResponse(com.linkedin.restli.common.BatchResponse) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 92 with Request

use of com.linkedin.r2.message.Request in project rest.li by linkedin.

the class TestRestLiResponseHandler method testRestLiResponseData.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "statusActionDataPartial")
public void testRestLiResponseData(AcceptTypeData acceptTypeData, String response1, String response2, ProtocolVersion protocolVersion, String errorResponseHeaderName) throws Exception {
    final RestRequest request = buildRequest(acceptTypeData.acceptHeaders, protocolVersion);
    RestLiResponseData responseData;
    RoutingResult routingResult1 = buildRoutingResultAction(Status.class, request, acceptTypeData.acceptHeaders);
    // #1 simple record template
    responseData = _responseHandler.buildRestLiResponseData(request, routingResult1, buildStatusRecord());
    checkResponseData(responseData, HttpStatus.S_200_OK, 1, false, true, errorResponseHeaderName);
    assertEquals(responseData.getRecordResponseEnvelope().getRecord().toString(), response1);
    // #2 DataTemplate response
    StringMap map = new StringMap();
    map.put("key1", "value1");
    map.put("key2", "value2");
    RoutingResult routingResult2 = buildRoutingResultAction(StringMap.class, request, acceptTypeData.acceptHeaders);
    responseData = _responseHandler.buildRestLiResponseData(request, routingResult2, map);
    checkResponseData(responseData, HttpStatus.S_200_OK, 1, false, true, errorResponseHeaderName);
    //Obtain the maps necessary for comparison
    final DataMap actualMap;
    final DataMap expectedMap;
    actualMap = responseData.getRecordResponseEnvelope().getRecord().data();
    expectedMap = JACKSON_DATA_CODEC.stringToMap(response2);
    assertEquals(actualMap, expectedMap);
    RoutingResult routingResult3 = buildRoutingResultAction(Void.TYPE, request, acceptTypeData.acceptHeaders);
    // #3 empty response
    responseData = _responseHandler.buildRestLiResponseData(request, routingResult3, null);
    checkResponseData(responseData, HttpStatus.S_200_OK, 1, false, false, errorResponseHeaderName);
    assertEquals(responseData.getRecordResponseEnvelope().getRecord(), null);
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) StringMap(com.linkedin.data.template.StringMap) RestRequest(com.linkedin.r2.message.rest.RestRequest) RestLiResponseData(com.linkedin.restli.server.RestLiResponseData) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 93 with Request

use of com.linkedin.r2.message.Request in project rest.li by linkedin.

the class TestRestLiRouting method testDefaultPathKeyUniqueness.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "uniqueness")
public void testDefaultPathKeyUniqueness(ProtocolVersion version, String uri) throws Exception {
    Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(CombinedResources.CombinedCollectionWithSubresources.class, CombinedResources.SubCollectionResource.class);
    _router = new RestLiRouter(pathRootResourceMap);
    RestRequest request;
    RoutingResult result;
    // #1 simple GET
    request = createRequest(uri, "GET", version);
    result = _router.process(request, new RequestContext(), null);
    assertNotNull(result);
    PathKeys keys = result.getContext().getPathKeys();
    assertEquals(keys.getAsString("testId"), "foo");
    assertEquals(keys.getAsString("subId"), "bar");
}
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) CombinedResources(com.linkedin.restli.server.combined.CombinedResources) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RequestContext(com.linkedin.r2.message.RequestContext) Test(org.testng.annotations.Test)

Example 94 with Request

use of com.linkedin.r2.message.Request in project rest.li by linkedin.

the class TestRestLiRouting method testActionNestedRouting.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "actionNestedRouting")
public void testActionNestedRouting(ProtocolVersion version, String uri) throws Exception {
    Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(StatusCollectionResource.class, RepliesCollectionResource.class);
    _router = new RestLiRouter(pathRootResourceMap);
    RestRequest request = createRequest(uri, "POST", version);
    RoutingResult result = _router.process(request, new RequestContext(), null);
    assertNotNull(result);
    assertEquals(result.getResourceMethod().getActionName(), "replyToAll");
    assertEquals(result.getResourceMethod().getType(), ResourceMethod.ACTION);
    assertEquals(result.getContext().getPathKeys().get("statusID"), Long.valueOf(1));
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) RestLiRouter(com.linkedin.restli.internal.server.RestLiRouter) RestRequest(com.linkedin.r2.message.rest.RestRequest) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RequestContext(com.linkedin.r2.message.RequestContext) Test(org.testng.annotations.Test)

Example 95 with Request

use of com.linkedin.r2.message.Request in project rest.li by linkedin.

the class TestRestLiRouting method testRoutingDetailsSimpleDelete.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "routingDetailsSimple")
public void testRoutingDetailsSimpleDelete(ProtocolVersion version, String uri) throws Exception {
    Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(TrendingResource.class);
    _router = new RestLiRouter(pathRootResourceMap);
    RestRequest request = createRequest(uri, "DELETE", version);
    RoutingResult result = _router.process(request, new RequestContext(), null);
    assertNotNull(result);
    ResourceMethodDescriptor resourceMethodDescriptor = result.getResourceMethod();
    assertNotNull(resourceMethodDescriptor);
    assertEquals(resourceMethodDescriptor.getType(), ResourceMethod.DELETE);
    assertNull(resourceMethodDescriptor.getActionName());
    assertNull(resourceMethodDescriptor.getFinderName());
    assertEquals(resourceMethodDescriptor.getMethod().getDeclaringClass(), TrendingResource.class);
    assertEquals(resourceMethodDescriptor.getMethod().getName(), "delete");
    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)

Aggregations

Test (org.testng.annotations.Test)209 RestRequest (com.linkedin.r2.message.rest.RestRequest)189 RequestContext (com.linkedin.r2.message.RequestContext)124 URI (java.net.URI)112 RestResponse (com.linkedin.r2.message.rest.RestResponse)111 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)105 ByteString (com.linkedin.data.ByteString)67 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)61 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)59 RestException (com.linkedin.r2.message.rest.RestException)54 StreamResponse (com.linkedin.r2.message.stream.StreamResponse)50 StreamRequestBuilder (com.linkedin.r2.message.stream.StreamRequestBuilder)47 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)44 FutureCallback (com.linkedin.common.callback.FutureCallback)41 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)38 HashMap (java.util.HashMap)38 Callback (com.linkedin.common.callback.Callback)34 FilterRequestContext (com.linkedin.restli.server.filter.FilterRequestContext)34 ExecutionException (java.util.concurrent.ExecutionException)33 BeforeTest (org.testng.annotations.BeforeTest)31