use of com.linkedin.restli.common.BatchCollectionResponse in project rest.li by linkedin.
the class TestRestLiValidation method testBatchFinderAutoWithMultipleErrorFields.
@Test(dataProvider = "autoBuilders")
public void testBatchFinderAutoWithMultipleErrorFields(Object builder) throws RemoteInvocationException {
try {
ValidationDemoCriteria c1 = new ValidationDemoCriteria().setIntA(3333).setStringB("hello");
ValidationDemoCriteria c2 = new ValidationDemoCriteria().setIntA(4444).setStringB("world");
Request<BatchCollectionResponse<ValidationDemo>> request = new RootBuilderWrapper<Integer, ValidationDemo>(builder).batchFindBy("searchValidationDemos").setQueryParam("criteria", Arrays.asList(c1, c2)).build();
_restClientAuto.sendRequest(request).getResponse();
Assert.fail("Expected RestLiResponseException");
} catch (RestLiResponseException e) {
Assert.assertEquals(e.getServiceErrorMessage(), "BatchCriteria: 0 Element: 0 ERROR :: /stringA :: length of \"longLengthValueA\" is out of range 1...10\n" + "ERROR :: /stringB :: field is required but not found and has no default value\n" + "BatchCriteria: 0 Element: 1 ERROR :: /stringA :: length of \"longLengthValueA\" is out of range 1...10\n" + "ERROR :: /stringB :: field is required but not found and has no default value\n" + "BatchCriteria: 0 Element: 2 ERROR :: /stringA :: length of \"longLengthValueA\" is out of range 1...10\n" + "ERROR :: /stringB :: field is required but not found and has no default value\n");
}
}
use of com.linkedin.restli.common.BatchCollectionResponse 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.common.BatchCollectionResponse in project rest.li by linkedin.
the class BatchFinderResponseBuilder method buildResponse.
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public RestLiResponse buildResponse(RoutingResult routingResult, RestLiResponseData<BatchFinderResponseEnvelope> responseData) {
BatchFinderResponseEnvelope response = responseData.getResponseEnvelope();
DataMap dataMap = new DataMap();
DataList elementsMap = new DataList();
for (BatchFinderEntry entry : response.getItems()) {
CheckedUtil.addWithoutChecking(elementsMap, entry.toResponse(_errorResponseBuilder));
}
CheckedUtil.putWithoutChecking(dataMap, CollectionResponse.ELEMENTS, elementsMap);
BatchCollectionResponse<?> collectionResponse = new BatchCollectionResponse<>(dataMap, null);
RestLiResponse.Builder builder = new RestLiResponse.Builder();
return builder.entity(collectionResponse).headers(responseData.getHeaders()).cookies(responseData.getCookies()).build();
}
Aggregations