Java 类org.hibernate.validator.internal.metadata.core.ConstraintHelper 实例源码

项目: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, 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());
}
项目:nest-old    文件:BeanMetaDataManager513.java   
/**
 * Creates a new {@code BeanMetaDataManager}.
 *
 * @param constraintHelper
 *            the constraint helper
 * @param executableHelper
 *            the executable helper
 * @param parameterNameProvider
 *            the parameter name provider
 * @param optionalMetaDataProviders
 *            optional meta data provider used on top of the annotation
 *            based provider
 */
public BeanMetaDataManager513(ConstraintHelper constraintHelper, ExecutableHelper executableHelper,
        ParameterNameProvider parameterNameProvider, List<MetaDataProvider> optionalMetaDataProviders) {
    super(constraintHelper, executableHelper, parameterNameProvider, optionalMetaDataProviders);
    this.constraintHelper = constraintHelper;
    this.metaDataProviders = newArrayList();
    this.metaDataProviders.addAll(optionalMetaDataProviders);
    this.executableHelper = executableHelper;

    this.beanMetaDataCache = new ConcurrentReferenceHashMap<Class<?>, BeanMetaData<?>>(DEFAULT_INITIAL_CAPACITY,
            DEFAULT_LOAD_FACTOR, DEFAULT_CONCURRENCY_LEVEL, SOFT, SOFT, EnumSet.of(IDENTITY_COMPARISONS));

    AnnotationProcessingOptions annotationProcessingOptions = getAnnotationProcessingOptionsFromNonDefaultProviders();
    AnnotationMetaDataProvider defaultProvider = new AnnotationMetaDataProvider(constraintHelper,
            parameterNameProvider, annotationProcessingOptions);
    this.metaDataProviders.add(defaultProvider);
}
项目: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, (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());
}
项目:nest-old    文件:BeanMetaDataImpl513.java   
@SuppressWarnings("incomplete-switch")
public BuilderDelegate(Class<?> beanClass, ConstrainedElement constrainedElement,
        ConstraintHelper constraintHelper, ExecutableHelper executableHelper) {
    this.beanClass = beanClass;
    this.constraintHelper = constraintHelper;
    this.executableHelper = executableHelper;

    switch (constrainedElement.getKind()) {
    case FIELD:
        ConstrainedField constrainedField = (ConstrainedField) constrainedElement;
        propertyBuilder = new PropertyMetaData.Builder(beanClass, constrainedField, constraintHelper);
        break;
    case CONSTRUCTOR:
    case METHOD:
        ConstrainedExecutable constrainedExecutable = (ConstrainedExecutable) constrainedElement;
        methodBuilder = new ExecutableMetaData.Builder(beanClass, constrainedExecutable, constraintHelper,
                executableHelper);

        if (constrainedExecutable.isGetterMethod()) {
            propertyBuilder = new PropertyMetaData.Builder(beanClass, constrainedExecutable, constraintHelper);
        }
        break;
    case TYPE:
        ConstrainedType constrainedType = (ConstrainedType) constrainedElement;
        propertyBuilder = new PropertyMetaData.Builder(beanClass, constrainedType, constraintHelper);
        break;
    }
}
项目:gwt-bean-validators    文件:ConstraintDescriptorImpl.java   
@Override
public String getMessageTemplate() {
  return (String) this.getAttributes().get(ConstraintHelper.MESSAGE);
}
项目:gwt-bean-validators    文件:ConstraintDescriptorImpl.java   
@Override
public ConstraintTarget getValidationAppliesTo() {
  return (ConstraintTarget) this.attributes.get(ConstraintHelper.VALIDATION_APPLIES_TO);
}
项目:nest-old    文件:ValidatorFactoryImpl513.java   
public ValidatorFactoryImpl513(ConfigurationState configurationState) {
    this.messageInterpolator = configurationState.getMessageInterpolator();
    this.traversableResolver = configurationState.getTraversableResolver();
    this.parameterNameProvider = configurationState.getParameterNameProvider();
    this.beanMetaDataManagerMap = Collections
            .synchronizedMap(new IdentityHashMap<ParameterNameProvider, BeanMetaDataManager513>());
    this.constraintHelper = new ConstraintHelper();
    this.typeResolutionHelper = new TypeResolutionHelper();
    this.executableHelper = new ExecutableHelper(typeResolutionHelper);

    // HV-302; don't load XmlMappingParser if not necessary
    if (configurationState.getMappingStreams().isEmpty()) {
        this.xmlMetaDataProvider = null;
    } else {
        this.xmlMetaDataProvider = new XmlMetaDataProvider(constraintHelper, parameterNameProvider,
                configurationState.getMappingStreams());
    }

    Map<String, String> properties = configurationState.getProperties();

    boolean tmpFailFast = false;
    List<ValidatedValueUnwrapper<?>> tmpValidatedValueHandlers = newArrayList(5);
    Set<DefaultConstraintMapping> tmpConstraintMappings = newHashSet();

    if (configurationState instanceof ConfigurationImpl) {
        ConfigurationImpl hibernateSpecificConfig = (ConfigurationImpl) configurationState;

        if (hibernateSpecificConfig.getProgrammaticMappings().size() > 0) {
            tmpConstraintMappings.addAll(hibernateSpecificConfig.getProgrammaticMappings());
        }
        // check whether fail fast is programmatically enabled
        tmpFailFast = hibernateSpecificConfig.getFailFast();

        tmpValidatedValueHandlers.addAll(hibernateSpecificConfig.getValidatedValueHandlers());

    }
    this.constraintMappings = Collections.unmodifiableSet(tmpConstraintMappings);

    tmpFailFast = checkPropertiesForFailFast(properties, tmpFailFast);
    this.failFast = tmpFailFast;

    tmpValidatedValueHandlers.addAll(getPropertyConfiguredValidatedValueHandlers(properties));
    this.validatedValueHandlers = Collections.unmodifiableList(tmpValidatedValueHandlers);

    this.constraintValidatorManager = new ConstraintValidatorManager(
            configurationState.getConstraintValidatorFactory());
}
项目:nest-old    文件:BeanMetaDataImpl513.java   
private BeanMetaDataBuilder(ConstraintHelper constraintHelper, ExecutableHelper executableHelper,
        Class<T> beanClass) {
    this.beanClass = beanClass;
    this.constraintHelper = constraintHelper;
    this.executableHelper = executableHelper;
}
项目:nest-old    文件:BeanMetaDataImpl513.java   
public static <T> BeanMetaDataBuilder<T> getInstance(ConstraintHelper constraintHelper,
        ExecutableHelper executableHelper, Class<T> beanClass) {
    return new BeanMetaDataBuilder<T>(constraintHelper, executableHelper, beanClass);
}
项目:nest-old    文件:ProgrammaticMetaDataProvider513.java   
public ProgrammaticMetaDataProvider513(ConstraintHelper constraintHelper,
        ParameterNameProvider parameterNameProvider, Set<DefaultConstraintMapping> constraintMappings) {
    super(constraintHelper, parameterNameProvider, constraintMappings);
}
项目:nest-old    文件:BeanMetaDataManager513.java   
/**
 * Creates a new {@code BeanMetaDataManager}.
 * {@link DefaultParameterNameProvider} is used as parameter name provider,
 * no meta data providers besides the annotation-based providers are used.
 *
 * @param constraintHelper
 *            the constraint helper
 * @param executableHelper
 *            the executable helper
 */
public BeanMetaDataManager513(ConstraintHelper constraintHelper, ExecutableHelper executableHelper) {
    this(constraintHelper, executableHelper, new DefaultParameterNameProvider(), Collections
            .<MetaDataProvider> emptyList());
}