Search in sources :

Example 1 with GreetingCriteria

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

the class TestBatchFinderResource method testBatchFinderWithError.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchFindersRequestBuilderDataProvider")
public void testBatchFinderWithError(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    GreetingCriteria c3 = new GreetingCriteria().setId(100L);
    Request<BatchCollectionResponse<Greeting>> request = builders.batchFindBy("searchGreetings").addQueryParam("criteria", c3).setQueryParam("message", "hello world").build();
    ResponseFuture<BatchCollectionResponse<Greeting>> future = getClient().sendRequest(request);
    BatchCollectionResponse<Greeting> response = future.getResponse().getEntity();
    List<BatchFinderCriteriaResult<Greeting>> batchResult = response.getResults();
    Assert.assertEquals(batchResult.size(), 1);
    ErrorResponse error = batchResult.get(0).getError();
    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) GreetingCriteria(com.linkedin.restli.examples.greetings.api.GreetingCriteria) ErrorResponse(com.linkedin.restli.common.ErrorResponse) Test(org.testng.annotations.Test)

Example 2 with GreetingCriteria

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

the class TestBatchFinderResource method testBatchFinder.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchFindersRequestBuilderDataProvider")
public void testBatchFinder(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    GreetingCriteria c1 = new GreetingCriteria().setId(1L).setTone(Tone.SINCERE);
    GreetingCriteria c2 = new GreetingCriteria().setId(2L).setTone(Tone.FRIENDLY);
    Request<BatchCollectionResponse<Greeting>> request = builders.batchFindBy("searchGreetings").setQueryParam("criteria", Arrays.asList(c1, c2)).setQueryParam("message", "hello world").build();
    ResponseFuture<BatchCollectionResponse<Greeting>> future = getClient().sendRequest(request);
    BatchCollectionResponse<Greeting> response = future.getResponse().getEntity();
    List<BatchFinderCriteriaResult<Greeting>> batchResult = response.getResults();
    List<Greeting> greetings1 = batchResult.get(0).getElements();
    Assert.assertTrue(greetings1.get(0).hasTone());
    Assert.assertTrue(greetings1.get(0).getTone().equals(Tone.SINCERE));
    List<Greeting> greetings2 = batchResult.get(1).getElements();
    Assert.assertTrue(greetings2.get(0).hasId());
    Assert.assertTrue(greetings2.get(0).getTone().equals(Tone.FRIENDLY));
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) BatchFinderCriteriaResult(com.linkedin.restli.common.BatchFinderCriteriaResult) BatchCollectionResponse(com.linkedin.restli.common.BatchCollectionResponse) GreetingCriteria(com.linkedin.restli.examples.greetings.api.GreetingCriteria) Test(org.testng.annotations.Test)

Example 3 with GreetingCriteria

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

the class TestBatchFinderResource method testBatchFinderWithNotFoundCriteria.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchFindersRequestBuilderDataProvider")
public void testBatchFinderWithNotFoundCriteria(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    GreetingCriteria c4 = new GreetingCriteria().setId(0L);
    Request<BatchCollectionResponse<Greeting>> request = builders.batchFindBy("searchGreetings").addQueryParam("criteria", c4).setQueryParam("message", "hello world").build();
    ResponseFuture<BatchCollectionResponse<Greeting>> future = getClient().sendRequest(request);
    BatchCollectionResponse<Greeting> response = future.getResponse().getEntity();
    List<BatchFinderCriteriaResult<Greeting>> batchResult = response.getResults();
    Assert.assertEquals(batchResult.size(), 1);
    ErrorResponse error = batchResult.get(0).getError();
    Assert.assertEquals(error.getMessage(), "The server didn't find a representation for this criteria");
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) BatchFinderCriteriaResult(com.linkedin.restli.common.BatchFinderCriteriaResult) BatchCollectionResponse(com.linkedin.restli.common.BatchCollectionResponse) GreetingCriteria(com.linkedin.restli.examples.greetings.api.GreetingCriteria) ErrorResponse(com.linkedin.restli.common.ErrorResponse) Test(org.testng.annotations.Test)

Example 4 with GreetingCriteria

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

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

the class TestBatchFinderResource method testBatchFinderWithErrorAndProjection.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchFindersRequestBuilderDataProvider")
public void testBatchFinderWithErrorAndProjection(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    GreetingCriteria c3 = new GreetingCriteria().setId(100L);
    Request<BatchCollectionResponse<Greeting>> request = builders.batchFindBy("searchGreetings").addQueryParam("criteria", c3).setQueryParam("message", "hello world").fields(Greeting.fields().id()).build();
    ResponseFuture<BatchCollectionResponse<Greeting>> future = getClient().sendRequest(request);
    BatchCollectionResponse<Greeting> response = future.getResponse().getEntity();
    List<BatchFinderCriteriaResult<Greeting>> batchResult = response.getResults();
    Assert.assertEquals(batchResult.size(), 1);
    ErrorResponse error = batchResult.get(0).getError();
    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) GreetingCriteria(com.linkedin.restli.examples.greetings.api.GreetingCriteria) ErrorResponse(com.linkedin.restli.common.ErrorResponse) Test(org.testng.annotations.Test)

Aggregations

Greeting (com.linkedin.restli.examples.greetings.api.Greeting)12 GreetingCriteria (com.linkedin.restli.examples.greetings.api.GreetingCriteria)12 BatchCollectionResponse (com.linkedin.restli.common.BatchCollectionResponse)10 BatchFinderCriteriaResult (com.linkedin.restli.common.BatchFinderCriteriaResult)10 Test (org.testng.annotations.Test)10 ErrorResponse (com.linkedin.restli.common.ErrorResponse)5 Batchfinders (com.linkedin.restli.examples.greetings.client.Batchfinders)3 BatchfindersFluentClient (com.linkedin.restli.examples.greetings.client.BatchfindersFluentClient)3 CreateGreeting (com.linkedin.restli.examples.greetings.client.CreateGreeting)3 PartialUpdateGreeting (com.linkedin.restli.examples.greetings.client.PartialUpdateGreeting)3 ParSeqUnitTestHelper (com.linkedin.parseq.ParSeqUnitTestHelper)2 ParSeqRestliClient (com.linkedin.restli.client.ParSeqRestliClient)2 ParSeqRestliClientBuilder (com.linkedin.restli.client.ParSeqRestliClientBuilder)2 ParSeqRestliClientConfigBuilder (com.linkedin.restli.client.ParSeqRestliClientConfigBuilder)2 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)2 PatchGenerator (com.linkedin.restli.client.util.PatchGenerator)2 CollectionMetadata (com.linkedin.restli.common.CollectionMetadata)2 CollectionResponse (com.linkedin.restli.common.CollectionResponse)2 CreateIdEntityStatus (com.linkedin.restli.common.CreateIdEntityStatus)2 CreateIdStatus (com.linkedin.restli.common.CreateIdStatus)2