use of com.linkedin.restli.examples.greetings.api.ValidationDemoCriteria 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.examples.greetings.api.ValidationDemoCriteria in project rest.li by linkedin.
the class AutomaticValidationDemoResource method searchValidationDemos.
@BatchFinder(value = "searchValidationDemos", batchParam = "criteria")
public BatchFinderResult<ValidationDemoCriteria, ValidationDemo, Empty> searchValidationDemos(@PagingContextParam PagingContext context, @QueryParam("criteria") ValidationDemoCriteria[] criteria) {
BatchFinderResult<ValidationDemoCriteria, ValidationDemo, Empty> batchFinderResult = new BatchFinderResult<>();
for (ValidationDemoCriteria currentCriteria : criteria) {
List<ValidationDemo> validationDemos = new ArrayList<>();
if (currentCriteria.getIntA() == 1111) {
// Generate entities that are missing stringB fields
for (int i = 0; i < 3; i++) {
ValidationDemo.UnionFieldWithInlineRecord union = new ValidationDemo.UnionFieldWithInlineRecord();
union.setMyEnum(myEnum.FOOFOO);
validationDemos.add(new ValidationDemo().setStringA("valueA").setIntA(currentCriteria.getIntA()).setUnionFieldWithInlineRecord(union));
}
} else if (currentCriteria.getIntA() == 2222) {
// Generate entities that their stringA field has a value over the length limitation
for (int i = 0; i < 3; i++) {
ValidationDemo.UnionFieldWithInlineRecord union = new ValidationDemo.UnionFieldWithInlineRecord();
union.setMyEnum(myEnum.FOOFOO);
validationDemos.add(new ValidationDemo().setStringA("longLengthValueA").setIntA(currentCriteria.getIntA()).setStringB("valueB").setUnionFieldWithInlineRecord(union));
}
} else if (currentCriteria.getIntA() == 3333) {
// the stringA field has a value over the length limitation and miss stringB fields
for (int i = 0; i < 3; i++) {
ValidationDemo.UnionFieldWithInlineRecord union = new ValidationDemo.UnionFieldWithInlineRecord();
union.setMyEnum(myEnum.FOOFOO);
validationDemos.add(new ValidationDemo().setStringA("longLengthValueA").setIntA(currentCriteria.getIntA()).setUnionFieldWithInlineRecord(union));
}
} else if (currentCriteria.getIntA() == 4444) {
// entities without errors
for (int i = 0; i < 3; i++) {
ValidationDemo.UnionFieldWithInlineRecord union = new ValidationDemo.UnionFieldWithInlineRecord();
union.setMyEnum(myEnum.FOOFOO);
validationDemos.add(new ValidationDemo().setStringA("valueA").setIntA(currentCriteria.getIntA()).setStringB("valueB").setUnionFieldWithInlineRecord(union));
}
} else {
// on errorResponse
batchFinderResult.putError(currentCriteria, new RestLiServiceException(HttpStatus.S_404_NOT_FOUND, "Fail to find Validation Demo!"));
continue;
}
CollectionResult<ValidationDemo, Empty> cr = new CollectionResult<>(validationDemos, validationDemos.size());
batchFinderResult.putResult(currentCriteria, cr);
}
return batchFinderResult;
}
Aggregations