|
|
|
@ -17,9 +17,11 @@
@@ -17,9 +17,11 @@
|
|
|
|
|
package org.springframework.validation.beanvalidation2; |
|
|
|
|
|
|
|
|
|
import java.lang.annotation.Documented; |
|
|
|
|
import java.lang.annotation.ElementType; |
|
|
|
|
import java.lang.annotation.Inherited; |
|
|
|
|
import java.lang.annotation.Repeatable; |
|
|
|
|
import java.lang.annotation.Retention; |
|
|
|
|
import java.lang.annotation.RetentionPolicy; |
|
|
|
|
import java.lang.annotation.Target; |
|
|
|
|
import java.lang.reflect.Field; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
@ -55,8 +57,6 @@ import org.springframework.validation.BeanPropertyBindingResult;
@@ -55,8 +57,6 @@ import org.springframework.validation.BeanPropertyBindingResult;
|
|
|
|
|
import org.springframework.validation.FieldError; |
|
|
|
|
import org.springframework.validation.beanvalidation.SpringValidatorAdapter; |
|
|
|
|
|
|
|
|
|
import static java.lang.annotation.ElementType.*; |
|
|
|
|
import static java.lang.annotation.RetentionPolicy.*; |
|
|
|
|
import static org.hamcrest.core.Is.*; |
|
|
|
|
import static org.hamcrest.core.StringContains.*; |
|
|
|
|
import static org.junit.Assert.*; |
|
|
|
@ -327,8 +327,8 @@ public class SpringValidatorAdapterTests {
@@ -327,8 +327,8 @@ public class SpringValidatorAdapterTests {
|
|
|
|
|
|
|
|
|
|
@Documented |
|
|
|
|
@Constraint(validatedBy = {SameValidator.class}) |
|
|
|
|
@Target({TYPE, ANNOTATION_TYPE}) |
|
|
|
|
@Retention(RUNTIME) |
|
|
|
|
@Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE}) |
|
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
|
@Repeatable(SameGroup.class) |
|
|
|
|
@interface Same { |
|
|
|
|
|
|
|
|
@ -342,8 +342,8 @@ public class SpringValidatorAdapterTests {
@@ -342,8 +342,8 @@ public class SpringValidatorAdapterTests {
|
|
|
|
|
|
|
|
|
|
String comparingField(); |
|
|
|
|
|
|
|
|
|
@Target({TYPE, ANNOTATION_TYPE}) |
|
|
|
|
@Retention(RUNTIME) |
|
|
|
|
@Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE}) |
|
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
|
@Documented |
|
|
|
|
@interface List { |
|
|
|
|
Same[] value(); |
|
|
|
@ -353,8 +353,8 @@ public class SpringValidatorAdapterTests {
@@ -353,8 +353,8 @@ public class SpringValidatorAdapterTests {
|
|
|
|
|
|
|
|
|
|
@Documented |
|
|
|
|
@Inherited |
|
|
|
|
@Retention(RUNTIME) |
|
|
|
|
@Target({TYPE, ANNOTATION_TYPE}) |
|
|
|
|
@Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE}) |
|
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
|
@interface SameGroup { |
|
|
|
|
|
|
|
|
|
Same[] value(); |
|
|
|
@ -490,7 +490,7 @@ public class SpringValidatorAdapterTests {
@@ -490,7 +490,7 @@ public class SpringValidatorAdapterTests {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Constraint(validatedBy = AnythingValidator.class) |
|
|
|
|
@Retention(RUNTIME) |
|
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
|
public @interface AnythingValid { |
|
|
|
|
|
|
|
|
|
String message() default "{AnythingValid.message}"; |
|
|
|
@ -511,14 +511,14 @@ public class SpringValidatorAdapterTests {
@@ -511,14 +511,14 @@ public class SpringValidatorAdapterTests {
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean isValid(Object value, ConstraintValidatorContext context) { |
|
|
|
|
List<Field> fieldsErros = new ArrayList<>(); |
|
|
|
|
Arrays.asList(value.getClass().getDeclaredFields()).forEach(f -> { |
|
|
|
|
f.setAccessible(true); |
|
|
|
|
List<Field> fieldsErrors = new ArrayList<>(); |
|
|
|
|
Arrays.asList(value.getClass().getDeclaredFields()).forEach(field -> { |
|
|
|
|
field.setAccessible(true); |
|
|
|
|
try { |
|
|
|
|
if (!f.getName().equals(ID) && f.get(value) == null) { |
|
|
|
|
fieldsErros.add(f); |
|
|
|
|
if (!field.getName().equals(ID) && field.get(value) == null) { |
|
|
|
|
fieldsErrors.add(field); |
|
|
|
|
context.buildConstraintViolationWithTemplate(context.getDefaultConstraintMessageTemplate()) |
|
|
|
|
.addPropertyNode(f.getName()) |
|
|
|
|
.addPropertyNode(field.getName()) |
|
|
|
|
.addConstraintViolation(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -526,7 +526,7 @@ public class SpringValidatorAdapterTests {
@@ -526,7 +526,7 @@ public class SpringValidatorAdapterTests {
|
|
|
|
|
throw new IllegalStateException(ex); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
return fieldsErros.isEmpty(); |
|
|
|
|
return fieldsErrors.isEmpty(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|