Package javax.validation.metadata

Examples of javax.validation.metadata.PropertyDescriptor


  public void testConstraintsOnSuperAndSubClassAddUp() {
    BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Bar.class );

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

    List<Class<? extends Annotation>> constraintTypes = getConstraintTypes( propDescriptor.getConstraintDescriptors() );

    assertEquals( constraintTypes.size(), 2 );
    assertTrue( constraintTypes.contains( DecimalMin.class ) );
    assertTrue( constraintTypes.contains( Size.class ) );
  }
View Full Code Here


  @Test
  @SpecAssertion(section = "6.6", id = "a")
  public void testPropertyName() {
    String propertyName = "orderList";
    PropertyDescriptor descriptor = getPropertyDescriptor( Customer.class, propertyName );
    assertEquals( descriptor.getPropertyName(), propertyName, "Wrong property name" );
  }
View Full Code Here

      @SpecAssertion(section = "6.4", id = "b"),
      @SpecAssertion(section = "6.5", id = "a"),
      @SpecAssertion(section = "6.5", id = "b")
  })
  public void testGetGroupConversionsForField() {
    PropertyDescriptor descriptor = getPropertyDescriptor( Customer.class, "orderList" );
    Set<GroupConversionDescriptor> groupConversions = descriptor.getGroupConversions();

    assertEquals( groupConversions.size(), 2 );

    for ( GroupConversionDescriptor groupConversionDescriptor : groupConversions ) {
      if ( groupConversionDescriptor.getFrom().equals( Default.class ) ) {
View Full Code Here

      @SpecAssertion(section = "6.4", id = "b"),
      @SpecAssertion(section = "6.5", id = "a"),
      @SpecAssertion(section = "6.5", id = "b")
  })
  public void testGetGroupConversionsForProperty() {
    PropertyDescriptor descriptor = getPropertyDescriptor( Customer.class, "account" );
    Set<GroupConversionDescriptor> groupConversions = descriptor.getGroupConversions();

    assertEquals( groupConversions.size(), 2 );

    for ( GroupConversionDescriptor groupConversionDescriptor : groupConversions ) {
      if ( groupConversionDescriptor.getFrom().equals( Default.class ) ) {
View Full Code Here

  }

  @Test
  @SpecAssertion(section = "6.4", id = "b")
  public void testGetGroupConversionsReturnsEmptySet() {
    PropertyDescriptor descriptor = getPropertyDescriptor( Customer.class, "firstName" );
    Set<GroupConversionDescriptor> groupConversions = descriptor.getGroupConversions();

    assertNotNull( groupConversions );
    assertTrue( groupConversions.isEmpty() );
  }
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

  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

  public void testConstraintWithNoExplicitlySpecifiedGroupBelongsToDefault() {
    Validator validator = TestUtil.getValidatorUnderTest();
    BeanDescriptor beanDescriptor = validator.getConstraintsForClass( User.class );
    assertTrue( beanDescriptor.isBeanConstrained() );

    PropertyDescriptor propDesc = beanDescriptor.getConstraintsForProperty( "firstname" );
    assertTrue( propDesc.getConstraintDescriptors().size() == 1 );

    ConstraintDescriptor<?> descriptor = propDesc.getConstraintDescriptors().iterator().next();
    assertTrue( descriptor.getGroups().size() == 1 );
    assertEquals(
        descriptor.getGroups().iterator().next(),
        Default.class,
        "Constraint should implicitly belong to the Default group."
View Full Code Here

  public void testConstraintCanBelongToMoreThanOneGroup() {
    Validator validator = TestUtil.getValidatorUnderTest();
    BeanDescriptor beanDescriptor = validator.getConstraintsForClass( User.class );
    assertTrue( beanDescriptor.isBeanConstrained() );

    PropertyDescriptor propDesc = beanDescriptor.getConstraintsForProperty( "defaultCreditCard" );
    assertTrue( propDesc.getConstraintDescriptors().size() == 1 );

    ConstraintDescriptor<?> descriptor = propDesc.getConstraintDescriptors().iterator().next();
    assertTrue( descriptor.getGroups().size() == 2 );
  }
View Full Code Here

      @SpecAssertion(section = "6.1", id = "a"),
      @SpecAssertion(section = "6.3", id = "b")
  })
  public void testGetConstraintsForConstrainedProperty() {
    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

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.