Package javax.validation.metadata

Examples of javax.validation.metadata.PropertyDescriptor


      @SpecAssertion(section = "6.3", id = "b"),
      @SpecAssertion(section = "6.4", id = "a")
  })
  public void testGetConstraintsForUnConstrainedProperty() {
    BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Customer.class );
    PropertyDescriptor propertyDescriptor = beanDescriptor.getConstraintsForProperty(
        "orderList"
    );
    assertEquals(
        propertyDescriptor.getConstraintDescriptors().size(),
        0,
        "There should be no constraint descriptors"
    );
    assertTrue( propertyDescriptor.isCascaded(), "The property should be cascaded" );
  }
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

                beanDescriptor = validator.getConstraintsForClass(beanType);
            }
        }

        final String propertyName = path[path.length - 1];
        PropertyDescriptor propertyDescriptor = beanDescriptor.getConstraintsForProperty(propertyName);

        if (propertyDescriptor == null) return;

        final Set<ConstraintViolation<Object>> violations = validator.validateValue(
                (Class<Object>) beanType, propertyName,
View Full Code Here

  public ConstraintIterator(Validator validator, Property property, Class<?>... groups)
  {
    BeanDescriptor beanDesc = validator.getConstraintsForClass(property.getOwner());
    if (beanDesc != null)
    {
      PropertyDescriptor propDesc = beanDesc.getConstraintsForProperty(property.getName());
      if (propDesc != null)
      {
        // TODO use hasConstraintDesc to optimize...?
        Set<ConstraintDescriptor<?>> constraints = propDesc.findConstraints()
          .unorderedAndMatchingGroups(groups)
          .getConstraintDescriptors();
        if (constraints != null)
        {
          stack.add(constraints.iterator());
View Full Code Here

    return beanDescriptor.getConstraintsForMethod( method.getName(), method.getParameterTypes() ) != null;
  }

  private boolean isGetterConstrained(Method method, BeanDescriptor beanDescriptor) {
    String propertyName = ReflectionHelper.getPropertyName( method );
    PropertyDescriptor propertyDescriptor = beanDescriptor.getConstraintsForProperty( propertyName );
    return propertyDescriptor != null && propertyDescriptor.findConstraints()
        .declaredOn( ElementType.METHOD )
        .hasConstraints();
  }
View Full Code Here

        Assert.assertEquals(4, bookBeanDescriptor.getConstrainedProperties().size());
        // not a property
        Assert.assertTrue(bookBeanDescriptor.getConstraintsForProperty("doesNotExist") == null);
        // property with no constraint
        Assert.assertTrue(bookBeanDescriptor.getConstraintsForProperty("description") == null);
        PropertyDescriptor propertyDescriptor = bookBeanDescriptor.getConstraintsForProperty("title");
        Assert.assertEquals(2, propertyDescriptor.getConstraintDescriptors().size());
        Assert.assertTrue("title".equals(propertyDescriptor.getPropertyName()));
        // assuming the implementation returns the NotEmpty constraint first
        Iterator<ConstraintDescriptor<?>> iter = propertyDescriptor.getConstraintDescriptors().iterator();
        ConstraintDescriptor<?> constraintDescriptor = null;
        while (iter.hasNext()) {
            constraintDescriptor = iter.next();
            if (constraintDescriptor.getAnnotation().annotationType().equals(NotNull.class)) {
                break;
            }

        }
        Assert.assertTrue(constraintDescriptor != null);
        Assert.assertTrue(constraintDescriptor.getGroups().size() == 1); // "first"
        Assert.assertEquals(NotNullValidator.class, constraintDescriptor.getConstraintValidatorClasses().get(0));
        // assuming the implementation returns the Size constraint first
        propertyDescriptor = bookBeanDescriptor.getConstraintsForProperty("subtitle");
        Iterator<ConstraintDescriptor<?>> iterator = propertyDescriptor.getConstraintDescriptors().iterator();
        constraintDescriptor = iterator.next();
        Assert.assertTrue(constraintDescriptor.getAnnotation().annotationType().equals(Size.class));
        Assert.assertTrue(((Integer) constraintDescriptor.getAttributes().get("max")) == 30);
        Assert.assertTrue(constraintDescriptor.getGroups().size() == 1);
        propertyDescriptor = bookBeanDescriptor.getConstraintsForProperty("author");
        Assert.assertTrue(propertyDescriptor.getConstraintDescriptors().size() == 1);
        Assert.assertTrue(propertyDescriptor.isCascaded());
        Assert.assertNull(bookBeanDescriptor.getConstraintsForProperty("unconstraintField"));
    }
View Full Code Here

  public void testGroupMembership() {
    Validator validator = TestUtil.getValidatorUnderTest();
    BeanDescriptor descriptor = validator.getConstraintsForClass( MiniaturePart.class );

    //  PreManufacturing belongs implicitly to All
    PropertyDescriptor propertyDescriptor = descriptor.getConstraintsForProperty( "partNumber" );
    Set<ConstraintDescriptor<?>> descriptorsForGroup = propertyDescriptor.findConstraints()
        .unorderedAndMatchingGroups( All.class )
        .getConstraintDescriptors();
    assertEquals( descriptorsForGroup.size(), 1, "Wrong number of descriptors" );
    assertEquals( descriptorsForGroup.iterator().next().getAnnotation().annotationType(), Digits.class );

    //  PostManufacturing belongs implicitly to All
    propertyDescriptor = descriptor.getConstraintsForProperty( "qaChecked" );
    descriptorsForGroup = propertyDescriptor.findConstraints()
        .unorderedAndMatchingGroups( All.class )
        .getConstraintDescriptors();
    assertEquals( descriptorsForGroup.size(), 1, "Wrong number of descriptors" );
        assertEquals( descriptorsForGroup.iterator().next().getAnnotation().annotationType(), AssertTrue.class );

    propertyDescriptor = descriptor.getConstraintsForProperty( "size" );
    descriptorsForGroup = propertyDescriptor.findConstraints()
        .unorderedAndMatchingGroups( All.class )
        .getConstraintDescriptors();
    assertEquals( descriptorsForGroup.size(), 1, "Wrong number of descriptors" );
    assertEquals( descriptorsForGroup.iterator().next().getAnnotation().annotationType(), Max.class );
  }
View Full Code Here

    Validator validator = TestUtil.getValidatorUnderTest();
    BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Bar.class );

    String propertyName = "foo";
    assertTrue( beanDescriptor.getConstraintsForProperty( propertyName ) != null );
    PropertyDescriptor propDescriptor = beanDescriptor.getConstraintsForProperty( propertyName );

    // cast is required for JDK 5 - at least on Mac OS X
    Annotation constraintAnnotation = ( Annotation ) propDescriptor.getConstraintDescriptors()
        .iterator()
        .next().getAnnotation();
    assertTrue( constraintAnnotation.annotationType() == NotNull.class );
  }
View Full Code Here

    Validator validator = TestUtil.getValidatorUnderTest();
    BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Bar.class );

    String propertyName = "fubar";
    assertTrue( beanDescriptor.getConstraintsForProperty( propertyName ) != null );
    PropertyDescriptor propDescriptor = beanDescriptor.getConstraintsForProperty( propertyName );

    // cast is required for JDK 5 - at least on Mac OS X
    Annotation constraintAnnotation = ( Annotation ) propDescriptor.getConstraintDescriptors()
        .iterator()
        .next().getAnnotation();
    assertTrue( constraintAnnotation.annotationType() == NotNull.class );
  }
