use of com.linkedin.restli.examples.greetings.api.MessageCriteria in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testAssociationBatchFinderUsingAssocKey.
@Test
public void testAssociationBatchFinderUsingAssocKey() throws Exception {
AssociationsFluentClient associations = new AssociationsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
MessageCriteriaArray criteriaArray = new MessageCriteriaArray();
criteriaArray.add(new MessageCriteria().setTone(Tone.FRIENDLY));
criteriaArray.add(new MessageCriteria().setTone(Tone.INSULTING));
BatchCollectionResponse<Message> messages = associations.findBySearchMessages(AssociationResourceHelpers.URL_COMPOUND_KEY.getPartAsString("src"), criteriaArray).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
Assert.assertEquals(messages.getResults().size(), 2);
BatchFinderCriteriaResult<Message> friendly = messages.getResults().get(0);
Assert.assertFalse(friendly.isError());
for (Message message : friendly.getElements()) {
Assert.assertEquals(message.getTone(), Tone.FRIENDLY);
}
BatchFinderCriteriaResult<Message> insulting = messages.getResults().get(1);
Assert.assertTrue(insulting.isError());
Assert.assertEquals((int) insulting.getError().getStatus(), 404);
}
use of com.linkedin.restli.examples.greetings.api.MessageCriteria 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!");
}
use of com.linkedin.restli.examples.greetings.api.MessageCriteria in project rest.li by linkedin.
the class AssociationsResource method searchMessages.
@BatchFinder(value = "searchMessages", batchParam = "criteria")
public BatchFinderResult<MessageCriteria, Message, Empty> searchMessages(@AssocKeyParam("src") String src, @PagingContextParam PagingContext context, @QueryParam("criteria") MessageCriteria[] criteria) {
BatchFinderResult<MessageCriteria, Message, Empty> batchFinderResult = new BatchFinderResult<>();
for (MessageCriteria currentCriteria : criteria) {
if (currentCriteria.getTone() == Tone.FRIENDLY) {
// on success
CollectionResult<Message, Empty> cr = new CollectionResult<>(Arrays.asList(m1, m2), 2);
batchFinderResult.putResult(currentCriteria, cr);
} else {
// on error: to construct error response for test
batchFinderResult.putError(currentCriteria, new RestLiServiceException(HttpStatus.S_404_NOT_FOUND, "Failed to find message!"));
}
}
return batchFinderResult;
}
Aggregations