use of com.linkedin.restli.examples.greetings.api.GreetingCriteria in project rest.li by linkedin.
the class TestBatchFinderResource method testBatchFinderWithProjection.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchFindersRequestBuilderDataProvider")
public void testBatchFinderWithProjection(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").fields(Greeting.fields().id()).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.assertFalse(greetings1.get(0).hasTone());
Assert.assertTrue(greetings1.get(0).hasId());
List<Greeting> greetings2 = batchResult.get(1).getElements();
Assert.assertTrue(greetings2.get(0).hasId());
Assert.assertFalse(greetings2.get(0).hasTone());
}
use of com.linkedin.restli.examples.greetings.api.GreetingCriteria 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!");
}
use of com.linkedin.restli.examples.greetings.api.GreetingCriteria in project rest.li by linkedin.
the class TestParseqBasedFluentClientApiWithProjections method testBatchFinderWithProjection.
@Test
public void testBatchFinderWithProjection() throws Exception {
Batchfinders batchFinders = new BatchfindersFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
GreetingCriteria c1 = new GreetingCriteria().setId(1L).setTone(Tone.SINCERE);
GreetingCriteria c2 = new GreetingCriteria().setId(2L).setTone(Tone.FRIENDLY);
CompletionStage<BatchCollectionResponse<Greeting>> result = batchFinders.findBySearchGreetings(Arrays.asList(c1, c2), "hello world", params -> params.withMask(mask -> mask.withTone().withId()));
CompletableFuture<BatchCollectionResponse<Greeting>> future = result.toCompletableFuture();
List<BatchFinderCriteriaResult<Greeting>> batchResult = future.get(5000, TimeUnit.MILLISECONDS).getResults();
List<Greeting> greetings1 = batchResult.get(0).getElements();
Assert.assertTrue(greetings1.get(0).hasTone());
Assert.assertEquals(greetings1.get(0).getTone(), Tone.SINCERE);
Assert.assertTrue(greetings1.get(0).hasId());
Assert.assertFalse(greetings1.get(0).hasMessage());
List<Greeting> greetings2 = batchResult.get(1).getElements();
Assert.assertTrue(greetings2.get(0).hasId());
Assert.assertEquals(greetings2.get(0).getTone(), Tone.FRIENDLY);
Assert.assertTrue(greetings2.get(0).hasId());
Assert.assertFalse(greetings2.get(0).hasMessage());
}
use of com.linkedin.restli.examples.greetings.api.GreetingCriteria in project rest.li by linkedin.
the class TestParseqBasedFluentClientApiWithProjections method testBatchFinderWithPagingProjection.
@Test
public void testBatchFinderWithPagingProjection() throws Exception {
Batchfinders batchFinders = new BatchfindersFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
GreetingCriteria c1 = new GreetingCriteria().setId(1L).setTone(Tone.SINCERE);
GreetingCriteria c2 = new GreetingCriteria().setId(2L).setTone(Tone.FRIENDLY);
CompletionStage<BatchCollectionResponse<Greeting>> result = batchFinders.findBySearchGreetings(Arrays.asList(c1, c2), "hello world", params -> params.withPagingMask(mask -> mask.withStart()).withMask(fieldMask -> fieldMask.withId().withTone()));
CompletableFuture<BatchCollectionResponse<Greeting>> future = result.toCompletableFuture();
List<BatchFinderCriteriaResult<Greeting>> batchResult = future.get(5000, TimeUnit.MILLISECONDS).getResults();
for (BatchFinderCriteriaResult<?> singleCriteria : batchResult) {
CollectionMetadata paging = singleCriteria.getPaging();
Assert.assertTrue(paging.hasStart());
Assert.assertFalse(paging.hasCount());
Assert.assertFalse(paging.hasTotal());
Assert.assertFalse(paging.hasLinks());
}
// Same request without paging mask (setting field mask to avoid validation error on server)
result = batchFinders.findBySearchGreetings(Arrays.asList(c1, c2), "hello world", params -> params.withMask(fieldMask -> fieldMask.withId().withTone()));
future = result.toCompletableFuture();
batchResult = future.get(5000, TimeUnit.MILLISECONDS).getResults();
for (BatchFinderCriteriaResult<?> singleCriteria : batchResult) {
CollectionMetadata paging = singleCriteria.getPaging();
Assert.assertTrue(paging.hasStart());
Assert.assertTrue(paging.hasCount());
Assert.assertTrue(paging.hasTotal());
Assert.assertTrue(paging.hasLinks());
}
}
use of com.linkedin.restli.examples.greetings.api.GreetingCriteria in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testBatchFinder.
@Test
public void testBatchFinder() throws Exception {
Batchfinders batchfinders = new BatchfindersFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
GreetingCriteria c1 = new GreetingCriteria().setId(1L).setTone(Tone.SINCERE);
GreetingCriteria c2 = new GreetingCriteria().setId(2L).setTone(Tone.FRIENDLY);
CompletionStage<BatchCollectionResponse<Greeting>> result = batchfinders.findBySearchGreetings(Arrays.asList(c1, c2), "hello world");
CompletableFuture<BatchCollectionResponse<Greeting>> future = result.toCompletableFuture();
List<BatchFinderCriteriaResult<Greeting>> batchResult = future.get(5000, TimeUnit.MILLISECONDS).getResults();
List<Greeting> greetings1 = batchResult.get(0).getElements();
Assert.assertTrue(greetings1.get(0).hasTone());
Assert.assertEquals(greetings1.get(0).getTone(), Tone.SINCERE);
List<Greeting> greetings2 = batchResult.get(1).getElements();
Assert.assertTrue(greetings2.get(0).hasId());
Assert.assertEquals(greetings2.get(0).getTone(), Tone.FRIENDLY);
}
Aggregations