use of com.linkedin.restli.common.BatchCollectionResponse in project rest.li by linkedin.
the class TestRestLiValidation method testBatchFinderAutoWithOverLengthField.
@Test(dataProvider = "autoBuilders")
public void testBatchFinderAutoWithOverLengthField(Object builder) throws RemoteInvocationException {
try {
ValidationDemoCriteria c1 = new ValidationDemoCriteria().setIntA(2222).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" + "BatchCriteria: 0 Element: 1 ERROR :: /stringA :: length of \"longLengthValueA\" is out of range 1...10\n" + "BatchCriteria: 0 Element: 2 ERROR :: /stringA :: length of \"longLengthValueA\" is out of range 1...10\n");
}
}
use of com.linkedin.restli.common.BatchCollectionResponse in project rest.li by linkedin.
the class TestRestLiValidation method testBatchFinderAutoWithMissingField.
@Test(dataProvider = "autoBuilders")
public void testBatchFinderAutoWithMissingField(Object builder) throws RemoteInvocationException {
try {
ValidationDemoCriteria c1 = new ValidationDemoCriteria().setIntA(1111).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 :: /stringB :: field is required but not found and has no default value\n" + "BatchCriteria: 0 Element: 1 ERROR :: /stringB :: field is required but not found and has no default value\n" + "BatchCriteria: 0 Element: 2 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 MockBatchCollectionResponseFactory method create.
/**
* Creates a {@link BatchCollectionResponse} with the specified mock data. Make sure the size of the specified lists
* are the same as the entries at the same index will be used for generating the instances of
* {@link com.linkedin.restli.common.BatchFinderCriteriaResult} that goes into the final {@link BatchCollectionResponse}.
* The specified paging and metadata list can contain null entries if the corresponding criteria result instance must
* not have the paging and/or metadata set.
*
* @param entryClass the class of elements to be stored in {@link BatchCollectionResponse}
* @param elementsList A list of list containing the instances of type `entryClass`
* @param pagingList A list of {@link CollectionMetadata} for paging
* @param metadataList A list of {@link DataMap} for custom metadata
* @param <T> the type of elements to be stored in {@link BatchCollectionResponse}
* @return An instance of {@link BatchCollectionResponse} created with the specified mock data
*/
public static <T extends RecordTemplate> BatchCollectionResponse<T> create(Class<T> entryClass, List<List<T>> elementsList, List<CollectionMetadata> pagingList, List<DataMap> metadataList) {
DataList batchedCollectionResponse = new DataList(DataMapBuilder.getOptimumHashMapCapacityFromSize(elementsList.size()));
for (int i = 0; i < elementsList.size(); i++) {
Collection<T> recordElements = elementsList.get(i);
DataList elements = recordElements.stream().map(RecordTemplate::data).collect(Collectors.toCollection(DataList::new));
DataMap collectionResponse = new DataMap(DataMapBuilder.getOptimumHashMapCapacityFromSize(3));
CheckedUtil.putWithoutCheckingOrChangeNotification(collectionResponse, CollectionResponse.ELEMENTS, elements);
if (!pagingList.isEmpty()) {
CollectionMetadata paging = pagingList.get(i);
if (paging != null) {
CheckedUtil.putWithoutCheckingOrChangeNotification(collectionResponse, CollectionResponse.PAGING, paging.data());
}
}
if (!metadataList.isEmpty()) {
DataMap metadata = metadataList.get(i);
if (metadata != null) {
CheckedUtil.putWithoutCheckingOrChangeNotification(collectionResponse, CollectionResponse.METADATA, metadata);
}
}
CheckedUtil.addWithoutChecking(batchedCollectionResponse, collectionResponse);
}
DataMap batchResponse = new DataMap(DataMapBuilder.getOptimumHashMapCapacityFromSize(1));
CheckedUtil.putWithoutCheckingOrChangeNotification(batchResponse, CollectionResponse.ELEMENTS, batchedCollectionResponse);
return new BatchCollectionResponse<>(batchResponse, new BatchFinderCriteriaResultDecoder<>(entryClass));
}
use of com.linkedin.restli.common.BatchCollectionResponse 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.BatchCollectionResponse in project rest.li by linkedin.
the class TestRestLiValidation method testBatchFinder.
@Test(dataProvider = "manualBuilders")
public void testBatchFinder(Object builder) throws RemoteInvocationException {
ValidationDemoCriteria c1 = new ValidationDemoCriteria().setIntA(1111).setStringB("hello");
ValidationDemoCriteria c2 = new ValidationDemoCriteria().setIntA(1111).setStringB("world");
Request<BatchCollectionResponse<ValidationDemo>> request = new RootBuilderWrapper<Integer, ValidationDemo>(builder).batchFindBy("searchValidationDemos").setQueryParam("criteria", Arrays.asList(c1, c2)).build();
Response<BatchCollectionResponse<ValidationDemo>> response = _restClientManual.sendRequest(request).getResponse();
Assert.assertEquals(response.getStatus(), HttpStatus.S_200_OK.getCode());
}
Aggregations