Search in sources :

Example 36 with CollectionResponse

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

the class TestPagingProjection method testMetadataAutomaticPagingAutomaticPartialNullIncorrectSingleMetaPagingTotal.

/**
   * Calls the resource method metadataAutomaticPagingAutomaticPartialNullIncorrect with a single metadata field and a single paging
   * field for 'total'.
   */
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testMetadataAutomaticPagingAutomaticPartialNullIncorrectSingleMetaPagingTotal(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    final Request<CollectionResponse<Greeting>> request = builders.findBy("metadataAutomaticPagingAutomaticPartialNullIncorrect").metadataFields(Greeting.fields().message()).pagingFields(CollectionMetadata.fields().total()).build();
    final Response<CollectionResponse<Greeting>> response = getClient().sendRequest(request).getResponse();
    final Greeting metadataGreeting = new Greeting(response.getEntity().getMetadataRaw());
    assertGreeting(metadataGreeting, false, /*hasTone*/
    true, /*hasMessage*/
    false);
    Assert.assertTrue(response.getEntity().hasPaging(), "We must have paging!");
    //Resource method on the server specified null so we shouldn't get anything back
    assertPaging(response.getEntity().getPaging(), false, /*hasTotal*/
    false, /*hasStart*/
    false, /*hasCount*/
    false);
    CollectionMetadata paging = response.getEntity().getPaging();
    final int pagingTotal = paging.getTotal();
    Assert.assertEquals(pagingTotal, 0, "We should still get the default of 0");
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CollectionMetadata(com.linkedin.restli.common.CollectionMetadata) CollectionResponse(com.linkedin.restli.common.CollectionResponse) Test(org.testng.annotations.Test)

Example 37 with CollectionResponse

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

the class TestPagingProjection method testMetadataAutomaticPagingAutomaticPartialNullSingleMetaPagingTotal.

/**
   * Calls the resource method metadataAutomaticPagingAutomaticPartialNull with a single metadata field and a single paging
   * field for 'total'.
   */
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testMetadataAutomaticPagingAutomaticPartialNullSingleMetaPagingTotal(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    final Request<CollectionResponse<Greeting>> request = builders.findBy("metadataAutomaticPagingAutomaticPartialNull").metadataFields(Greeting.fields().message()).pagingFields(CollectionMetadata.fields().total()).build();
    final Response<CollectionResponse<Greeting>> response = getClient().sendRequest(request).getResponse();
    final Greeting metadataGreeting = new Greeting(response.getEntity().getMetadataRaw());
    assertGreeting(metadataGreeting, false, /*hasTone*/
    true, /*hasMessage*/
    false);
    Assert.assertTrue(response.getEntity().hasPaging(), "We must have paging!");
    assertPaging(response.getEntity().getPaging(), true, /*hasTotal*/
    false, /*hasStart*/
    false, /*hasCount*/
    false);
    final int totalCount = response.getEntity().getPaging().getTotal();
    Assert.assertEquals(totalCount, 2, "We must have 2 in our count");
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CollectionResponse(com.linkedin.restli.common.CollectionResponse) Test(org.testng.annotations.Test)

Example 38 with CollectionResponse

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

the class TestPagingProjection method testGetAllMetadataManualPagingAutomaticPartialNull.

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//The following are single tests against individual resource methods
/**
   * Calls the resource method getAllMetadataManualPagingAutomaticPartialNull with a single metadata field and multiple
   * paging fields. This is the only test for this method and used to make sure that the GET_ALL code path within restli
   * for paging projection calculation also works as intended.
   */
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testGetAllMetadataManualPagingAutomaticPartialNull(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    final Request<CollectionResponse<Greeting>> request = builders.getAll().metadataFields(Greeting.fields().message()).pagingFields(CollectionMetadata.fields().total(), CollectionMetadata.fields().count(), CollectionMetadata.fields().links()).build();
    final Response<CollectionResponse<Greeting>> response = getClient().sendRequest(request).getResponse();
    final Greeting metadataGreeting = new Greeting(response.getEntity().getMetadataRaw());
    assertGreeting(metadataGreeting, false, /*hasTone*/
    true, /*hasMessage*/
    true);
    Assert.assertTrue(response.getEntity().hasPaging(), "We must have paging!");
    assertPaging(response.getEntity().getPaging(), true, /*hasTotal*/
    false, /*hasStart*/
    true, /*hasCount*/
    true);
    final int totalCount = response.getEntity().getPaging().getTotal();
    Assert.assertEquals(totalCount, 2, "We must have 2 in our count");
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CollectionResponse(com.linkedin.restli.common.CollectionResponse) Test(org.testng.annotations.Test)

Example 39 with CollectionResponse

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

the class TestPagingProjection method testMetadataAutomaticPagingAutomaticPartialNullNoFields.

/**
   * Calls the resource method metadataAutomaticPagingAutomaticPartialNull without any projection fields specified
   */
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testMetadataAutomaticPagingAutomaticPartialNullNoFields(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    final Request<CollectionResponse<Greeting>> request = builders.findBy("metadataAutomaticPagingAutomaticPartialNull").metadataFields().pagingFields().build();
    final Response<CollectionResponse<Greeting>> response = getClient().sendRequest(request).getResponse();
    final Greeting metadataGreeting = new Greeting(response.getEntity().getMetadataRaw());
    //nothing should be sent back for both below
    assertGreeting(metadataGreeting, false, /*hasTone*/
    false, /*hasMessage*/
    false);
    assertPaging(response.getEntity().getPaging(), false, /*hasTotal*/
    false, /*hasStart*/
    false, /*hasCount*/
    false);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CollectionResponse(com.linkedin.restli.common.CollectionResponse) Test(org.testng.annotations.Test)

Example 40 with CollectionResponse

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

the class TestGreetingsClient method testSearch.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testSearch(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    Request<CollectionResponse<Greeting>> findRequest = builders.findBy("Search").setQueryParam("tone", Tone.FRIENDLY).build();
    List<Greeting> greetings = getClient().sendRequest(findRequest).getResponse().getEntity().getElements();
    for (Greeting g : greetings) {
        Assert.assertEquals(g.getTone(), Tone.FRIENDLY);
        Assert.assertNotNull(g.getMessage());
    }
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CollectionResponse(com.linkedin.restli.common.CollectionResponse) 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