微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javax.validation.constraints.NotEmpty的实例源码

项目:minijax    文件MinijaxConstraintDescriptor.java   
private static MinijaxConstraintDescriptor<NotEmpty> buildNotEmptyValidator(final NotEmpty notEmpty,final Class<?> valueClass) {
    if (valueClass.isArray()) {
        return new MinijaxConstraintDescriptor<>(notEmpty,NotEmptyValidatorForArray.INSTANCE);
    }

    if (CharSequence.class.isAssignableFrom(valueClass)) {
        return new MinijaxConstraintDescriptor<>(notEmpty,NotEmptyValidatorForCharSequence.INSTANCE);
    }

    if (Collection.class.isAssignableFrom(valueClass)) {
        return new MinijaxConstraintDescriptor<>(notEmpty,NotEmptyValidatorForCollection.INSTANCE);
    }

    if (Map.class.isAssignableFrom(valueClass)) {
        return new MinijaxConstraintDescriptor<>(notEmpty,NotEmptyValidatorForMap.INSTANCE);
    }

    throw new ValidationException("Unsupported type for @NotEmpty annotation: " + valueClass);
}
项目:bootstrap    文件JAXRSBeanValidationImplicitininterceptorTest.java   
/**
 * Check not valid parameter operation Failed.
 */
@Test
public void objectInvalid() {
    final SystemUser userDto = new SystemUser();
    userDto.setLogin("");
    try {
        validationInInterceptor.handleValidation(MESSAGE,INSTANCE,fromName("object"),Arrays.asList(userDto));
        Assert.fail("Expected validation errors");
    } catch (final ConstraintViolationException cve) {

        // Check all expected errors are there.
        final Set<ConstraintViolation<?>> constraintViolations = cve.getConstraintViolations();
        Assert.assertNotNull(constraintViolations);
        Assert.assertEquals(1,constraintViolations.size());

        // Check expected errors
        final ConstraintViolation<?> error1 = constraintViolations.iterator().next();
        Assert.assertEquals(NotEmpty.class,error1.getConstraintDescriptor().getAnnotation().annotationType());
        Assert.assertEquals("",error1.getInvalidValue());
        Assert.assertEquals("login",error1.getPropertyPath().toString());
    }
}
项目:bootstrap    文件ValidationjsonExceptionTest.java   
@Test
public void testConstraintViolationExceptionParameter() {
    final Wine bean = new Wine();
    final Set<ConstraintViolation<?>> violations = new LinkedHashSet<>();

    final ConstraintHelper helper = new ConstraintHelper();

    final ConstraintDescriptor<NotEmpty> notEmptyNameDescriptor = new ConstraintDescriptorImpl<>(helper,(Member) null,getAnnotation("name",NotEmpty.class),ElementType.FIELD);
    PathImpl path = PathImpl.createPathFromString("name");
    violations.add(ConstraintViolationImpl.<Wine> forParameterValidation("name-Empty",null,"interpolated",Wine.class,bean,new Object(),"value",path,notEmptyNameDescriptor,ElementType.ParaMETER,null));
    path.addParameterNode("parameter1",0);

    final ConstraintViolationException violationException = Mockito.mock(ConstraintViolationException.class);
    Mockito.when(violationException.getConstraintViolations()).thenReturn(violations);

    final ValidationjsonException validationjsonException = new ValidationjsonException(violationException);
    Assert.assertFalse(validationjsonException.getErrors().isEmpty());
    Assert.assertEquals("{parameter1=[{rule=name-Empty}]}",validationjsonException.getErrors().toString());
}
项目:bootstrap    文件ValidationjsonExceptionTest.java   
@Test
public void testConstraintViolationException() {
    final Wine bean = new Wine();
    final Set<ConstraintViolation<?>> violations = new LinkedHashSet<>();

    final ConstraintHelper helper = new ConstraintHelper();

    final ConstraintDescriptor<NotEmpty> notEmptyNameDescriptor = new ConstraintDescriptorImpl<>(helper,ElementType.FIELD);
    final ConstraintDescriptor<NotEmpty> notEmptyGrapesDescriptor = new ConstraintDescriptorImpl<>(helper,getAnnotation("grapes",ElementType.FIELD);
    final ConstraintDescriptor<Length> lengthNameDescriptor = new ConstraintDescriptorImpl<>(helper,Length.class),ElementType.FIELD);
    violations.add(ConstraintViolationImpl.<Wine> forBeanValidation("name-Empty",PathImpl.createPathFromString("name"),ElementType.FIELD,null));
    violations.add(ConstraintViolationImpl.<Wine> forBeanValidation("name-length",lengthNameDescriptor,null));
    violations.add(ConstraintViolationImpl.<Wine> forBeanValidation("grapes-Empty",PathImpl.createPathFromString("grapes"),notEmptyGrapesDescriptor,null));

    final ConstraintViolationException violationException = Mockito.mock(ConstraintViolationException.class);
    Mockito.when(violationException.getConstraintViolations()).thenReturn(violations);

    final ValidationjsonException validationjsonException = new ValidationjsonException(violationException);
    Assert.assertFalse(validationjsonException.getErrors().isEmpty());
    Assert.assertEquals("{name=[{rule=name-Empty},{rule=name-length,parameters={min=0,max=50}}],grapes=[{rule=grapes-Empty}]}",validationjsonException.getErrors().toString());
}
项目:minijax    文件MinijaxConstraintDescriptor.java   
@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);
    }
}
项目:bootstrap    文件JAXRSBeanValidationImplicitininterceptorTest.java   
/**
 * @param params Collection parameter with several constraints.
 */
