Package javax.validation.metadata

Examples of javax.validation.metadata.BeanDescriptor


        this.methodInfo = methodInfo;
        this.methodValidator = methodValidator;
    }

    public boolean accepts(ResourceMethod method) {
        BeanDescriptor bean = methodValidator.getConstraintsForClass(method.getResource().getType());
        MethodDescriptor descriptor = bean.getConstraintsForMethod(method.getMethod().getName(), method.getMethod().getParameterTypes());
        return descriptor != null && descriptor.hasConstrainedParameters();
    }
View Full Code Here


  @Test
  @SpecAssertion(section = "4.4.1", id = "b")
  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

  @Test
  @SpecAssertion(section = "4.4", id = "a")
  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(
View Full Code Here

  @Test
  @SpecAssertion(section = "4.4", id = "c")
  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

  @Test
  @SpecAssertion(section = "4.4.4", id = "a")
  public void testImplicitGrouping() {
    Validator validator = TestUtil.getValidatorUnderTest();
    BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Order.class );
    assertTrue( beanDescriptor.isBeanConstrained() );

    // validating the Default Group should validate all 5 constraints
    Order order = new Order();
    Set<ConstraintViolation<Order>> violations = validator.validate( order );
    assertTrue( violations.size() == 5, "All 5 NotNull constraints should fail." );
View Full Code Here

  }

  @Test
  @SpecAssertion(section = "6.2", id = "a")
  public void testGetElementClassReturnsBeanClass() {
    BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Customer.class );
    assertEquals( beanDescriptor.getElementClass(), Customer.class, "Wrong element class" );
  }
View Full Code Here

  @SpecAssertions({
      @SpecAssertion(section = "6.1", id = "a"),
      @SpecAssertion(section = "6.3", id = "a")
  })
  public void testIsBeanConstrainedDueToValidAnnotation() {
    BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Customer.class );

    // constraint via @Valid
    assertFalse(
        beanDescriptor.hasConstraints(),
        "There should be no direct constraints on the specified bean."
    );
    assertTrue(
        beanDescriptor.isBeanConstrained(),
        "Bean should be constrained due to @valid "
    );
  }
View Full Code Here

      @SpecAssertion(section = "6.1", id = "a"),
      @SpecAssertion(section = "6.3", id = "a")
  })
  public void testIsBeanConstrainedDueToConstraintOnEntity() {
    // constraint hosted on bean itself
    BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Account.class );
    assertTrue(
        beanDescriptor.hasConstraints(),
        "There should be direct constraints on the specified bean."
    );
    assertTrue(
        beanDescriptor.isBeanConstrained(),
        "Bean should be constrained due to @valid"
    );
  }
View Full Code Here

      @SpecAssertion(section = "6.1", id = "a"),
      @SpecAssertion(section = "6.3", id = "a")
  })
  public void testIsBeanConstrainedDueToConstraintProperty() {
    // constraint on bean property
    BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Order.class );
    assertFalse(
        beanDescriptor.hasConstraints(),
        "There should be no direct constraints on the specified bean."
    );
    assertTrue(
        beanDescriptor.isBeanConstrained(),
        "Bean should be constrained due to @NotNull"
    );
  }
View Full Code Here

      @SpecAssertion(section = "6.1", id = "a"),
      @SpecAssertion(section = "6.3", id = "a")
  })
  public void testIsBeanConstrainedDueToConstraintOnInterface() {
    // constraint on implemented interface
    BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Man.class );
    assertFalse(
        beanDescriptor.hasConstraints(),
        "There should be no direct constraints on the specified bean."
    );
    assertTrue(
        beanDescriptor.isBeanConstrained(),
        "Bean should be constrained due to constraints on Person."
    );
  }
View Full Code Here

TOP

Related Classes of javax.validation.metadata.BeanDescriptor

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.