use of com.linkedin.restli.common.BatchFinderCriteriaResult 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.common.BatchFinderCriteriaResult 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);
}
use of com.linkedin.restli.common.BatchFinderCriteriaResult in project rest.li by linkedin.
the class TestFillInDefaultValue method testFillInDefaultBatchFinder.
@Test(dataProvider = "testBatchFinderData")
public void testFillInDefaultBatchFinder(Object[] criteria, HighLevelRecordWithDefault[] expected) throws RemoteInvocationException {
FillInDefaultsRequestBuilders builders = new FillInDefaultsRequestBuilders();
BatchFindRequest<HighLevelRecordWithDefault> request = builders.batchFindBySearchRecords().addCriteriaParam((RecordCriteria) criteria[0]).addCriteriaParam((RecordCriteria) criteria[1]).setParam(RestConstants.FILL_IN_DEFAULTS_PARAM, true).build();
List<BatchFinderCriteriaResult<HighLevelRecordWithDefault>> batchFinderCriteriaResults = getClient().sendRequest(request).getResponse().getEntity().getResults();
Set<HighLevelRecordWithDefault> actualActionResponse = new HashSet<>();
for (BatchFinderCriteriaResult<HighLevelRecordWithDefault> result : batchFinderCriteriaResults) {
actualActionResponse.addAll(result.getElements());
}
Set<HighLevelRecordWithDefault> expectedActionResponse = new HashSet<>(Arrays.asList(expected));
Assert.assertEquals(actualActionResponse, expectedActionResponse);
}
use of com.linkedin.restli.common.BatchFinderCriteriaResult in project rest.li by linkedin.
the class TestAssociationsResource method testBatchFinder.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testBatchFinder(RootBuilderWrapper<CompoundKey, Message> builders) throws RemoteInvocationException {
MessageCriteria m1 = new MessageCriteria().setMessage("hello").setTone(Tone.FRIENDLY);
MessageCriteria m2 = new MessageCriteria().setMessage("world").setTone(Tone.SINCERE);
Request<BatchCollectionResponse<Message>> request = builders.batchFindBy("searchMessages").assocKey("src", "KEY1").setQueryParam("criteria", Arrays.asList(m1, m2)).build();
ResponseFuture<BatchCollectionResponse<Message>> future = getClient().sendRequest(request);
BatchCollectionResponse<Message> response = future.getResponse().getEntity();
List<BatchFinderCriteriaResult<Message>> batchResult = response.getResults();
// on success
List<Message> messages = batchResult.get(0).getElements();
Assert.assertTrue(messages.get(0).hasTone());
Assert.assertTrue(messages.get(0).getTone().equals(Tone.FRIENDLY));
// on error
Assert.assertTrue(batchResult.get(1).isError());
ErrorResponse error = batchResult.get(1).getError();
Assert.assertEquals(error.getMessage(), "Failed to find message!");
}
Aggregations