use of com.linkedin.restli.examples.greetings.api.ValidationDemoCriteria in project rest.li by linkedin.
the class TestRestLiValidation method testBatchFinderAutoWithErrorCriteriaResult.
@Test(dataProvider = "autoBuilders")
public void testBatchFinderAutoWithErrorCriteriaResult(Object builder) throws RemoteInvocationException {
ValidationDemoCriteria c1 = new ValidationDemoCriteria().setIntA(5555).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();
Response<BatchCollectionResponse<ValidationDemo>> response = _restClientAuto.sendRequest(request).getResponse();
Assert.assertEquals(response.getStatus(), HttpStatus.S_200_OK.getCode());
}
use of com.linkedin.restli.examples.greetings.api.ValidationDemoCriteria 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.examples.greetings.api.ValidationDemoCriteria 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.examples.greetings.api.ValidationDemoCriteria in project rest.li by linkedin.
the class ValidationDemoResource method searchValidationDemos.
@BatchFinder(value = "searchValidationDemos", batchParam = "criteria")
public BatchFinderResult<ValidationDemoCriteria, ValidationDemo, Empty> searchValidationDemos(@PagingContextParam PagingContext context, @QueryParam("criteria") ValidationDemoCriteria[] criteria, @ValidatorParam RestLiDataValidator validator) {
BatchFinderResult<ValidationDemoCriteria, ValidationDemo, Empty> batchFinderResult = new BatchFinderResult<>();
for (ValidationDemoCriteria currentCriteria : criteria) {
List<ValidationDemo> validationDemos = new ArrayList<>();
// 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));
}
// Validate outgoing data
for (ValidationDemo entity : validationDemos) {
ValidationResult result = validator.validateOutput(entity);
check(!result.isValid());
check(result.getMessages().toString().contains("/stringB :: field is required but not found"));
}
// Fix entities
for (ValidationDemo validationDemo : validationDemos) {
validationDemo.setStringB("valueB");
}
// Validate again
for (ValidationDemo entity : validationDemos) {
ValidationResult result = validator.validateOutput(entity);
check(result.isValid());
}
CollectionResult<ValidationDemo, Empty> cr = new CollectionResult<>(validationDemos, validationDemos.size());
batchFinderResult.putResult(currentCriteria, cr);
}
return batchFinderResult;
}
use of com.linkedin.restli.examples.greetings.api.ValidationDemoCriteria 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