Search in sources :

Example 36 with Greeting

use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.

the class TestCustomMetadataProjection method testGetAllRootAutomaticMetadataManual.

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//The following are single tests against individual resource methods
/**
   * Calls the resource method getAllRootAutomaticMetadataManual with a single metadata field and a single root object
   * entity field. This is the only test for this method and used to make sure that the GET_ALL code path within restli
   * for metadata projection calculation also works as intended.
   */
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testGetAllRootAutomaticMetadataManual(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    final Request<CollectionResponse<Greeting>> request = builders.getAll().fields(Greeting.fields().message()).metadataFields(Greeting.fields().message()).build();
    final Response<CollectionResponse<Greeting>> response = getClient().sendRequest(request).getResponse();
    //Since restli does the projection here for the root entity records, only the message field will exist
    assertEntityElements(response.getEntity().getElements(), false, /*hasTone*/
    true, /*hasMessage*/
    false);
    final Greeting metadataGreeting = new Greeting(response.getEntity().getMetadataRaw());
    //Since the resource method does the projection here for the meta data, the message and the tone will both
    //exist since the resource method intentionally chooses to preserve both.
    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 37 with Greeting

use of com.linkedin.restli.examples.greetings.api.Greeting 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 38 with Greeting

use of com.linkedin.restli.examples.greetings.api.Greeting 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 39 with Greeting

use of com.linkedin.restli.examples.greetings.api.Greeting 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 40 with Greeting

use of com.linkedin.restli.examples.greetings.api.Greeting 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)

Aggregations

Greeting (com.linkedin.restli.examples.greetings.api.Greeting)250 Test (org.testng.annotations.Test)195 CollectionResponse (com.linkedin.restli.common.CollectionResponse)59 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)33 EmptyRecord (com.linkedin.restli.common.EmptyRecord)33 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)20 CustomLong (com.linkedin.restli.examples.custom.types.CustomLong)20 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)18 BatchCreateIdResponse (com.linkedin.restli.common.BatchCreateIdResponse)12 EntityResponse (com.linkedin.restli.common.EntityResponse)12 BatchResponse (com.linkedin.restli.common.BatchResponse)11 RestLiIntegrationTest (com.linkedin.restli.examples.RestLiIntegrationTest)11 IdResponse (com.linkedin.restli.common.IdResponse)10 GreetingsRequestBuilders (com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders)10 GreetingsBuilders (com.linkedin.restli.examples.greetings.client.GreetingsBuilders)9 ConsistentHashKeyMapper (com.linkedin.d2.balancer.util.hashing.ConsistentHashKeyMapper)8 Response (com.linkedin.restli.client.Response)8 CreateIdStatus (com.linkedin.restli.common.CreateIdStatus)8 ErrorResponse (com.linkedin.restli.common.ErrorResponse)8