Package javax.validation.metadata

Examples of javax.validation.metadata.PropertyDescriptor


  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


      @SpecAssertion(section = "5.3", id = "b")
  })
  public void testGetConstraintForConstrainedProperty() {
    Validator validator = TestUtil.getValidatorUnderTest();
    BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Order.class );
    PropertyDescriptor propertyDescriptor = beanDescriptor.getConstraintsForProperty( "orderNumber" );
    assertEquals(
        propertyDescriptor.getConstraintDescriptors().size(), 1, "There should be one constraint descriptor"
    );
  }
View Full Code Here

      @SpecAssertion(section = "5.4", id = "a")
  })
  public void testGetConstraintForUnConstrainedProperty() {
    Validator validator = TestUtil.getValidatorUnderTest();
    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

    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 <T extends Annotation> void testExcludeExistingValidators() {
    Configuration<?> config = TestUtil.getConfigurationUnderTest();
    config.addMapping( TestUtil.getInputStreamForPath( packageName + mappingFile1 ) );
    Validator validator = config.buildValidatorFactory().getValidator();

    PropertyDescriptor propDescriptor = validator.getConstraintsForClass( Name.class )
        .getConstraintsForProperty( "name" );

    Set<ConstraintDescriptor<?>> descriptors = propDescriptor.getConstraintDescriptors();
    assertEquals( descriptors.size(), 1, "There should only be one constraint." );

    @SuppressWarnings("unchecked")
    ConstraintDescriptor<T> descriptor = ( ConstraintDescriptor<T> ) descriptors.iterator().next();
    List<Class<? extends ConstraintValidator<T, ?>>> validators = descriptor.getConstraintValidatorClasses();
View Full Code Here

  public <T extends Annotation> void testIncludeExistingValidators() {
    Configuration<?> config = TestUtil.getConfigurationUnderTest();
    config.addMapping( TestUtil.getInputStreamForPath( packageName + mappingFile2 ) );
    Validator validator = config.buildValidatorFactory().getValidator();

    PropertyDescriptor propDescriptor = validator.getConstraintsForClass( Name.class )
        .getConstraintsForProperty( "name" );


    Set<ConstraintDescriptor<?>> descriptors = propDescriptor.getConstraintDescriptors();
    assertEquals( descriptors.size(), 1, "There should only be one constraint." );

    @SuppressWarnings("unchecked")
    ConstraintDescriptor<T> descriptor = ( ConstraintDescriptor<T> ) descriptors.iterator().next();
    List<Class<? extends ConstraintValidator<T, ?>>> validators = descriptor.getConstraintValidatorClasses();
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

  @SpecAssertion(section = "5.1", id = "b")
  public void testConstraintDescriptorWithoutExplicitGroup() {
    Validator validator = TestUtil.getValidatorUnderTest();

    BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Order.class );
    PropertyDescriptor propertyDescriptor = beanDescriptor.getConstraintsForProperty( "orderNumber" );
    Set<ConstraintDescriptor<?>> descriptors = propertyDescriptor.getConstraintDescriptors();

    assertEquals( descriptors.size(), 1, "There should be only one constraint descriptor" );
    ConstraintDescriptor<?> descriptor = descriptors.iterator().next();
    Set<Class<?>> groups = descriptor.getGroups();
    assertTrue( groups.size() == 1, "There should be only one group" );
View Full Code Here

  })
  public void testRightValidatorIsSelectedAndInitializedCalled() {
    Validator validator = TestUtil.getValidatorUnderTest();
    Shoe shoe = new Shoe();
    shoe.size = -2;
    final PropertyDescriptor propertyDescriptor = validator.getConstraintsForClass( Shoe.class )
        .getConstraintsForProperty( "size" );
    assertNotNull( propertyDescriptor );

    BoundariesConstraintValidator.isValidCalls = 0;
    final Set<ConstraintViolation<Shoe>> constraintViolations = validator.validate( shoe );
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.