Search in sources :

Example 91 with FieldError

use of org.springframework.validation.FieldError in project spring-boot by spring-projects.

the class ValidationErrorsTests method getErrorsShouldAdaptFieldErrorsToBeOriginProviders.

@Test
void getErrorsShouldAdaptFieldErrorsToBeOriginProviders() {
    Set<ConfigurationProperty> boundProperties = new LinkedHashSet<>();
    ConfigurationPropertyName name1 = ConfigurationPropertyName.of("foo.bar");
    Origin origin1 = MockOrigin.of("line1");
    boundProperties.add(new ConfigurationProperty(name1, "boot", origin1));
    ConfigurationPropertyName name2 = ConfigurationPropertyName.of("foo.baz.bar");
    Origin origin2 = MockOrigin.of("line2");
    boundProperties.add(new ConfigurationProperty(name2, "boot", origin2));
    List<ObjectError> allErrors = new ArrayList<>();
    allErrors.add(new FieldError("objectname", "bar", "message"));
    ValidationErrors errors = new ValidationErrors(ConfigurationPropertyName.of("foo.baz"), boundProperties, allErrors);
    assertThat(Origin.from(errors.getAllErrors().get(0))).isEqualTo(origin2);
}
Also used : ConfigurationProperty(org.springframework.boot.context.properties.source.ConfigurationProperty) LinkedHashSet(java.util.LinkedHashSet) Origin(org.springframework.boot.origin.Origin) MockOrigin(org.springframework.boot.origin.MockOrigin) ConfigurationPropertyName(org.springframework.boot.context.properties.source.ConfigurationPropertyName) ObjectError(org.springframework.validation.ObjectError) ArrayList(java.util.ArrayList) FieldError(org.springframework.validation.FieldError) Test(org.junit.jupiter.api.Test)

Example 92 with FieldError

use of org.springframework.validation.FieldError in project spring-boot by spring-projects.

the class BindValidationFailureAnalyzerTests method otherBindExceptionShouldReturnAnalysis.

@Test
void otherBindExceptionShouldReturnAnalysis() {
    BindException cause = new BindException(new FieldValidationFailureProperties(), "fieldValidationFailureProperties");
    cause.addError(new FieldError("test", "value", "must not be null"));
    BeanCreationException rootFailure = new BeanCreationException("bean creation failure", cause);
    FailureAnalysis analysis = new BindValidationFailureAnalyzer().analyze(rootFailure, rootFailure);
    assertThat(analysis.getDescription()).contains(failure("test.value", "null", "must not be null"));
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) BindException(org.springframework.validation.BindException) FieldError(org.springframework.validation.FieldError) FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis) Test(org.junit.jupiter.api.Test)

Aggregations

FieldError (org.springframework.validation.FieldError)92 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)20 ObjectError (org.springframework.validation.ObjectError)19 Test (org.junit.jupiter.api.Test)17 BindingResult (org.springframework.validation.BindingResult)16 ApiOperation (io.swagger.annotations.ApiOperation)14 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)12 Errors (org.springframework.validation.Errors)11 ArrayList (java.util.ArrayList)7 BindException (org.springframework.validation.BindException)6 CustomResult (com.megagao.production.ssm.domain.customize.CustomResult)5 Locale (java.util.Locale)5 Test (org.junit.Test)5 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)5 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)5 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)4 HashMap (java.util.HashMap)4 UserProfileDTO (com.odysseusinc.arachne.portal.api.v1.dto.UserProfileDTO)3 LinkedHashSet (java.util.LinkedHashSet)3 MapBindingResult (org.springframework.validation.MapBindingResult)3