Search in sources :

Example 11 with CollectionResponse

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

the class TestCustomMetadataProjection method testRootManualMetadataAutomaticSingleRootSingleMeta.

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//The following tests operate on the resource method rootManualMetadataAutomatic
/**
   * Calls the resource method rootManualMetadataAutomatic 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 testRootManualMetadataAutomaticSingleRootSingleMeta(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    final Request<CollectionResponse<Greeting>> request = builders.findBy("rootManualMetadataAutomatic").fields(Greeting.fields().message()).metadataFields(Greeting.fields().message()).build();
    final Response<CollectionResponse<Greeting>> response = getClient().sendRequest(request).getResponse();
    //Note the server behavior here is to preserve the tone and the message even though the projection only specified
    //message
    assertEntityElements(response.getEntity().getElements(), true, /*hasTone*/
    true, /*hasMessage*/
    false);
    final Greeting metadataGreeting = new Greeting(response.getEntity().getMetadataRaw());
    assertCustomMetadata(metadataGreeting, false, /*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 12 with CollectionResponse

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

the class TestCustomMetadataProjection method testRootManualMetadataManualSingleRootSingleMeta.

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//The following tests operate on the resource method rootManualMetadataManual
/**
   * Calls the resource method rootManualMetadataManual 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 testRootManualMetadataManualSingleRootSingleMeta(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    final Request<CollectionResponse<Greeting>> request = builders.findBy("rootManualMetadataManual").fields(Greeting.fields().message()).metadataFields(Greeting.fields().message()).build();
    final Response<CollectionResponse<Greeting>> response = getClient().sendRequest(request).getResponse();
    //Note the following for the resulting entity elements and metadata:
    //The resource method should ideally only preserve only the message, but we intentionally also preserve
    //the tone to verify that it is the resource method who performs the projection and not restli
    assertEntityElements(response.getEntity().getElements(), true, /*hasTone*/
    true, /*hasMessage*/
    false);
    final Greeting metadataGreeting = new Greeting(response.getEntity().getMetadataRaw());
    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 13 with CollectionResponse

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

the class TestCustomMetadataProjection method testRootManualMetadataManualAllFields.

/**
   * Calls the resource method rootManualMetadataManual with all custom metadata fields and a single
   * root object entity projection field
   */
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testRootManualMetadataManualAllFields(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    final Request<CollectionResponse<Greeting>> findRequest = builders.findBy("rootManualMetadataManual").fields(Greeting.fields().tone()).metadataFields(Greeting.fields().tone(), Greeting.fields().id(), Greeting.fields().message()).build();
    final Response<CollectionResponse<Greeting>> response = getClient().sendRequest(findRequest).getResponse();
    //Manual projection on the resource method only works if it sees the message field in the projection
    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 14 with CollectionResponse

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

the class TestCustomMetadataProjection method testRootManualMetadataManualNoFields.

/**
   * Calls the resource method rootManualMetadataManual with no fields specified in any projection
   */
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testRootManualMetadataManualNoFields(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    final Request<CollectionResponse<Greeting>> findRequest = builders.findBy("rootManualMetadataManual").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 15 with CollectionResponse

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

the class TestRestLiResponseHandler method testFieldProjection_collections_List.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "basicData")
public void testFieldProjection_collections_List(AcceptTypeData acceptTypeData, ProtocolVersion protocolVersion, String errorResponseHeaderName) throws Exception {
    RestResponse response;
    List<Status> statusCollection = buildStatusListResult(10, "f1", "f2", "f3");
    RestRequest request = buildRequest("/test?fields=f1,f2", acceptTypeData.acceptHeaders, protocolVersion);
    response = _responseHandler.buildResponse(request, buildRoutingResultFinder(request, acceptTypeData.acceptHeaders), statusCollection);
    checkResponse(response, 200, 2, acceptTypeData.responseContentType, CollectionResponse.class.getName(), null, true, errorResponseHeaderName);
    DataMap dataMap = acceptTypeData.dataCodec.readMap(response.getEntity().asInputStream());
    CollectionResponse<Status> collectionResponse = new CollectionResponse<Status>(dataMap, Status.class);
    assertEquals(collectionResponse.getElements().size(), 10);
    for (Status status : collectionResponse.getElements()) {
        assertTrue(status.data().containsKey("f1"));
        assertTrue(status.data().containsKey("f2"));
        assertFalse(status.data().containsKey("f3"));
    }
    // ensure that output status objects were not modified by rest.li!
    Status status1 = statusCollection.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) CollectionResponse(com.linkedin.restli.common.CollectionResponse) DataMap(com.linkedin.data.DataMap) 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