use of org.springframework.validation.BindingResult in project ORCID-Source by ORCID.
the class ClaimControllerTest method testResendClaimEmail.
@Test
public void testResendClaimEmail() {
BindingResult bindingResult = mock(BindingResult.class);
when(bindingResult.hasErrors()).thenReturn(false);
when(emailManager.emailExists("billie@holiday.com")).thenReturn(true);
when(emailManager.findOrcidIdByEmail("billie@holiday.com")).thenReturn("0000-0000-0000-0000");
when(profileEntityCacheManager.retrieve(Mockito.anyString())).thenReturn(getProfileEntityToTestClaimResend(false));
EmailRequest emailRequest = new EmailRequest();
emailRequest.setEmail("billie@holiday.com");
emailRequest = claimController.resendClaimEmail(emailRequest);
assertNotNull(emailRequest);
assertNotNull(emailRequest.getSuccessMessage());
}
use of org.springframework.validation.BindingResult in project spring-framework by spring-projects.
the class ModelResultMatchers method attributeHasNoErrors.
/**
* Assert the given model attribute(s) do not have errors.
*/
public ResultMatcher attributeHasNoErrors(final String... names) {
return new ResultMatcher() {
@Override
public void match(MvcResult mvcResult) throws Exception {
ModelAndView mav = getModelAndView(mvcResult);
for (String name : names) {
BindingResult result = getBindingResult(mav, name);
assertTrue("No errors for attribute [" + name + "]", !result.hasErrors());
}
}
};
}
use of org.springframework.validation.BindingResult in project spring-framework by spring-projects.
the class ModelResultMatchers method attributeHasFieldErrorCode.
/**
* Assert a field error code for a model attribute using exact String match.
* @since 4.1
*/
public ResultMatcher attributeHasFieldErrorCode(final String name, final String fieldName, final String error) {
return new ResultMatcher() {
public void match(MvcResult mvcResult) throws Exception {
ModelAndView mav = getModelAndView(mvcResult);
BindingResult result = getBindingResult(mav, name);
assertTrue("No errors for attribute: [" + name + "]", result.hasErrors());
boolean hasFieldErrors = result.hasFieldErrors(fieldName);
assertTrue("No errors for field: [" + fieldName + "] of attribute [" + name + "]", hasFieldErrors);
String code = result.getFieldError(fieldName).getCode();
assertTrue("Expected error code '" + error + "' but got '" + code + "'", code.equals(error));
}
};
}
use of org.springframework.validation.BindingResult in project spring-boot by spring-projects.
the class DefaultErrorAttributes method addErrorMessage.
private void addErrorMessage(Map<String, Object> errorAttributes, Throwable error) {
BindingResult result = extractBindingResult(error);
if (result == null) {
errorAttributes.put("message", error.getMessage());
return;
}
if (result.getErrorCount() > 0) {
errorAttributes.put("errors", result.getAllErrors());
errorAttributes.put("message", "Validation failed for object='" + result.getObjectName() + "'. Error count: " + result.getErrorCount());
} else {
errorAttributes.put("message", "No errors");
}
}
use of org.springframework.validation.BindingResult in project spring-boot by spring-projects.
the class YamlConfigurationFactory method validate.
private void validate() throws BindException {
BindingResult errors = new BeanPropertyBindingResult(this.configuration, "configuration");
this.validator.validate(this.configuration, errors);
if (errors.hasErrors()) {
logger.error("YAML configuration failed validation");
for (ObjectError error : errors.getAllErrors()) {
logger.error(getErrorMessage(error));
}
throw new BindException(errors);
}
}
Aggregations