Search in sources :

Example 1 with BatchfindersRequestBuilders

use of com.linkedin.restli.examples.greetings.client.BatchfindersRequestBuilders in project rest.li by linkedin.

the class TestBatchFinderResource method testUsingResourceSpecificBuilderWithProjection.

@Test
public void testUsingResourceSpecificBuilderWithProjection() throws RemoteInvocationException {
    GreetingCriteria c1 = new GreetingCriteria().setId(1L).setTone(Tone.SINCERE);
    GreetingCriteria c2 = new GreetingCriteria().setId(2L).setTone(Tone.FRIENDLY);
    GreetingCriteria c3 = new GreetingCriteria().setId(100);
    Request<BatchCollectionResponse<Greeting>> req = new BatchfindersRequestBuilders().batchFindBySearchGreetings().criteriaParam(Arrays.asList(c1, c2, c3)).fields(Greeting.fields().tone()).messageParam("hello world").build();
    Response<BatchCollectionResponse<Greeting>> resp = REST_CLIENT.sendRequest(req).getResponse();
    BatchCollectionResponse<Greeting> response = resp.getEntity();
    List<BatchFinderCriteriaResult<Greeting>> batchResult = response.getResults();
    Assert.assertEquals(batchResult.size(), 3);
    // on success
    List<Greeting> greetings1 = batchResult.get(0).getElements();
    Assert.assertTrue(greetings1.get(0).hasTone());
    Assert.assertTrue(greetings1.get(0).getTone().equals(Tone.SINCERE));
    Assert.assertFalse(greetings1.get(0).hasId());
    List<Greeting> greetings2 = batchResult.get(1).getElements();
    Assert.assertTrue(greetings2.get(0).hasTone());
    Assert.assertTrue(greetings2.get(0).getTone().equals(Tone.FRIENDLY));
    Assert.assertFalse(greetings2.get(0).hasId());
    // on error
    ErrorResponse error = batchResult.get(2).getError();
    Assert.assertTrue(batchResult.get(2).isError());
    Assert.assertEquals(error.getMessage(), "Fail to find Greeting!");
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) BatchFinderCriteriaResult(com.linkedin.restli.common.BatchFinderCriteriaResult) BatchCollectionResponse(com.linkedin.restli.common.BatchCollectionResponse) BatchfindersRequestBuilders(com.linkedin.restli.examples.greetings.client.BatchfindersRequestBuilders) GreetingCriteria(com.linkedin.restli.examples.greetings.api.GreetingCriteria) ErrorResponse(com.linkedin.restli.common.ErrorResponse) Test(org.testng.annotations.Test)

Example 2 with BatchfindersRequestBuilders

use of com.linkedin.restli.examples.greetings.client.BatchfindersRequestBuilders in project rest.li by linkedin.

the class TestBatchFinderResource method testUsingResourceSpecificBuilder.

@Test
public void testUsingResourceSpecificBuilder() throws RemoteInvocationException {
    GreetingCriteria c1 = new GreetingCriteria().setId(1L).setTone(Tone.SINCERE);
    GreetingCriteria c2 = new GreetingCriteria().setId(2L).setTone(Tone.FRIENDLY);
    GreetingCriteria c3 = new GreetingCriteria().setId(100);
    Request<BatchCollectionResponse<Greeting>> req = new BatchfindersRequestBuilders().batchFindBySearchGreetings().criteriaParam(Arrays.asList(c1, c2, c3)).messageParam("hello world").build();
    Response<BatchCollectionResponse<Greeting>> resp = REST_CLIENT.sendRequest(req).getResponse();
    BatchCollectionResponse<Greeting> response = resp.getEntity();
    List<BatchFinderCriteriaResult<Greeting>> batchResult = response.getResults();
    Assert.assertEquals(batchResult.size(), 3);
    // on success
    List<Greeting> greetings1 = batchResult.get(0).getElements();
    Assert.assertTrue(greetings1.get(0).hasTone());
    Assert.assertTrue(greetings1.get(0).getTone().equals(Tone.SINCERE));
    // on error
    ErrorResponse error = batchResult.get(2).getError();
    Assert.assertTrue(batchResult.get(2).isError());
    Assert.assertEquals(error.getMessage(), "Fail to find Greeting!");
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) BatchFinderCriteriaResult(com.linkedin.restli.common.BatchFinderCriteriaResult) BatchCollectionResponse(com.linkedin.restli.common.BatchCollectionResponse) BatchfindersRequestBuilders(com.linkedin.restli.examples.greetings.client.BatchfindersRequestBuilders) GreetingCriteria(com.linkedin.restli.examples.greetings.api.GreetingCriteria) ErrorResponse(com.linkedin.restli.common.ErrorResponse) Test(org.testng.annotations.Test)

Aggregations

BatchCollectionResponse (com.linkedin.restli.common.BatchCollectionResponse)2 BatchFinderCriteriaResult (com.linkedin.restli.common.BatchFinderCriteriaResult)2 ErrorResponse (com.linkedin.restli.common.ErrorResponse)2 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)2 GreetingCriteria (com.linkedin.restli.examples.greetings.api.GreetingCriteria)2 BatchfindersRequestBuilders (com.linkedin.restli.examples.greetings.client.BatchfindersRequestBuilders)2 Test (org.testng.annotations.Test)2