Package javax.validation.metadata

Examples of javax.validation.metadata.PropertyDescriptor


     * {@link ConstraintFinder#lookingAt(javax.validation.metadata.Scope)}.
     */
    public void testConstraintFinderLookingAt() {
        Validator validator = getValidator();
       
        PropertyDescriptor nameDescriptor = validator.getConstraintsForClass( Woman.class ).getConstraintsForProperty("name");
        Set<ConstraintDescriptor<?>> constraints = nameDescriptor.findConstraints().lookingAt(Scope.HIERARCHY).getConstraintDescriptors();
        Assert.assertEquals("Incorrect number of descriptors", 1, constraints.size());
       
        constraints = nameDescriptor.findConstraints().lookingAt(Scope.LOCAL_ELEMENT).getConstraintDescriptors();
        Assert.assertEquals("Incorrect number of descriptors", 0, constraints.size());
    }
View Full Code Here


public class BeanValidationMetadataExtractor {

    public static Set<ConstraintDescriptor<?>> extractAllConstraintDescriptors(FacesContext context, RequestContext requestContext, ValueExpression ve) {

        PropertyDescriptor propertyDescriptor = extractPropertyDescriptor(context, requestContext, ve);

        if (propertyDescriptor != null) {
            return propertyDescriptor.getConstraintDescriptors();
        }
       
        return null;
    }
View Full Code Here

        return extractConstraintDescriptors(context, requestContext, ve, Default.class);
    }
   
    public static Set<ConstraintDescriptor<?>> extractConstraintDescriptors(FacesContext context, RequestContext requestContext, ValueExpression ve, Class... groups) {

        PropertyDescriptor propertyDescriptor = extractPropertyDescriptor(context, requestContext, ve);

        if (propertyDescriptor != null) {
            return propertyDescriptor.findConstraints().unorderedAndMatchingGroups(groups).getConstraintDescriptors();
        }
       
        return null;
    }
View Full Code Here

   
    String currentProperty = beanValidationContext.getCurrentProperty();
   
    if(currentProperty == null) return;
   
    PropertyDescriptor propertyDescriptor = beanDescriptor.getConstraintsForProperty(currentProperty);
   
    if(propertyDescriptor == null) return;
   
    for (final ConstraintDescriptor<?> descriptor :propertyDescriptor.getConstraintDescriptors())
    {
      Class<? extends Annotation> annotationType = descriptor.getAnnotation().annotationType();
     
      ClientConstraintDescriptor clientConstraintDescriptor = clientValidatorSource.getConstraintDescriptor(annotationType);
     
View Full Code Here

   
    if(currentProperty == null) return;
   
    BeanDescriptor beanDescriptor = validator.getConstraintsForClass(beanValidationContext.getBeanType());
   
    PropertyDescriptor propertyDescriptor = beanDescriptor.getConstraintsForProperty(currentProperty);
   
    if(propertyDescriptor == null) return;
   
    final Set<ConstraintViolation<Object>> violations = validator.validateValue(
            (Class<Object>) beanValidationContext.getBeanType(), currentProperty,
View Full Code Here

  public void testIgnoreAnnotations() {
    Validator validator = TestUtil.getValidatorUnderTest();
    BeanDescriptor beanDescriptor = validator.getConstraintsForClass( User.class );
    assertNotNull( beanDescriptor );

    PropertyDescriptor propDescriptor = beanDescriptor.getConstraintsForProperty( "firstname" );
    assertNull( propDescriptor, "The annotation defined constraints should be ignored." );
  }
View Full Code Here

  public void testIncludeAnnotations() {
    Validator validator = TestUtil.getValidatorUnderTest();
    BeanDescriptor beanDescriptor = validator.getConstraintsForClass( User.class );
    assertNotNull( beanDescriptor );

    PropertyDescriptor propDescriptor = beanDescriptor.getConstraintsForProperty( "lastname" );
    assertNotNull( propDescriptor );

    Set<ConstraintDescriptor<?>> constraintDescriptors = propDescriptor.getConstraintDescriptors();
    assertEquals( constraintDescriptors.size(), 2, "There should be two constraints" );

    boolean foundNotNullConstraint = false;
    boolean foundPatternConstraint = false;
    for ( ConstraintDescriptor<?> descriptor : constraintDescriptors ) {
View Full Code Here

  public void testCascadedConfiguration() {
    Validator validator = TestUtil.getValidatorUnderTest();
    BeanDescriptor beanDescriptor = validator.getConstraintsForClass( User.class );
    assertNotNull( beanDescriptor );

    PropertyDescriptor propDescriptor = beanDescriptor.getConstraintsForProperty( "firstCreditCard" );
    assertNotNull( propDescriptor );
    assertTrue( propDescriptor.isCascaded(), "Cascaded validation is configured via xml." );

    propDescriptor = beanDescriptor.getConstraintsForProperty( "secondCreditCard" );
    assertNull( propDescriptor, "The @Valid annotation should be ignored." );
  }
View Full Code Here

  public void testGroupConversionsAreAdditive() {
    Validator validator = TestUtil.getValidatorUnderTest();
    BeanDescriptor beanDescriptor = validator.getConstraintsForClass( User.class );
    assertNotNull( beanDescriptor );

    PropertyDescriptor propDescriptor = beanDescriptor.getConstraintsForProperty( "firstCreditCard" );
    assertNotNull( propDescriptor );
    assertTrue( propDescriptor.isCascaded(), "Cascaded validation is configured via xml." );
    Set<GroupConversionDescriptor> groupConversionDescriptorSet = propDescriptor.getGroupConversions();

    assertTrue(
        groupConversionDescriptorSet.size() == 2,
        "There should be two group conversions. One configured via annotations and one via XML"
    );
View Full Code Here

  public void testAnnotationsIncluded() {
    Validator validator = TestUtil.getValidatorUnderTest();
    BeanDescriptor beanDescriptor = validator.getConstraintsForClass( User.class );
    assertNotNull( beanDescriptor );

    PropertyDescriptor propDescriptor = beanDescriptor.getConstraintsForProperty( "firstname" );
    assertNotNull( propDescriptor );

    Set<ConstraintDescriptor<?>> constraintDescriptors = propDescriptor.getConstraintDescriptors();
    assertEquals( constraintDescriptors.size(), 1, "There should be two constraints" );
    ConstraintDescriptor<?> descriptor = constraintDescriptors.iterator().next();
    assertTrue( descriptor.getAnnotation() instanceof NotNull, "Wrong constraint annotation." );
  }
View Full Code Here

TOP

Related Classes of javax.validation.metadata.PropertyDescriptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.