Package javax.validation.metadata

Examples of javax.validation.metadata.ElementDescriptor


        Class targetClass = propertyDetails.getBaseObject().getClass();

        targetClass = ProxyUtils.getUnproxiedClass(targetClass);

        ElementDescriptor elementDescriptor = getDescriptorFor(targetClass, propertyDetails.getProperty());

        if (elementDescriptor == null)
        {
            return;
        }
View Full Code Here


  public void testGetElementClass() {
    Validator validator = getValidatorUnderTest();
    BeanDescriptor beanDescriptor = validator.getConstraintsForClass( SuperClass.class );
    assertEquals( beanDescriptor.getElementClass(), SuperClass.class, "Wrong element class" );

    ElementDescriptor elementDescriptor = beanDescriptor.getConstraintsForProperty( "myField" );
    assertEquals( elementDescriptor.getElementClass(), String.class, "Wrong element class" );
  }
View Full Code Here

  }

  @Test
  @SpecAssertion(section = "6.2", id = "b")
  public void testGetConstraintDescriptors() {
    ElementDescriptor descriptor = getPropertyDescriptor( SubClass.class, "myField" );
    assertEquals( descriptor.getConstraintDescriptors().size(), 2, "There should be two constraints on myField" );
  }
View Full Code Here

  }

  @Test
  @SpecAssertion(section = "6.2", id = "c")
  public void testHasConstraints() {
    ElementDescriptor descriptor = getPropertyDescriptor( SubClass.class, "myField" );
    assertTrue( descriptor.hasConstraints() );
  }
View Full Code Here

        parameterTypes
    );
  }

  public static Set<ConstraintDescriptor<?>> getConstraintDescriptorsFor(Class<?> clazz, String property) {
    ElementDescriptor elementDescriptor = getPropertyDescriptor( clazz, property );
    return elementDescriptor.getConstraintDescriptors();
  }
View Full Code Here

    message.append( Arrays.toString( args ) );
    message.append( "\nConstraint violations: " );

    int i = 1;
    for ( ConstraintViolation<?> constraintViolation : violations ) {
      ElementDescriptor elementDescriptor = locateElementDescriptor( constraintViolation );

      message.append( "\n (" );
      message.append( i );
      message.append( ")" );
      if ( elementDescriptor != null ) {
        message.append( " Kind: " );
        message.append( elementDescriptor.getKind() );
        if ( elementDescriptor instanceof ParameterDescriptor ) {
          message.append( "\n parameter index: " );
          message.append( ( (ParameterDescriptor) elementDescriptor ).getIndex() );
        }
      }
View Full Code Here

        property);
  }

  public static Set<ConstraintDescriptor<?>> getConstraintDescriptorsFor(
      Class<?> clazz, String property) {
    ElementDescriptor elementDescriptor = getPropertyDescriptor(clazz, property);
    return elementDescriptor.getConstraintDescriptors();
  }
View Full Code Here

    protected Validator createValidator() {
        return factory.getValidator();
    }

    public void testMetaDataAPI_ComposedConstraints() {
        ElementDescriptor ed =
              validator.getConstraintsForClass(FrenchAddress.class)
                    .getConstraintsForProperty("zipCode");
        Assert.assertEquals(1, ed.getConstraintDescriptors().size());
        for (ConstraintDescriptor<?> cd : ed.getConstraintDescriptors()) {
            Assert.assertTrue(cd.isReportAsSingleViolation());
            Assert.assertEquals(3, cd.getComposingConstraints().size());
            Assert.assertTrue("no composing constraints found!!",
                  !cd.getComposingConstraints().isEmpty());
            processConstraintDescriptor(cd); //check all constraints on zip code
View Full Code Here

        Assert.assertTrue(bc.getConstraintDescriptors() != null);
        TestUtils.failOnModifiable(bc.getConstraintDescriptors(), "beanDescriptor constraintDescriptors");
    }

    public void testMetadataAPI_Engine() {
        ElementDescriptor desc =
            validator.getConstraintsForClass(Engine.class).getConstraintsForProperty("serialNumber");
        assertNotNull(desc);
        // assertEquals(ElementType.FIELD, desc.getElementType());
        Assert.assertEquals(String.class, desc.getElementClass());
    }
View Full Code Here

        Assert.assertTrue(propNames.contains("country"));
        Assert.assertTrue(propNames.contains("city")); // annotated at method
        // level
        Assert.assertEquals(5, props.size());

        ElementDescriptor desc =
            validator.getConstraintsForClass(Address.class).getConstraintsForProperty("addressline1");
        Assert.assertNotNull(desc);
        boolean found = false;
        for (ConstraintDescriptor<?> each : desc.getConstraintDescriptors()) {
            if (each.getConstraintValidatorClasses().get(0).equals(SizeValidatorForString.class)) {
                Assert.assertTrue(each.getAttributes().containsKey("max"));
                assertEquals(30, each.getAttributes().get("max"));
                found = true;
            }
View Full Code Here

TOP

Related Classes of javax.validation.metadata.ElementDescriptor

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.