@Test
public void testAssertFalse() {
Set<ConstraintViolation<ObjectWithValidation>> violations = validator.validate(obj, AssertFalse.class);
assertNotNull(violations);
assertEquals(violations.size(), 1);
if (runPeformance) {
long time = System.currentTimeMillis();
for (int index = 0; index < 10000; index++) {
validator.validate(obj, AssertFalse.class);
}
long used = System.currentTimeMillis() - time;
System.out.println("Hibernate Validator [AssertFalse] check used " + used + "ms, avg. " + ((double) used)
/ 10000 + "ms.");
}
}
java类javax.validation.constraints.AssertFalse的实例源码
TestObject.java 文件源码
项目:nest-old
阅读 29
收藏 0
点赞 0
评论 0
ContractsBoltReflector.java 文件源码
项目:storm-data-contracts
阅读 22
收藏 0
点赞 0
评论 0
private void checkAnnotations(Class<?> contractClass) {
Field[] fields = contractClass.getFields();
for (Field field : fields) {
Class fieldType = field.getType();
if (Optional.class.isAssignableFrom(fieldType)) {
checkAnnotation(contractClass, field,UnwrapValidatedValue.class);
checkNoAnnotation(contractClass, field, NotNull.class);
}
else {
checkNoAnnotation(contractClass, field, UnwrapValidatedValue.class);
checkAnnotation(contractClass, field,NotNull.class);
}
}
for(Method method : contractClass.getMethods()) {
if(method.isAnnotationPresent(AssertTrue.class) || method.isAnnotationPresent(AssertFalse.class)) {
if(method.getReturnType() != boolean.class && method.getReturnType() != Boolean.class) {
throw new IllegalStateException("AssertTrue or AssertFalse annotations must be placed above methods that return boolean value");
}
if(!method.getName().startsWith("is")) {
throw new IllegalStateException("Methods annotated with AssertTrue or AssertFalse must start with \"is\"");
}
}
}
}
ValidationUtils.java 文件源码
项目:para
阅读 26
收藏 0
点赞 0
评论 0
private static boolean isValidSimpleConstraint(String cName, String field, Object actual, LinkedList<String> err) {
if ("required".equals(cName) && !required().isValid(actual)) {
err.add(Utils.formatMessage("{0} is required.", field));
return false;
} else if (matches(AssertFalse.class, cName) && !falsy().isValid(actual)) {
err.add(Utils.formatMessage("{0} must be false.", field));
return false;
} else if (matches(AssertTrue.class, cName) && !truthy().isValid(actual)) {
err.add(Utils.formatMessage("{0} must be true.", field));
return false;
} else if (matches(Future.class, cName) && !future().isValid(actual)) {
err.add(Utils.formatMessage("{0} must be in the future.", field));
return false;
} else if (matches(Past.class, cName) && !past().isValid(actual)) {
err.add(Utils.formatMessage("{0} must be in the past.", field));
return false;
} else if (matches(URL.class, cName) && !url().isValid(actual)) {
err.add(Utils.formatMessage("{0} is not a valid URL.", field));
return false;
} else if (matches(Email.class, cName) && !email().isValid(actual)) {
err.add(Utils.formatMessage("{0} is not a valid email.", field));
return false;
}
return true;
}
MinijaxConstraintDescriptor.java 文件源码
项目:minijax
阅读 32
收藏 0
点赞 0
评论 0
private static MinijaxConstraintDescriptor<AssertFalse> buildAssertFalseValidator(final AssertFalse assertFalse, final Class<?> valueClass) {
if (valueClass == boolean.class || valueClass == Boolean.class) {
return new MinijaxConstraintDescriptor<>(assertFalse, AssertFalseValidator.INSTANCE);
}
throw new ValidationException("Unsupported type for @AssertFalse annotation: " + valueClass);
}
AssertFalseAnnotationPostProcessor.java 文件源码
项目:randomito-all
阅读 21
收藏 0
点赞 0
评论 0
@Override
public Object process(AnnotationInfo ctx, Object value) throws Exception {
if (!ctx.isAnnotationPresent(AssertFalse.class)) {
return value;
}
return false;
}
AssertFalseValidationAdapter.java 文件源码
项目:geeMVC-Java-MVC-Framework
阅读 22
收藏 0
点赞 0
评论 0
@Override
public void validate(AssertFalse assertFalseAnnotation, String name, ValidationContext validationCtx, Errors errors) {
Object value = validationCtx.value(name);
boolean isFalse = false;
if (value != null && value instanceof Boolean)
isFalse = Boolean.FALSE.equals(value);
if (!isFalse)
errors.add(name, assertFalseAnnotation.message(), value);
}
ReflectionMagicWorksTest.java 文件源码
项目:backstopper
阅读 30
收藏 0
点赞 0
评论 0
/**
* Makes sure that the Reflections helper stuff is working properly and capturing all annotation possibilities (class type, constructor, constructor param, method, method param, and field).
*/
@Test
public void verifyThatTheReflectionsConfigurationIsCapturingAllAnnotationPossibilities() {
List<Pair<Annotation, AnnotatedElement>> annotationOptionsClassAnnotations = getSubAnnotationListForElementsOfOwnerClass(TROLLER.allConstraintAnnotationsMasterList,
DifferentValidationAnnotationOptions.class);
assertThat(annotationOptionsClassAnnotations.size(), is(10));
assertThat(getSubAnnotationListForAnnotationsOfClassType(annotationOptionsClassAnnotations, SomeClassLevelJsr303Annotation.class).size(), is(2));
assertThat(getSubAnnotationListForAnnotationsOfClassType(annotationOptionsClassAnnotations, OtherClassLevelJsr303Annotation.class).size(), is(1));
assertThat(getSubAnnotationListForAnnotationsOfClassType(annotationOptionsClassAnnotations, AssertTrue.class).size(), is(1));
assertThat(getSubAnnotationListForAnnotationsOfClassType(annotationOptionsClassAnnotations, AssertFalse.class).size(), is(1));
assertThat(getSubAnnotationListForAnnotationsOfClassType(annotationOptionsClassAnnotations, NotNull.class).size(), is(2));
assertThat(getSubAnnotationListForAnnotationsOfClassType(annotationOptionsClassAnnotations, Min.class).size(), is(2));
assertThat(getSubAnnotationListForAnnotationsOfClassType(annotationOptionsClassAnnotations, Max.class).size(), is(1));
}
ReflectionMagicWorksTest.java 文件源码
项目:backstopper
阅读 25
收藏 0
点赞 0
评论 0
@AssertFalse(message = "I am an annotated method")
public boolean annotatedMethod(String nonAnnotatedMethodParam,
@Max(value = 42, message = "I am an annotated method param 1") Integer annotatedMethodParam1,
@Min(value = 42, message = "I am an annotated method param 2") Integer annotatedMethodParam2,
String alsoNotAnnotatedMethodParam) {
return true;
}
AnnotationMapper.java 文件源码
项目:benerator
阅读 22
收藏 0
点赞 0
评论 0
private static void mapBeanValidationParameter(Annotation annotation, InstanceDescriptor element) {
SimpleTypeDescriptor typeDescriptor = (SimpleTypeDescriptor) element.getLocalType(false);
if (annotation instanceof AssertFalse)
typeDescriptor.setTrueQuota(0.);
else if (annotation instanceof AssertTrue)
typeDescriptor.setTrueQuota(1.);
else if (annotation instanceof DecimalMax)
typeDescriptor.setMax(String.valueOf(DescriptorUtil.convertType(((DecimalMax) annotation).value(), typeDescriptor)));
else if (annotation instanceof DecimalMin)
typeDescriptor.setMin(String.valueOf(DescriptorUtil.convertType(((DecimalMin) annotation).value(), typeDescriptor)));
else if (annotation instanceof Digits) {
Digits digits = (Digits) annotation;
typeDescriptor.setGranularity(String.valueOf(Math.pow(10, - digits.fraction())));
} else if (annotation instanceof Future)
typeDescriptor.setMin(new SimpleDateFormat("yyyy-MM-dd").format(TimeUtil.tomorrow()));
else if (annotation instanceof Max)
typeDescriptor.setMax(String.valueOf(((Max) annotation).value()));
else if (annotation instanceof Min)
typeDescriptor.setMin(String.valueOf(((Min) annotation).value()));
else if (annotation instanceof NotNull) {
element.setNullable(false);
element.setNullQuota(0.);
} else if (annotation instanceof Null) {
element.setNullable(true);
element.setNullQuota(1.);
} else if (annotation instanceof Past)
typeDescriptor.setMax(new SimpleDateFormat("yyyy-MM-dd").format(TimeUtil.yesterday()));
else if (annotation instanceof Pattern)
typeDescriptor.setPattern(String.valueOf(((Pattern) annotation).regexp()));
else if (annotation instanceof Size) {
Size size = (Size) annotation;
typeDescriptor.setMinLength(size.min());
typeDescriptor.setMaxLength(size.max());
}
}
MinijaxConstraintDescriptor.java 文件源码
项目:minijax
阅读 24
收藏 0
点赞 0
评论 0
@SuppressWarnings("unchecked")
public static <T extends Annotation> MinijaxConstraintDescriptor<T> build(final AnnotatedType annotatedType, final T annotation) {
final Constraint constraint = annotation.annotationType().getAnnotation(Constraint.class);
if (constraint == null) {
return null;
}
final Class<?> valueClass = ReflectionUtils.getRawType(annotatedType);
final Class<?> annotationClass = annotation.annotationType();
if (constraint.validatedBy().length > 0) {
return buildDeclaredValidator(annotation, constraint.validatedBy()[0]);
} else if (annotationClass == AssertFalse.class) {
return (MinijaxConstraintDescriptor<T>) buildAssertFalseValidator((AssertFalse) annotation, valueClass);
} else if (annotationClass == AssertTrue.class) {
return (MinijaxConstraintDescriptor<T>) buildAssertTrueValidator((AssertTrue) annotation, valueClass);
} else if (annotationClass == Max.class) {
return (MinijaxConstraintDescriptor<T>) buildMaxValidator((Max) annotation, valueClass);
} else if (annotationClass == Min.class) {
return (MinijaxConstraintDescriptor<T>) buildMinValidator((Min) annotation, valueClass);
} else if (annotationClass == NotBlank.class) {
return (MinijaxConstraintDescriptor<T>) buildNotBlankValidator((NotBlank) annotation, valueClass);
} else if (annotationClass == NotEmpty.class) {
return (MinijaxConstraintDescriptor<T>) buildNotEmptyValidator((NotEmpty) annotation, valueClass);
} else if (annotationClass == NotNull.class) {
return (MinijaxConstraintDescriptor<T>) buildNotNullValidator((NotNull) annotation);
} else if (annotationClass == Pattern.class) {
return (MinijaxConstraintDescriptor<T>) buildPatternValidator((Pattern) annotation, valueClass);
} else if (annotationClass == Size.class) {
return (MinijaxConstraintDescriptor<T>) buildSizeValidator((Size) annotation, valueClass);
} else {
throw new ValidationException("Unrecognized constraint annotation: " + annotation);
}
}
ObservationDTOBase.java 文件源码
项目:oma-riista-web
阅读 18
收藏 0
点赞 0
评论 0
@AssertFalse
public boolean isGeolocationSourceNull() {
return getGeoLocation().getSource() == null;
}
AssertFalseValidationAdapter.java 文件源码
项目:geeMVC-Java-MVC-Framework
阅读 23
收藏 0
点赞 0
评论 0
@Override
public boolean incudeInValidation(AssertFalse validationAnnotation, RequestHandler requestHandler, ValidationContext validationCtx) {
return true;
}
CassandraProperties.java 文件源码
项目:cassandra
阅读 22
收藏 0
点赞 0
评论 0
@AssertFalse(message = "both 'username' and 'password' are required or neither one")
private boolean isInvalid() {
return StringUtils.hasText(this.username) ^ StringUtils.hasText(this.password);
}
TriggerPropertiesMaxMessagesDefaultOne.java 文件源码
项目:spring-cloud-stream-app-starters
阅读 20
收藏 0
点赞 0
评论 0
@AssertFalse
public boolean isMutuallyExclusive() {
return this.date != null && this.cron != null && this.fixedDelay != 1;
}
TriggerProperties.java 文件源码
项目:spring-cloud-stream-app-starters
阅读 21
收藏 0
点赞 0
评论 0
@AssertFalse
boolean isMutuallyExclusive();
TriggerPropertiesMaxMessagesDefaultUnlimited.java 文件源码
项目:spring-cloud-stream-app-starters
阅读 18
收藏 0
点赞 0
评论 0
@AssertFalse
public boolean isMutuallyExclusive() {
return this.date != null && this.cron != null && this.fixedDelay != 1;
}
CassandraProperties.java 文件源码
项目:spring-cloud-stream-app-starters
阅读 23
收藏 0
点赞 0
评论 0
@AssertFalse(message = "both 'username' and 'password' are required or neither one")
private boolean isInvalid() {
return StringUtils.hasText(this.username) ^ StringUtils.hasText(this.password);
}
ModelCreator.java 文件源码
项目:putnami-web-toolkit
阅读 25
收藏 0
点赞 0
评论 0
private void appendFalseValidator(SourceWriter w, JField field) {
AssertFalse falseAnnotation = field.getAnnotation(AssertFalse.class);
if (falseAnnotation != null) {
w.println(", new AssertFalseValidator(\"%s\")", falseAnnotation.message());
}
}
ValidationCdiDataService.java 文件源码
项目:ocelot
阅读 20
收藏 0
点赞 0
评论 0
public void methodWithArgumentFalse(@AssertFalse Boolean bool0) {}