当前位置: 首页>>代码示例>>Java>>正文


Java NotEmpty类代码示例

本文整理汇总了Java中javax.validation.constraints.NotEmpty的典型用法代码示例。如果您正苦于以下问题:Java NotEmpty类的具体用法?Java NotEmpty怎么用?Java NotEmpty使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


NotEmpty类属于javax.validation.constraints包,在下文中一共展示了NotEmpty类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildNotEmptyValidator

import javax.validation.constraints.NotEmpty; //导入依赖的package包/类
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);
}
 
开发者ID:minijax,项目名称:minijax,代码行数:20,代码来源:MinijaxConstraintDescriptor.java

示例2: objectInvalid

import javax.validation.constraints.NotEmpty; //导入依赖的package包/类
/**
 * 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());
	}
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:25,代码来源:JAXRSBeanValidationImplicitInInterceptorTest.java

示例3: testConstraintViolationExceptionParameter

import javax.validation.constraints.NotEmpty; //导入依赖的package包/类
@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, null, "interpolated", Wine.class, bean, new Object(),
			"value", path, notEmptyNameDescriptor, ElementType.PARAMETER, null, 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());
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:22,代码来源:ValidationJsonExceptionTest.java

示例4: testConstraintViolationException

import javax.validation.constraints.NotEmpty; //导入依赖的package包/类
@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, (Member) null,
			getAnnotation("name", NotEmpty.class), ElementType.FIELD);
	final ConstraintDescriptor<NotEmpty> notEmptyGrapesDescriptor = new ConstraintDescriptorImpl<>(helper, (Member) null,
			getAnnotation("grapes", NotEmpty.class), ElementType.FIELD);
	final ConstraintDescriptor<Length> lengthNameDescriptor = new ConstraintDescriptorImpl<>(helper, (Member) null,
			getAnnotation("name", Length.class), ElementType.FIELD);
	violations.add(ConstraintViolationImpl.<Wine> forBeanValidation("name-Empty", null, null, "interpolated", Wine.class, bean, new Object(),
			"value", PathImpl.createPathFromString("name"), notEmptyNameDescriptor, ElementType.FIELD, null));
	violations.add(ConstraintViolationImpl.<Wine> forBeanValidation("name-length", null, null, "interpolated", Wine.class, bean, new Object(),
			"value", PathImpl.createPathFromString("name"), lengthNameDescriptor, ElementType.FIELD, null));
	violations.add(ConstraintViolationImpl.<Wine> forBeanValidation("grapes-Empty", null, null, "interpolated", Wine.class, bean, new Object(),
			"value", PathImpl.createPathFromString("grapes"), notEmptyGrapesDescriptor, ElementType.FIELD, 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());
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:29,代码来源:ValidationJsonExceptionTest.java

示例5: jsr349Collection

import javax.validation.constraints.NotEmpty; //导入依赖的package包/类
/**
 * @param params Collection parameter with several constraints.
 */
public void jsr349Collection(final @NotEmpty @Size(max = 2) Collection<Object> params) {
	//
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:7,代码来源:JAXRSBeanValidationImplicitInInterceptorTest.java

示例6: getSourceAttributes

import javax.validation.constraints.NotEmpty; //导入依赖的package包/类
@NotEmpty
public abstract List<String> getSourceAttributes();
 
开发者ID:molgenis,项目名称:molgenis,代码行数:3,代码来源:GenerateAlgorithmRequest.java

示例7: getOntologyIds

import javax.validation.constraints.NotEmpty; //导入依赖的package包/类
@NotEmpty
public abstract List<String> getOntologyIds();
 
开发者ID:molgenis,项目名称:molgenis,代码行数:3,代码来源:AutoTagRequest.java

示例8: getOntologyTermIRI

import javax.validation.constraints.NotEmpty; //导入依赖的package包/类
@NotEmpty
public abstract String getOntologyTermIRI();
 
开发者ID:molgenis,项目名称:molgenis,代码行数:3,代码来源:RemoveTagRequest.java

示例9: getOntologyTermIRIs

import javax.validation.constraints.NotEmpty; //导入依赖的package包/类
@NotEmpty
public abstract List<String> getOntologyTermIRIs();
 
开发者ID:molgenis,项目名称:molgenis,代码行数:3,代码来源:AddTagRequest.java

示例10: getEntities

import javax.validation.constraints.NotEmpty; //导入依赖的package包/类
@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();
 
开发者ID:molgenis,项目名称:molgenis,代码行数:5,代码来源:EntityCollectionBatchRequestV2.java

示例11: getEntityIds

import javax.validation.constraints.NotEmpty; //导入依赖的package包/类
@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();
 
开发者ID:molgenis,项目名称:molgenis,代码行数:4,代码来源:EntityCollectionDeleteRequestV2.java

示例12: setEmail

import javax.validation.constraints.NotEmpty; //导入依赖的package包/类
@NotEmpty
@Email
@Size(max = 128)
public void setEmail(String email) {
	this.email = email;
}
 
开发者ID:ralscha,项目名称:extclassgenerator,代码行数:7,代码来源:UserClass.java

示例13: getEmail

import javax.validation.constraints.NotEmpty; //导入依赖的package包/类
@NotEmpty
@Email
@Size(max = 128)
String getEmail();
 
开发者ID:ralscha,项目名称:extclassgenerator,代码行数:5,代码来源:User.java

示例14: build

import javax.validation.constraints.NotEmpty; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:minijax,项目名称:minijax,代码行数:45,代码来源:MinijaxConstraintDescriptor.java

示例15: doCheckMismatchedValidatorAnnotation

import javax.validation.constraints.NotEmpty; //导入依赖的package包/类
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();
}
 
开发者ID:lastaflute,项目名称:lastaflute,代码行数:42,代码来源:ExecuteMethodValidatorChecker.java


注:本文中的javax.validation.constraints.NotEmpty类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。