View Full Code Here

  public void testGroupMembership() {
    Validator validator = TestUtil.getValidatorUnderTest();
    BeanDescriptor descriptor = validator.getConstraintsForClass( MiniaturePart.class );

    //  PreManufacturing belongs implicitly to All
    PropertyDescriptor propertyDescriptor = descriptor.getConstraintsForProperty( "partNumber" );
    Set<ConstraintDescriptor<?>> descriptorsForGroup = propertyDescriptor.getUnorderedConstraintDescriptorsMatchingGroups(
        All.class
    );
    assertEquals( descriptorsForGroup.size(), 1, "Wrong number of descriptors" );
    assertEquals( descriptorsForGroup.iterator().next().getAnnotation().annotationType(), Digits.class );

    //  PostManufacturing belongs implicitly to All
    propertyDescriptor = descriptor.getConstraintsForProperty( "qaChecked" );
    descriptorsForGroup = propertyDescriptor.getUnorderedConstraintDescriptorsMatchingGroups( All.class );
    assertEquals( descriptorsForGroup.size(), 1, "Wrong number of descriptors" );
    assertEquals( descriptorsForGroup.iterator().next().getAnnotation().annotationType(), AssertTrue.class );

    propertyDescriptor = descriptor.getConstraintsForProperty( "size" );
    descriptorsForGroup = propertyDescriptor.getUnorderedConstraintDescriptorsMatchingGroups( All.class );
    assertEquals( descriptorsForGroup.size(), 1, "Wrong number of descriptors" );
    assertEquals( descriptorsForGroup.iterator().next().getAnnotation().annotationType(), Max.class );
  }
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.