public void jsr349Collection(final @NotEmpty @Size(max = 2) Collection<Object> params) {
    //
}
项目:lastaflute    文件ExecuteMethodValidatorChecker.java   
protected void doCheckMismatchedValidatorAnnotation(Field field,Map<String,Class<?>> genericMap) { // recursive point
    pathDeque.push(field.getName());
    checkedTypeSet.add(field.getDeclaringClass());
    final Class<?> fieldType = deriveFieldType(field,genericMap);
    // *depends on JSON rule so difficult,check only physical mismatch here
    //if (isFormPropertyCannotNotNullType(fieldType)) {
    //    final Class<NotNull> notNullType = NotNull.class;
    //    if (field.getAnnotation(notNullType) != null) {
    //        throwExecuteMethodFormPropertyValidationMismatchException(property,notNullType);
    //    }
    //}
    if (isCannotNotEmptyType(fieldType)) {
        final Class<NotEmpty> notEmptyType = NotEmpty.class;
        if (field.getAnnotation(notEmptyType) != null) {
            throwExecuteMethodNotEmptyValidationMismatchException(field,notEmptyType);
        }
    }
    if (isCannotNotBlankType(fieldType)) {
        final Class<NotBlank> notBlankType = NotBlank.class;
        if (field.getAnnotation(notBlankType) != null) {
            throwExecuteMethodNotEmptyValidationMismatchException(field,notBlankType);
        }
    }
    if (isFormPropertyCannotrequiredPrimitiveType(fieldType)) {
        final Class<required> requiredType = required.class;
        if (field.getAnnotation(requiredType) != null) {
            throwExecuteMethodPrimitiveValidationMismatchException(field,requiredType);
        }
        final Class<NotNull> notNullType = NotNull.class;
        if (field.getAnnotation(notNullType) != null) {
            throwExecuteMethodPrimitiveValidationMismatchException(field,notNullType);
        }
    }
    if (Collection.class.isAssignableFrom(fieldType)) { // only collection,except array and map,simply
        doCheckGenericBeanValidationMismatch(field);
    } else if (mayBenestedBeanType(fieldType)) {
        doChecknestedValidationMismatch(fieldType);
        doCheckGenericBeanValidationMismatch(field);
    }
    pathDeque.pop();
}
项目:molgenis    文件GeneratealgorithmRequest.java   
@NotEmpty
public abstract List<String> getSourceAttributes();
项目:molgenis    文件AutoTagRequest.java   
@NotEmpty
public abstract List<String> getontologyIds();
项目:molgenis    文件GetontologyTermRequest.java   
@NotEmpty
public abstract List<String> getontologyIds();
项目:molgenis    文件RemoveTagRequest.java   
@NotEmpty
public abstract String getontologyTermIRI();
项目:molgenis    文件AddTagRequest.java   
@NotEmpty
public abstract List<String> getontologyTermIRIs();
项目:molgenis    文件EntityCollectionBatchRequestV2.java   
@Nullable // See #3897. If hashCode fails,the validation throws an exception
@NotEmpty(message = "Please provide at least one entity in the entities property.")
@Size(max = RestControllerV2.MAX_ENTITIES,message = "Number of entities cannot be more than {max}.")
public abstract List<Map<String,Object>> getEntities();
项目:molgenis    文件EntityCollectionDeleteRequestV2.java   
@NotEmpty(message = "Please provide at least one entity in the entityIds property.")
@Size(max = RestControllerV2.MAX_ENTITIES,message = "Number of entity identifiers cannot be more than {max}.")
public abstract List<String> getEntityIds();
项目:extclassgenerator    文件UserClass.java   
@NotEmpty
@Email
@Size(max = 128)
public void setEmail(String email) {
    this.email = email;
}
项目:extclassgenerator    文件User.java   
@NotEmpty
@Email
@Size(max = 128)
String getEmail();

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。