Search in sources :

Example 81 with CollectionResponse

use of com.linkedin.restli.common.CollectionResponse in project rest.li by linkedin.

the class TestCustomMetadataProjection method testRootAutomaticMetadataAutomaticNoFields.

/**
   * Calls the resource method rootAutomaticMetadataAutomatic with no fields specified in any projection
   */
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testRootAutomaticMetadataAutomaticNoFields(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    final Request<CollectionResponse<Greeting>> findRequest = builders.findBy("rootAutomaticMetadataAutomatic").build();
    final Response<CollectionResponse<Greeting>> response = getClient().sendRequest(findRequest).getResponse();
    assertEntityElements(response.getEntity().getElements(), true, /*hasTone*/
    true, /*hasMessage*/
    true);
    final Greeting metadataGreeting = new Greeting(response.getEntity().getMetadataRaw());
    assertCustomMetadata(metadataGreeting, true, /*hasTone*/
    true, /*hasMessage*/
    true);
    Assert.assertTrue(response.getEntity().hasPaging(), "We must have paging!");
    assertAllPagingFieldsExist(response.getEntity().getPaging());
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CollectionResponse(com.linkedin.restli.common.CollectionResponse) Test(org.testng.annotations.Test)

Example 82 with CollectionResponse

use of com.linkedin.restli.common.CollectionResponse in project rest.li by linkedin.

the class TestCustomMetadataProjection method testRootAutomaticMetadataManualSingleRootSingleMeta.

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//The following tests operate on the resource method rootAutomaticMetadataManual
/**
   * Calls the resource method rootAutomaticMetadataManual with a single metadata field and a single root object
   * entity field
   */
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testRootAutomaticMetadataManualSingleRootSingleMeta(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    final Request<CollectionResponse<Greeting>> request = builders.findBy("rootAutomaticMetadataManual").fields(Greeting.fields().tone()).metadataFields(Greeting.fields().message()).build();
    final Response<CollectionResponse<Greeting>> response = getClient().sendRequest(request).getResponse();
    assertEntityElements(response.getEntity().getElements(), true, /*hasTone*/
    false, /*hasMessage*/
    false);
    final Greeting metadataGreeting = new Greeting(response.getEntity().getMetadataRaw());
    //Note that the server here will intentionally leave the tone in the greeting
    assertCustomMetadata(metadataGreeting, true, /*hasTone*/
    true, /*hasMessage*/
    false);
    Assert.assertTrue(response.getEntity().hasPaging(), "We must have paging!");
    assertAllPagingFieldsExist(response.getEntity().getPaging());
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CollectionResponse(com.linkedin.restli.common.CollectionResponse) Test(org.testng.annotations.Test)

Example 83 with CollectionResponse

use of com.linkedin.restli.common.CollectionResponse in project rest.li by linkedin.

the class TestCustomMetadataProjection method testRootAutomaticMetadataManualNoFields.

/**
   * Calls the resource method rootAutomaticMetadataManual with no fields specified in any projection
   */
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testRootAutomaticMetadataManualNoFields(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    final Request<CollectionResponse<Greeting>> findRequest = builders.findBy("rootAutomaticMetadataManual").build();
    final Response<CollectionResponse<Greeting>> response = getClient().sendRequest(findRequest).getResponse();
    assertEntityElements(response.getEntity().getElements(), true, /*hasTone*/
    true, /*hasMessage*/
    true);
    final Greeting metadataGreeting = new Greeting(response.getEntity().getMetadataRaw());
    //Note here the resource method is doing manual projection, but not removing anything, so we should get all
    //the fields back
    assertCustomMetadata(metadataGreeting, true, /*hasTone*/
    true, /*hasMessage*/
    true);
    Assert.assertTrue(response.getEntity().hasPaging(), "We must have paging!");
    assertAllPagingFieldsExist(response.getEntity().getPaging());
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CollectionResponse(com.linkedin.restli.common.CollectionResponse) Test(org.testng.annotations.Test)

Example 84 with CollectionResponse

use of com.linkedin.restli.common.CollectionResponse in project rest.li by linkedin.

the class TestGreetingClientContentTypes method testFinder.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "clientDataDataProvider")
public void testFinder(RestClient restClient, RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    Request<CollectionResponse<Greeting>> request = builders.findBy("Search").setQueryParam("tone", Tone.SINCERE).paginate(1, 2).build();
    Response<CollectionResponse<Greeting>> response = restClient.sendRequest(request).getResponse();
    CollectionResponse<Greeting> collectionResponse = response.getEntity();
    List<Greeting> greetings = collectionResponse.getElements();
    for (Greeting g : greetings) {
        Assert.assertEquals(g.getTone(), Tone.SINCERE);
    }
    collectionResponse.getPaging().getLinks();
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CollectionResponse(com.linkedin.restli.common.CollectionResponse) Test(org.testng.annotations.Test)

Example 85 with CollectionResponse

use of com.linkedin.restli.common.CollectionResponse in project rest.li by linkedin.

the class TestCollectionResponseBuilder method testBuilder.

@SuppressWarnings("unchecked")
@Test(dataProvider = "testData")
public void testBuilder(Object results, DataMap expectedMetadata, List<Foo> expectedElements, CollectionMetadata expectedPaging, MaskTree dataMaskTree, MaskTree metaDataMaskTree, MaskTree pagingMaskTree, ProjectionMode dataProjectionMode, ProjectionMode metadataProjectionMode) throws URISyntaxException {
    for (ResourceMethod resourceMethod : Arrays.asList(ResourceMethod.GET_ALL, ResourceMethod.FINDER)) {
        Map<String, String> headers = ResponseBuilderUtil.getHeaders();
        ResourceContext mockContext = getMockResourceContext(dataMaskTree, metaDataMaskTree, pagingMaskTree, dataProjectionMode, metadataProjectionMode);
        ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor(resourceMethod);
        RoutingResult routingResult = new RoutingResult(mockContext, mockDescriptor);
        CollectionResponseBuilder responseBuilder = new CollectionResponseBuilder();
        RestLiResponseData responseData = responseBuilder.buildRestLiResponseData(getRestRequest(), routingResult, results, headers, Collections.<HttpCookie>emptyList());
        PartialRestResponse restResponse = responseBuilder.buildResponse(routingResult, responseData);
        EasyMock.verify(mockContext, mockDescriptor);
        ResponseBuilderUtil.validateHeaders(restResponse, headers);
        CollectionResponse<Foo> actualResults = (CollectionResponse<Foo>) restResponse.getEntity();
        Assert.assertEquals(actualResults.getElements(), expectedElements);
        Assert.assertEquals(actualResults.getMetadataRaw(), expectedMetadata);
        Assert.assertEquals(actualResults.getPaging(), expectedPaging);
        EasyMock.verify(mockContext);
    }
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) ResourceContext(com.linkedin.restli.server.ResourceContext) CollectionResponse(com.linkedin.restli.common.CollectionResponse) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) Foo(com.linkedin.pegasus.generator.examples.Foo) RestLiResponseData(com.linkedin.restli.server.RestLiResponseData) ResourceMethod(com.linkedin.restli.common.ResourceMethod) Test(org.testng.annotations.Test)

Aggregations

CollectionResponse (com.linkedin.restli.common.CollectionResponse)85 Test (org.testng.annotations.Test)77 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)58 CreateStatus (com.linkedin.restli.common.CreateStatus)11 ArrayList (java.util.ArrayList)7 DataMap (com.linkedin.data.DataMap)6 CollectionMetadata (com.linkedin.restli.common.CollectionMetadata)6 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)5 CreateIdStatus (com.linkedin.restli.common.CreateIdStatus)5 UpdateStatus (com.linkedin.restli.common.UpdateStatus)5 HttpStatus (com.linkedin.restli.common.HttpStatus)4 CustomLong (com.linkedin.restli.examples.custom.types.CustomLong)4 ValidationDemo (com.linkedin.restli.examples.greetings.api.ValidationDemo)4 RootBuilderWrapper (com.linkedin.restli.test.util.RootBuilderWrapper)4 HashMap (java.util.HashMap)4 RestResponse (com.linkedin.r2.message.rest.RestResponse)3 Link (com.linkedin.restli.common.Link)3 Message (com.linkedin.restli.examples.greetings.api.Message)3 AutoValidationWithProjectionBuilders (com.linkedin.restli.examples.greetings.client.AutoValidationWithProjectionBuilders)3 URIDetails (com.linkedin.restli.internal.testutils.URIDetails)3