Search in sources :

Example 1 with ObjectError

use of cn.taketoday.validation.ObjectError in project today-infrastructure by TAKETODAY.

the class DefaultErrorAttributesTests method withoutBindingErrors.

@Test
void withoutBindingErrors() {
    BindingResult bindingResult = new MapBindingResult(Collections.singletonMap("a", "b"), "objectName");
    bindingResult.addError(new ObjectError("c", "d"));
    Exception ex = new BindException(bindingResult);
    testBindingResult(bindingResult, ex, ErrorAttributeOptions.defaults());
}
Also used : BindingResult(cn.taketoday.validation.BindingResult) MapBindingResult(cn.taketoday.validation.MapBindingResult) ObjectError(cn.taketoday.validation.ObjectError) BindException(cn.taketoday.validation.BindException) MapBindingResult(cn.taketoday.validation.MapBindingResult) ServletException(jakarta.servlet.ServletException) BindException(cn.taketoday.validation.BindException) MethodArgumentNotValidException(cn.taketoday.web.bind.MethodArgumentNotValidException) Test(org.junit.jupiter.api.Test)

Example 2 with ObjectError

use of cn.taketoday.validation.ObjectError in project today-infrastructure by TAKETODAY.

the class DefaultErrorAttributesTests method withBindingErrors.

@Test
void withBindingErrors() {
    BindingResult bindingResult = new MapBindingResult(Collections.singletonMap("a", "b"), "objectName");
    bindingResult.addError(new ObjectError("c", "d"));
    Exception ex = new BindException(bindingResult);
    testBindingResult(bindingResult, ex, ErrorAttributeOptions.of(Include.MESSAGE, Include.BINDING_ERRORS));
}
Also used : BindingResult(cn.taketoday.validation.BindingResult) MapBindingResult(cn.taketoday.validation.MapBindingResult) ObjectError(cn.taketoday.validation.ObjectError) BindException(cn.taketoday.validation.BindException) MapBindingResult(cn.taketoday.validation.MapBindingResult) ServletException(jakarta.servlet.ServletException) BindException(cn.taketoday.validation.BindException) MethodArgumentNotValidException(cn.taketoday.web.bind.MethodArgumentNotValidException) Test(org.junit.jupiter.api.Test)

Example 3 with ObjectError

use of cn.taketoday.validation.ObjectError in project today-infrastructure by TAKETODAY.

the class ValidationErrorsTests method iteratorShouldIterateErrors.

@Test
void iteratorShouldIterateErrors() {
    List<ObjectError> allErrors = new ArrayList<>();
    allErrors.add(new ObjectError("foo", "bar"));
    ValidationErrors errors = new ValidationErrors(NAME, Collections.emptySet(), allErrors);
    assertThat(errors.iterator()).toIterable().containsExactlyElementsOf(allErrors);
}
Also used : ObjectError(cn.taketoday.validation.ObjectError) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 4 with ObjectError

use of cn.taketoday.validation.ObjectError in project today-infrastructure by TAKETODAY.

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(cn.taketoday.context.properties.source.ConfigurationProperty) LinkedHashSet(java.util.LinkedHashSet) MockOrigin(cn.taketoday.origin.MockOrigin) Origin(cn.taketoday.origin.Origin) ConfigurationPropertyName(cn.taketoday.context.properties.source.ConfigurationPropertyName) ObjectError(cn.taketoday.validation.ObjectError) ArrayList(java.util.ArrayList) FieldError(cn.taketoday.validation.FieldError) Test(org.junit.jupiter.api.Test)

Example 5 with ObjectError

use of cn.taketoday.validation.ObjectError in project today-infrastructure by TAKETODAY.

the class ValidationErrorsTests method getErrorsShouldReturnErrors.

@Test
void getErrorsShouldReturnErrors() {
    List<ObjectError> allErrors = new ArrayList<>();
    allErrors.add(new ObjectError("foo", "bar"));
    ValidationErrors errors = new ValidationErrors(NAME, Collections.emptySet(), allErrors);
    assertThat(errors.getAllErrors()).isEqualTo(allErrors);
}
Also used : ObjectError(cn.taketoday.validation.ObjectError) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Aggregations

ObjectError (cn.taketoday.validation.ObjectError)22 Test (org.junit.jupiter.api.Test)18 BindingResult (cn.taketoday.validation.BindingResult)8 BindException (cn.taketoday.validation.BindException)6 MapBindingResult (cn.taketoday.validation.MapBindingResult)6 MethodArgumentNotValidException (cn.taketoday.web.bind.MethodArgumentNotValidException)6 ServletException (jakarta.servlet.ServletException)6 ArrayList (java.util.ArrayList)6 BeanPropertyBindingResult (cn.taketoday.validation.BeanPropertyBindingResult)4 ConfigurableApplicationContext (cn.taketoday.context.ConfigurableApplicationContext)2 BindException (cn.taketoday.context.properties.bind.BindException)2 BindValidationException (cn.taketoday.context.properties.bind.validation.BindValidationException)2 ConfigurationProperty (cn.taketoday.context.properties.source.ConfigurationProperty)2 ConfigurationPropertyName (cn.taketoday.context.properties.source.ConfigurationPropertyName)2 MockConfigurationPropertySource (cn.taketoday.context.properties.source.MockConfigurationPropertySource)2 StandardApplicationContext (cn.taketoday.context.support.StandardApplicationContext)2 MethodParameter (cn.taketoday.core.MethodParameter)2 MockOrigin (cn.taketoday.origin.MockOrigin)2 Origin (cn.taketoday.origin.Origin)2 FieldError (cn.taketoday.validation.FieldError)2