incubator-bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1166451 [5/6] - in /incubator/bval/trunk: ./ bval-core/ bval-core/src/main/java/org/apache/bval/ bval-core/src/main/java/org/apache/bval/model/ bval-core/src/main/java/org/apache/bval/util/ bval-json/src/main/resources/org/apache/bval/json...
Date Wed, 07 Sep 2011 22:32:28 GMT
Modified: incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/ConstraintDefinitionsTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/ConstraintDefinitionsTest.java?rev=1166451&r1=1166450&r2=1166451&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/ConstraintDefinitionsTest.java (original)
+++ incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/ConstraintDefinitionsTest.java Wed Sep  7 22:32:26 2011
@@ -18,23 +18,31 @@
  */
 package org.apache.bval.jsr303;
 
-import junit.framework.Assert;
-import junit.framework.TestCase;
-import org.apache.bval.constraints.NotNullValidator;
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
-import javax.validation.*;
-import javax.validation.constraints.Min;
-import javax.validation.metadata.BeanDescriptor;
-import javax.validation.metadata.ConstraintDescriptor;
 import java.lang.annotation.Documented;
 import java.lang.annotation.Retention;
 import java.lang.annotation.Target;
 import java.util.Locale;
 import java.util.Set;
 
-import static java.lang.annotation.ElementType.*;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import javax.validation.Constraint;
+import javax.validation.ConstraintDefinitionException;
+import javax.validation.Payload;
+import javax.validation.Validation;
+import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
+import javax.validation.constraints.Min;
+import javax.validation.metadata.BeanDescriptor;
+import javax.validation.metadata.ConstraintDescriptor;
 
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.bval.constraints.NotNullValidator;
 
 /**
  * Checks the correct parsing of constraint definitions.
@@ -42,7 +50,6 @@ import static java.lang.annotation.Reten
  * @author Carlos Vara
  */
 public class ConstraintDefinitionsTest extends TestCase {
-    
     static ValidatorFactory factory;
 
     static {
@@ -50,23 +57,42 @@ public class ConstraintDefinitionsTest e
         ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
     }
 
-    private Validator getValidator() {
+    /**
+     * Validator instance to test
+     */
+    protected Validator validator;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        validator = createValidator();
+    }
+
+    /**
+     * Create the validator instance.
+     * 
+     * @return Validator
+     */
+    protected Validator createValidator() {
         return factory.getValidator();
     }
-    
-    
+
     /**
      * Checks the correct parsing of a constraint with an array of constraints
      * as attributes.
      */
     public void testCustomAttributes() {
-        Validator validator = getValidator();
         BeanDescriptor constraints = validator.getConstraintsForClass(Person.class);
-        Set<ConstraintDescriptor<?>> ageConstraints = constraints.getConstraintsForProperty("age").getConstraintDescriptors();
-        
+        Set<ConstraintDescriptor<?>> ageConstraints =
+            constraints.getConstraintsForProperty("age").getConstraintDescriptors();
+
         Assert.assertEquals("There should be 2 constraints in 'age'", ageConstraints.size(), 2);
-        for ( ConstraintDescriptor<?> cd : ageConstraints ) {
-            Assert.assertEquals("Annotation should be @Min", cd.getAnnotation().annotationType().getName(), Min.class.getName());
+        for (ConstraintDescriptor<?> cd : ageConstraints) {
+            Assert.assertEquals("Annotation should be @Min", cd.getAnnotation().annotationType().getName(), Min.class
+                .getName());
         }
     }
 
@@ -76,7 +102,7 @@ public class ConstraintDefinitionsTest e
      */
     public void testNoGroupsConstraint() {
         try {
-            getValidator().validate(new NoGroups());
+            validator.validate(new NoGroups());
             fail("No exception thrown when parsing a constraint definition with no groups() method");
         } catch (ConstraintDefinitionException e) {
             // correct
@@ -90,7 +116,7 @@ public class ConstraintDefinitionsTest e
      */
     public void testInvalidDefaultGroupsConstraint() {
         try {
-            getValidator().validate(new InvalidGroups());
+            validator.validate(new InvalidGroups());
             fail("No exception thrown when parsing a constraint definition with a groups() method does not return Class[]");
         } catch (ConstraintDefinitionException e) {
             // correct
@@ -103,13 +129,13 @@ public class ConstraintDefinitionsTest e
      */
     public void testNoPayloadConstraint() {
         try {
-            getValidator().validate(new NoPayload());
+            validator.validate(new NoPayload());
             fail("No exception thrown when parsing a constraint definition with no payload() method");
         } catch (ConstraintDefinitionException e) {
             // correct
         }
     }
-    
+
     /**
      * Checks that a {@link ConstraintDefinitionException} is thrown when
      * parsing a constraint definition with an invalid <code>payload()</code>
@@ -117,7 +143,7 @@ public class ConstraintDefinitionsTest e
      */
     public void testInvalidDefaultPayloadConstraint() {
         try {
-            getValidator().validate(new InvalidPayload());
+            validator.validate(new InvalidPayload());
             fail("No exception thrown when parsing a constraint definition with a payload() method does not return an empty array");
         } catch (ConstraintDefinitionException e) {
             // correct
@@ -130,13 +156,13 @@ public class ConstraintDefinitionsTest e
      */
     public void testNoMessageConstraint() {
         try {
-            getValidator().validate(new NoMessage());
+            validator.validate(new NoMessage());
             fail("No exception thrown when parsing a constraint definition with no payload() method");
         } catch (ConstraintDefinitionException e) {
             // correct
         }
     }
-    
+
     /**
      * Checks that a {@link ConstraintDefinitionException} is thrown when
      * parsing a constraint definition with an invalid <code>message()</code>
@@ -144,7 +170,7 @@ public class ConstraintDefinitionsTest e
      */
     public void testInvalidDefaultMessageConstraint() {
         try {
-            getValidator().validate(new InvalidMessage());
+            validator.validate(new InvalidMessage());
             fail("No exception thrown when parsing a constraint definition with a message() method does not return a String");
         } catch (ConstraintDefinitionException e) {
             // correct
@@ -157,130 +183,140 @@ public class ConstraintDefinitionsTest e
      */
     public void testInvalidAttributeConstraint() {
         try {
-            getValidator().validate(new InvalidAttribute());
+            validator.validate(new InvalidAttribute());
             fail("No exception thrown when parsing a constraint definition with a method starting with 'valid'");
         } catch (ConstraintDefinitionException e) {
             // correct
         }
     }
-    
+
     public static class Person {
-        @MinList({
-            @Min(value=20),
-            @Min(value=30)
-        })
+        @MinList( { @Min(value = 20), @Min(value = 30) })
         public Integer age;
     }
-    
-    @Target({ METHOD, FIELD, ANNOTATION_TYPE })
+
+    @Target( { METHOD, FIELD, ANNOTATION_TYPE })
     @Retention(RUNTIME)
     @Documented
     public static @interface MinList {
         Min[] value();
     }
-    
+
     public static class NoGroups {
         @NoGroupsConstraint
         public String prop;
     }
-    
-    @Target({ METHOD, FIELD, ANNOTATION_TYPE })
+
+    @Target( { METHOD, FIELD, ANNOTATION_TYPE })
     @Retention(RUNTIME)
     @Documented
-    @Constraint(validatedBy = {NotNullValidator.class})
+    @Constraint(validatedBy = { NotNullValidator.class })
     public static @interface NoGroupsConstraint {
         String message() default "def msg";
+
         Class<? extends Payload>[] payload() default {};
     }
-    
+
     public static class InvalidGroups {
         @InvalidGroupsConstraint
         public String prop;
     }
-    
-    @Target({ METHOD, FIELD, ANNOTATION_TYPE })
+
+    @Target( { METHOD, FIELD, ANNOTATION_TYPE })
     @Retention(RUNTIME)
     @Documented
-    @Constraint(validatedBy = {NotNullValidator.class})
+    @Constraint(validatedBy = { NotNullValidator.class })
     public static @interface InvalidGroupsConstraint {
         String message() default "def msg";
+
         String[] groups() default { "Group1" };
+
         Class<? extends Payload>[] payload() default {};
     }
-    
+
     public static class NoPayload {
         @NoPayloadConstraint
         public String prop;
     }
-    
-    @Target({ METHOD, FIELD, ANNOTATION_TYPE })
+
+    @Target( { METHOD, FIELD, ANNOTATION_TYPE })
     @Retention(RUNTIME)
     @Documented
-    @Constraint(validatedBy = {NotNullValidator.class})
+    @Constraint(validatedBy = { NotNullValidator.class })
     public static @interface NoPayloadConstraint {
         String message() default "def msg";
+
         String[] groups() default {};
     }
-    
+
     public static class InvalidPayload {
         @InvalidPayloadConstraint
         public String prop;
     }
-    
-    @Target({ METHOD, FIELD, ANNOTATION_TYPE })
+
+    @Target( { METHOD, FIELD, ANNOTATION_TYPE })
     @Retention(RUNTIME)
     @Documented
-    @Constraint(validatedBy = {NotNullValidator.class})
+    @Constraint(validatedBy = { NotNullValidator.class })
     public static @interface InvalidPayloadConstraint {
         String message() default "def msg";
+
         String[] groups() default {};
-        Class<? extends Payload>[] payload() default {Payload1.class};
+
+        Class<? extends Payload>[] payload() default { Payload1.class };
+
         public static class Payload1 implements Payload {
         }
     }
-    
+
     public static class NoMessage {
         @NoMessageConstraint
         public String prop;
     }
-    
-    @Target({ METHOD, FIELD, ANNOTATION_TYPE })
+
+    @Target( { METHOD, FIELD, ANNOTATION_TYPE })
     @Retention(RUNTIME)
     @Documented
-    @Constraint(validatedBy = {NotNullValidator.class})
+    @Constraint(validatedBy = { NotNullValidator.class })
     public static @interface NoMessageConstraint {
         String[] groups() default {};
+
         Class<? extends Payload>[] payload() default {};
     }
-    
+
     public static class InvalidMessage {
-        @InvalidMessageConstraint(message=2)
+        @InvalidMessageConstraint(message = 2)
         public String prop;
     }
-    
-    @Target({ METHOD, FIELD, ANNOTATION_TYPE })
+
+    @Target( { METHOD, FIELD, ANNOTATION_TYPE })
     @Retention(RUNTIME)
     @Documented
-    @Constraint(validatedBy = {NotNullValidator.class})
+    @Constraint(validatedBy = { NotNullValidator.class })
     public static @interface InvalidMessageConstraint {
         int message();
+
         String[] groups() default {};
+
         Class<? extends Payload>[] payload() default {};
     }
-    
+
     public static class InvalidAttribute {
         @InvalidAttributeConstraint
         public String prop;
     }
-    
-    @Target({ METHOD, FIELD, ANNOTATION_TYPE })
+
+    @Target( { METHOD, FIELD, ANNOTATION_TYPE })
     @Retention(RUNTIME)
     @Documented
-    @Constraint(validatedBy = {NotNullValidator.class})
+    @Constraint(validatedBy = { NotNullValidator.class })
     public static @interface InvalidAttributeConstraint {
         String message() default "def msg";
+
         String[] groups() default {};
+
         Class<? extends Payload>[] payload() default {};
+
         String validValue() default "1";
     }
 }

Modified: incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/DefaultMessageInterpolatorTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/DefaultMessageInterpolatorTest.java?rev=1166451&r1=1166450&r2=1166451&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/DefaultMessageInterpolatorTest.java (original)
+++ incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/DefaultMessageInterpolatorTest.java Wed Sep  7 22:32:26 2011
@@ -62,7 +62,7 @@ public class DefaultMessageInterpolatorT
 
             public ConstraintDescriptor<?> getConstraintDescriptor() {
                 return (ConstraintDescriptor<?>) gvalidator.getConstraintsForClass(PreferredGuest.class)
-                    .getConstraintsForProperty("guestCreditCardNumber").getConstraintDescriptors().toArray()[0];
+                    .getConstraintsForProperty("guestCreditCardNumber").getConstraintDescriptors().iterator().next();
             }
 
             public Object getValidatedValue() {
@@ -74,8 +74,8 @@ public class DefaultMessageInterpolatorT
 
         ctx = new MessageInterpolator.Context() {
             public ConstraintDescriptor<?> getConstraintDescriptor() {
-                return (ConstraintDescriptor) gvalidator.getConstraintsForClass(Author.class)
-                    .getConstraintsForProperty("lastName").getConstraintDescriptors().toArray()[0];
+                return gvalidator.getConstraintsForClass(Author.class).getConstraintsForProperty("lastName")
+                    .getConstraintDescriptors().iterator().next();
             }
 
             public Object getValidatedValue() {
@@ -101,7 +101,7 @@ public class DefaultMessageInterpolatorT
 
             public ConstraintDescriptor<?> getConstraintDescriptor() {
                 return (ConstraintDescriptor<?>) validator.getConstraintsForClass(Person.class)
-                    .getConstraintsForProperty("idNumber").getConstraintDescriptors().toArray()[0];
+                    .getConstraintsForProperty("idNumber").getConstraintDescriptors().iterator().next();
             }
 
             public Object getValidatedValue() {
@@ -118,7 +118,7 @@ public class DefaultMessageInterpolatorT
 
             public ConstraintDescriptor<?> getConstraintDescriptor() {
                 return (ConstraintDescriptor<?>) validator.getConstraintsForClass(Person.class)
-                    .getConstraintsForProperty("otherId").getConstraintDescriptors().toArray()[0];
+                    .getConstraintsForProperty("otherId").getConstraintDescriptors().iterator().next();
             }
 
             public Object getValidatedValue() {

Modified: incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/ExceptionsContractTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/ExceptionsContractTest.java?rev=1166451&r1=1166450&r2=1166451&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/ExceptionsContractTest.java (original)
+++ incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/ExceptionsContractTest.java Wed Sep  7 22:32:26 2011
@@ -25,6 +25,7 @@ import javax.validation.Validation;
 import javax.validation.ValidationException;
 import javax.validation.Validator;
 import javax.validation.ValidatorFactory;
+import javax.validation.constraints.Min;
 import javax.validation.constraints.NotNull;
 import javax.validation.metadata.BeanDescriptor;
 import java.util.Locale;
@@ -36,7 +37,6 @@ import java.util.Locale;
  * @author Carlos Vara
  */
 public class ExceptionsContractTest extends TestCase {
-
     static ValidatorFactory factory;
 
     static {
@@ -44,7 +44,26 @@ public class ExceptionsContractTest exte
         ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
     }
 
-    private Validator getValidator() {
+    /**
+     * Validator instance to test
+     */
+    protected Validator validator;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        validator = createValidator();
+    }
+
+    /**
+     * Create the validator instance.
+     * 
+     * @return Validator
+     */
+    protected Validator createValidator() {
         return factory.getValidator();
     }
 
@@ -53,7 +72,6 @@ public class ExceptionsContractTest exte
      * getter throws an exception.
      */
     public void testExceptionThrowingBean() {
-        Validator validator = getValidator();
         try {
             validator.validate(new ExceptionThrowingBean());
             Assert.fail("No exception thrown when validating a bean whose getter throws a RTE");
@@ -67,7 +85,6 @@ public class ExceptionsContractTest exte
      * <code>null</code> as group array.
      */
     public void testValidateNullGroup() {
-        Validator validator = getValidator();
         try {
             Class<?>[] groups = null;
             validator.validate(new String(), groups);
@@ -82,7 +99,6 @@ public class ExceptionsContractTest exte
      * invalid property name.
      */
     public void testValidateInvalidPropertyName() {
-        Validator validator = getValidator();
 
         // Null propertyName
         try {
@@ -112,7 +128,6 @@ public class ExceptionsContractTest exte
      * validate a property on a null object.
      */
     public void testValidatePropertyOnNullBean() {
-        Validator validator = getValidator();
         try {
             validator.validateProperty(null, "class");
         } catch (IllegalArgumentException e) {
@@ -126,7 +141,6 @@ public class ExceptionsContractTest exte
      * {@link Validator#validateProperty(Object, String, Class...)} call.
      */
     public void testValidatePropertyNullGroup() {
-        Validator validator = getValidator();
         try {
             Class<?>[] groups = null;
             validator.validateProperty(new Person(), "name", groups);
@@ -142,7 +156,6 @@ public class ExceptionsContractTest exte
      * <code>null</code> class.
      */
     public void testValidateValueOnNullClass() {
-        Validator validator = getValidator();
         try {
             validator.validateValue(null, "class", Object.class);
             Assert.fail("No exception thrown when passing null as group array");
@@ -157,8 +170,6 @@ public class ExceptionsContractTest exte
      * {@link Validator#validateValue(Class, String, Object, Class...)}.
      */
     public void testValidateValueInvalidPropertyName() {
-        Validator validator = getValidator();
-
         // Null propertyName
         try {
             validator.validateValue(Person.class, null, "John");
@@ -187,7 +198,6 @@ public class ExceptionsContractTest exte
      * <code>null</code> group array.
      */
     public void testValidateValueNullGroup() {
-        Validator validator = getValidator();
         try {
             Class<?>[] groups = null;
             validator.validateValue(Person.class, "name", "John", groups);
@@ -198,21 +208,39 @@ public class ExceptionsContractTest exte
     }
 
     /**
+     * Enforces the "not a valid object property" part of the {@link IllegalArgumentException}
+     * declaration on {@link Validator#validateValue(Class, String, Object, Class...)}
+     */
+    public void testValidateIncompatibleValue() {
+        try {
+            validator.validateValue(Person.class, "name", 666);
+            Assert.fail("No exception thrown when passing Integer for string value");
+        } catch (IllegalArgumentException e) {
+            // Correct
+        }
+        try {
+            validator.validateValue(Person.class, "age", null);
+            Assert.fail("No exception thrown when passing null for primitive value");
+        } catch (IllegalArgumentException e) {
+            // Correct
+        }
+    }
+
+    /**
      * Checks that an {@link IllegalArgumentException} is thrown when calling
      * {@link BeanDescriptor#getConstraintsForProperty(String)} with an invalid
      * property name.
      */
     public void testGetConstraintsForInvalidProperty() {
-        Validator validator = getValidator();
         BeanDescriptor personDescriptor = validator.getConstraintsForClass(Person.class);
-        
+
         try {
             personDescriptor.getConstraintsForProperty(null);
             fail("No exception thrown when calling getConstraintsForProperty with null property");
         } catch (IllegalArgumentException e) {
             // Correct
         }
-        
+
         try {
             personDescriptor.getConstraintsForProperty("");
             fail("No exception thrown when calling getConstraintsForProperty with empty property");
@@ -220,7 +248,6 @@ public class ExceptionsContractTest exte
             // Correct
         }
     }
-    
 
     public static class ExceptionThrowingBean {
 
@@ -232,10 +259,12 @@ public class ExceptionsContractTest exte
     }
 
     public static class Person {
-        
+
         @NotNull
         public String name;
-        
+
+        @Min(0)
+        public int age;
     }
 
 }

Modified: incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/FooTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/FooTest.java?rev=1166451&r1=1166450&r2=1166451&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/FooTest.java (original)
+++ incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/FooTest.java Wed Sep  7 22:32:26 2011
@@ -59,7 +59,7 @@ public class FooTest extends TestCase {
         Validator v = ApacheValidatorFactory.getDefault().getValidator();
         Set<ConstraintViolation<FooTest>> errors = v.validate(t);
         System.out.println("got errors:");
-        for (ConstraintViolation error : errors) {
+        for (ConstraintViolation<?> error : errors) {
             System.out.println(error.getPropertyPath());
         }
     }

Modified: incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/Jsr303Test.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/Jsr303Test.java?rev=1166451&r1=1166450&r2=1166451&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/Jsr303Test.java (original)
+++ incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/Jsr303Test.java Wed Sep  7 22:32:26 2011
@@ -18,106 +18,155 @@
  */
 package org.apache.bval.jsr303;
 
-import junit.framework.Assert;
-import junit.framework.TestCase;
-import org.apache.bval.constraints.SizeValidatorForString;
-import org.apache.bval.jsr303.example.*;
-import org.apache.bval.jsr303.util.TestUtils;
+import java.math.BigDecimal;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Locale;
+import java.util.Set;
 
 import javax.validation.ConstraintViolation;
 import javax.validation.UnexpectedTypeException;
+import javax.validation.Validation;
 import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
 import javax.validation.metadata.BeanDescriptor;
 import javax.validation.metadata.ConstraintDescriptor;
 import javax.validation.metadata.ElementDescriptor;
 import javax.validation.metadata.PropertyDescriptor;
-import java.math.BigDecimal;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Set;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.bval.constraints.SizeValidatorForString;
+import org.apache.bval.jsr303.example.Address;
+import org.apache.bval.jsr303.example.Book;
+import org.apache.bval.jsr303.example.Engine;
+import org.apache.bval.jsr303.example.IllustratedBook;
+import org.apache.bval.jsr303.example.MaxTestEntity;
+import org.apache.bval.jsr303.example.NoValidatorTestEntity;
+import org.apache.bval.jsr303.example.Second;
+import org.apache.bval.jsr303.example.SizeTestEntity;
+import org.apache.bval.jsr303.util.TestUtils;
 
 /**
  * Description: <br/>
  */
 public class Jsr303Test extends TestCase {
-/*    static {
-        ApacheValidatorFactory.getDefault().getMetaBeanManager()
-                .addResourceLoader("org/apache/bval/example/test-beanInfos.xml");
-    }*/
-
-    /*  public void testUseCoreXmlMetaData() {
-        Validator validator = getValidator();
-
-        BusinessObject object = new BusinessObject();
-        object.setTitle("1234567834567 too long title ");
-        Set<ConstraintViolation<BusinessObject>> violations = validator.validate(object);
-        Assert.assertNotNull(violations);
-        Assert.assertTrue(!violations.isEmpty());
+    /*
+     * static { ApacheValidatorFactory.getDefault().getMetaBeanManager()
+     * .addResourceLoader("org/apache/bval/example/test-beanInfos.xml"); }
+     */
+
+    /*
+     * public void testUseCoreXmlMetaData() { Validator validator =
+     * getValidator();
+     * 
+     * BusinessObject object = new BusinessObject();
+     * object.setTitle("1234567834567 too long title ");
+     * Set<ConstraintViolation<BusinessObject>> violations =
+     * validator.validate(object); Assert.assertNotNull(violations);
+     * Assert.assertTrue(!violations.isEmpty());
+     * 
+     * Assert.assertTrue(!validator.validateProperty(object,
+     * "title").isEmpty()); }
+     */
 
-        Assert.assertTrue(!validator.validateProperty(object, "title").isEmpty());
-    }*/
+    static ValidatorFactory factory;
+
+    static {
+        factory = Validation.buildDefaultValidatorFactory();
+        ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
+    }
+
+    /**
+     * Validator instance to test
+     */
+    protected Validator validator;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        validator = createValidator();
+    }
+
+    /**
+     * Create the validator instance.
+     * 
+     * @return Validator
+     */
+    protected Validator createValidator() {
+        return factory.getValidator();
+    }
 
     public void testPropertyDescriptorHasConstraints() {
-        BeanDescriptor cons = getValidator().getConstraintsForClass(Book.class);
+        BeanDescriptor cons = validator.getConstraintsForClass(Book.class);
         assertTrue(cons.getConstraintsForProperty("author").hasConstraints());
         assertTrue(cons.getConstraintsForProperty("title").hasConstraints());
         assertTrue(cons.getConstraintsForProperty("uselessField").hasConstraints());
-        // cons.getConstraintsForProperty("unconstraintField") == null without Introspector
-        // cons.getConstraintsForProperty("unconstraintField") != null with Introspector
-        assertTrue(cons.getConstraintsForProperty("unconstraintField") == null ||
-              !cons.getConstraintsForProperty("unconstraintField").hasConstraints());
+        // cons.getConstraintsForProperty("unconstraintField") == null without
+        // Introspector
+        // cons.getConstraintsForProperty("unconstraintField") != null with
+        // Introspector
+        assertTrue(cons.getConstraintsForProperty("unconstraintField") == null
+            || !cons.getConstraintsForProperty("unconstraintField").hasConstraints());
         assertNull(cons.getConstraintsForProperty("unknownField"));
     }
 
     public void testValidateValue() {
-        Validator validator = getValidator();
-        assertTrue(
-              validator.validateValue(Book.class, "subtitle", "123456789098765432").isEmpty());
+        assertTrue(validator.validateValue(Book.class, "subtitle", "123456789098765432").isEmpty());
         assertFalse(validator.validateValue(Book.class, "subtitle",
-              "123456789098765432123412345678909876543212341234564567890987654321234",
-              Second.class).isEmpty());
-        // tests for issue 22: validation of a field without any constraints 
+            "123456789098765432123412345678909876543212341234564567890987654321234", Second.class).isEmpty());
+        // tests for issue 22: validation of a field without any constraints
         assertEquals(0, validator.validateValue(Book.class, "unconstraintField", 4).size());
-        // tests for issue 22: validation of unknown field cause ValidationException
+        // tests for issue 22: validation of unknown field cause
+        // ValidationException
         try {
             validator.validateValue(Book.class, "unknownProperty", 4);
             fail("unknownProperty not detected");
         } catch (IllegalArgumentException ex) {
             // OK
-            assertEquals(
-                  "unknown property 'unknownProperty' in org.apache.bval.jsr303.example.Book",
-                  ex.getMessage());
+            assertEquals("unknown property 'unknownProperty' in org.apache.bval.jsr303.example.Book", ex.getMessage());
+        }
+    }
+
+    public void testValidateNonCascadedRealNestedProperty() {
+        try {
+            validator.validateValue(IllustratedBook.class, "illustrator.firstName", "Edgar");
+            fail("unknownProperty not detected");
+        } catch (IllegalArgumentException ex) {
+            // OK
+            assertEquals("Property org.apache.bval.jsr303.example.IllustratedBook.illustrator is not cascaded", ex.getMessage());
         }
     }
 
     public void testMetadataAPI_Book() {
-        Validator validator = getValidator();
         Assert.assertNotNull(validator.getConstraintsForClass(Book.class));
-        Assert.assertTrue(validator.getConstraintsForClass(Book.class) ==
-              validator.getConstraintsForClass(Book.class));
+        // not necessary for implementation correctness, but we'll test
+        // nevertheless:
+        Assert.assertSame(validator.getConstraintsForClass(Book.class), validator.getConstraintsForClass(Book.class));
         BeanDescriptor bc = validator.getConstraintsForClass(Book.class);
-//        assertEquals(ElementType.TYPE, bc.getElementType());
+        // assertEquals(ElementType.TYPE, bc.getElementType());
         Assert.assertEquals(Book.class, bc.getElementClass());
-//        assertEquals(false, bc.isCascaded());
-//        assertEquals("", bc.getPropertyPath());
+        // assertEquals(false, bc.isCascaded());
+        // assertEquals("", bc.getPropertyPath());
         Assert.assertTrue(bc.getConstraintDescriptors() != null);
         TestUtils.failOnModifiable(bc.getConstraintDescriptors(), "beanDescriptor constraintDescriptors");
     }
 
     public void testMetadataAPI_Engine() {
-        Validator validator = getValidator();
-        ElementDescriptor desc = validator.getConstraintsForClass(Engine.class)
-              .getConstraintsForProperty("serialNumber");
+        ElementDescriptor desc =
+            validator.getConstraintsForClass(Engine.class).getConstraintsForProperty("serialNumber");
         assertNotNull(desc);
-//        assertEquals(ElementType.FIELD, desc.getElementType());
+        // assertEquals(ElementType.FIELD, desc.getElementType());
         Assert.assertEquals(String.class, desc.getElementClass());
     }
 
     public void testMetadataAPI_Address() {
-        Validator validator = getValidator();
-        Assert.assertFalse(validator.getConstraintsForClass(Address.class)
-              .getConstraintDescriptors().isEmpty());
+        Assert.assertFalse(validator.getConstraintsForClass(Address.class).getConstraintDescriptors().isEmpty());
 
         Set<PropertyDescriptor> props = validator.getConstraintsForClass(Address.class).getConstrainedProperties();
         TestUtils.failOnModifiable(props, "beanDescriptor constrainedProperties");
@@ -126,20 +175,21 @@ public class Jsr303Test extends TestCase
             TestUtils.failOnModifiable(each.getConstraintDescriptors(), "propertyDescriptor constraintDescriptors");
             propNames.add(each.getPropertyName());
         }
-        Assert.assertTrue(propNames.contains("addressline1")); // annotated at field level
+        Assert.assertTrue(propNames.contains("addressline1")); // annotated at
+        // field level
         Assert.assertTrue(propNames.contains("addressline2"));
         Assert.assertTrue(propNames.contains("zipCode"));
         Assert.assertTrue(propNames.contains("country"));
-        Assert.assertTrue(propNames.contains("city"));       // annotated at method level
+        Assert.assertTrue(propNames.contains("city")); // annotated at method
+        // level
         Assert.assertEquals(5, props.size());
 
-        ElementDescriptor desc = validator.getConstraintsForClass(Address.class)
-              .getConstraintsForProperty("addressline1");
+        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)) {
+        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;
@@ -150,7 +200,6 @@ public class Jsr303Test extends TestCase
     }
 
     public void testValidateMultiValuedConstraints() {
-        Validator validator = getValidator();
         Engine engine = new Engine();
         engine.serialNumber = "abcd-defg-0123";
         Set<ConstraintViolation<Engine>> violations;
@@ -160,8 +209,7 @@ public class Jsr303Test extends TestCase
         engine.serialNumber = "!)/(/()";
         violations = validator.validate(engine);
         assertEquals(2, violations.size());
-        for (String msg : new String[]{"must contain alphabetical characters only",
-              "must match ....-....-...."}) {
+        for (String msg : new String[] { "must contain alphabetical characters only", "must match ....-....-...." }) {
             assertNotNull(TestUtils.getViolationWithMessage(violations, msg));
         }
     }
@@ -172,7 +220,6 @@ public class Jsr303Test extends TestCase
         entity.setProperty("201");
         entity.setLongValue(301);
         entity.setDecimalValue(new BigDecimal(401));
-        Validator validator = getValidator();
         Set<ConstraintViolation<MaxTestEntity>> violations = validator.validate(entity);
         assertEquals(4, violations.size());
 
@@ -182,10 +229,9 @@ public class Jsr303Test extends TestCase
             fail("UnexpectedTypeException expected but not thrown");
         } catch (UnexpectedTypeException ex) {
             // we expected this
-            assertEquals("No validator could be found for type java.lang.Object. " +
-                  "See: @Max at private java.lang.Object " +
-                  "org.apache.bval.jsr303.example." + "NoValidatorTestEntity.anything",
-                  ex.getMessage());
+            assertEquals("No validator could be found for type java.lang.Object. "
+                + "See: @Max at private java.lang.Object " + "org.apache.bval.jsr303.example."
+                + "NoValidatorTestEntity.anything", ex.getMessage());
         }
     }
 
@@ -199,7 +245,7 @@ public class Jsr303Test extends TestCase
         en.fa = new float[3];
         en.it = new int[3];
         en.la = new long[3];
-        en.map = new HashMap();
+        en.map = new HashMap<String, String>();
         en.map.put("1", "1");
         en.map.put("3", "3");
         en.map.put("2", "2");
@@ -207,15 +253,14 @@ public class Jsr303Test extends TestCase
         en.oa2 = new Integer[3];
         en.sa = new short[3];
         en.text = "123";
-        Set<ConstraintViolation<SizeTestEntity>> vi = getValidator().validate(en);
+        Set<ConstraintViolation<SizeTestEntity>> vi = validator.validate(en);
         assertEquals(13, vi.size());
     }
-    
+
     /**
      * JSR-303 Section 5.1.c, IllegalArgumentException should be thrown
      */
     public void testGetConstraintsForNullClass() {
-        Validator validator = getValidator();
         try {
             validator.getConstraintsForClass(null);
             Assert.fail("No exception thrown on Validator.getConstraintsForClass(null)");
@@ -225,8 +270,4 @@ public class Jsr303Test extends TestCase
         }
     }
 
-    private Validator getValidator() {
-//        return Validation.buildDefaultValidatorFactory().getValidator();
-        return ApacheValidatorFactory.getDefault().getValidator();
-    }
 }

Modified: incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/PayloadTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/PayloadTest.java?rev=1166451&r1=1166450&r2=1166451&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/PayloadTest.java (original)
+++ incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/PayloadTest.java Wed Sep  7 22:32:26 2011
@@ -18,14 +18,19 @@
  */
 package org.apache.bval.jsr303;
 
-import junit.framework.TestCase;
-import org.apache.bval.jsr303.util.TestUtils;
+import java.util.Locale;
+import java.util.Set;
 
 import javax.validation.ConstraintViolation;
 import javax.validation.Payload;
+import javax.validation.Validation;
 import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
 import javax.validation.constraints.NotNull;
-import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.bval.jsr303.util.TestUtils;
 
 /**
  * Description: test that payload information can be retrieved
@@ -33,10 +38,34 @@ import java.util.Set;
  * through the ConstraintViolation objects<br/>
  */
 public class PayloadTest extends TestCase {
-    private Validator validator;
+    static ValidatorFactory factory;
+
+    static {
+        factory = Validation.buildDefaultValidatorFactory();
+        ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
+    }
+
+    /**
+     * Validator instance to test
+     */
+    protected Validator validator;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        validator = createValidator();
+    }
 
-    protected void setUp() {
-        validator = ApacheValidatorFactory.getDefault().getValidator();
+    /**
+     * Create the validator instance.
+     * 
+     * @return Validator
+     */
+    protected Validator createValidator() {
+        return factory.getValidator();
     }
 
     static class Severity {
@@ -72,7 +101,7 @@ public class PayloadTest extends TestCas
         Address address = new Address(null, null);
         violations = validator.validate(address);
         assertEquals(2, violations.size());
-        ConstraintViolation vio;
+        ConstraintViolation<?> vio;
         vio = TestUtils.getViolation(violations, "zipCode");
         assertNotNull(vio);
         assertEquals(1, vio.getConstraintDescriptor().getPayload().size());

Modified: incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/TckReproducerTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/TckReproducerTest.java?rev=1166451&r1=1166450&r2=1166451&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/TckReproducerTest.java (original)
+++ incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/TckReproducerTest.java Wed Sep  7 22:32:26 2011
@@ -23,8 +23,12 @@ import junit.framework.TestCase;
 import org.apache.bval.util.PropertyAccess;
 
 import javax.validation.ConstraintViolation;
+import javax.validation.Validation;
 import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
 import javax.validation.constraints.Pattern;
+
+import java.util.Locale;
 import java.util.Set;
 
 /**
@@ -34,6 +38,35 @@ import java.util.Set;
  * Time: 14:21:45<br>
  */
 public class TckReproducerTest extends TestCase {
+    static ValidatorFactory factory;
+
+    static {
+        factory = Validation.buildDefaultValidatorFactory();
+        ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
+    }
+
+    /**
+     * Validator instance to test
+     */
+    protected Validator validator;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        validator = createValidator();
+    }
+
+    /**
+     * Create the validator instance.
+     * 
+     * @return Validator
+     */
+    protected Validator createValidator() {
+        return factory.getValidator();
+    }
 
     public static <T> void assertCorrectNumberOfViolations(Set<ConstraintViolation<T>> violations,
         int expectedViolations) {
@@ -41,12 +74,7 @@ public class TckReproducerTest extends T
             + violations.size(), expectedViolations, violations.size());
     }
 
-    private Validator getValidator() {
-        return ApacheValidatorFactory.getDefault().getValidator();
-    }
-
     public void testPropertyAccessOnNonPublicClass() throws Exception {
-        Validator validator = getValidator();
         Car car = new Car("USd-298");
         assertEquals(car.getLicensePlateNumber(), PropertyAccess.getProperty(car, "licensePlateNumber"));
 

Modified: incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/ValidationTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/ValidationTest.java?rev=1166451&r1=1166450&r2=1166451&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/ValidationTest.java (original)
+++ incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/ValidationTest.java Wed Sep  7 22:32:26 2011
@@ -18,11 +18,16 @@
  */
 package org.apache.bval.jsr303;
 
-import junit.framework.Assert;
-import junit.framework.TestCase;
-import org.apache.bval.constraints.NotNullValidator;
-import org.apache.bval.jsr303.example.*;
-import org.apache.bval.jsr303.util.TestUtils;
+import java.lang.reflect.Array;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
 
 import javax.validation.ConstraintViolation;
 import javax.validation.Validation;
@@ -34,11 +39,23 @@ import javax.validation.groups.Default;
 import javax.validation.metadata.BeanDescriptor;
 import javax.validation.metadata.ConstraintDescriptor;
 import javax.validation.metadata.PropertyDescriptor;
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.Set;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.bval.constraints.NotNullValidator;
+import org.apache.bval.jsr303.example.AccessTestBusinessObject;
+import org.apache.bval.jsr303.example.AccessTestBusinessObjectSub;
+import org.apache.bval.jsr303.example.Address;
+import org.apache.bval.jsr303.example.Author;
+import org.apache.bval.jsr303.example.Book;
+import org.apache.bval.jsr303.example.BusinessAddress;
+import org.apache.bval.jsr303.example.Continent;
+import org.apache.bval.jsr303.example.Country;
+import org.apache.bval.jsr303.example.First;
+import org.apache.bval.jsr303.example.Last;
+import org.apache.bval.jsr303.example.RecursiveFoo;
+import org.apache.bval.jsr303.util.TestUtils;
 
 /**
  * Description: <br/>
@@ -48,29 +65,46 @@ public class ValidationTest extends Test
 
     static {
         factory = Validation.buildDefaultValidatorFactory();
-        ((DefaultMessageInterpolator)factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
+        ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
+    }
+
+    /**
+     * Validator instance to test
+     */
+    protected Validator validator;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        validator = createValidator();
     }
 
-    private Validator getValidator() {
+    /**
+     * Create the validator instance.
+     * 
+     * @return Validator
+     */
+    protected Validator createValidator() {
         return factory.getValidator();
     }
 
     public void testAccessStrategies_field_method() {
         AccessTestBusinessObject o1 = new AccessTestBusinessObject("1");
         AccessTestBusinessObjectSub o2 = new AccessTestBusinessObjectSub("3");
-        Validator validator = getValidator();
-        Set<ConstraintViolation<AccessTestBusinessObject>> errors =
-              validator.validate(o1);
+        Set<ConstraintViolation<AccessTestBusinessObject>> errors = validator.validate(o1);
         assertTrue(errors.isEmpty());
-        Set<ConstraintViolation<AccessTestBusinessObjectSub>> errors2 =
-              validator.validate(o2);
+        Set<ConstraintViolation<AccessTestBusinessObjectSub>> errors2 = validator.validate(o2);
         assertTrue(errors2.isEmpty());
 
         o2 = new AccessTestBusinessObjectSub("1");
         errors2 = validator.validate(o2);
         assertEquals(1, errors2.size());
 
-        // assert, that getvar2() and getVar2() are both validated with their getter method
+        // assert, that getvar2() and getVar2() are both validated with their
+        // getter method
         o2 = new AccessTestBusinessObjectSub("3");
         o2.setVar2("1");
         o2.setvar2("2");
@@ -92,17 +126,17 @@ public class ValidationTest extends Test
         AccessTestBusinessObject o1 = new AccessTestBusinessObject("1");
         AccessTestBusinessObject o2 = new AccessTestBusinessObject("2");
         o1.next(o2);
-        Validator validator = getValidator();
-        Set<ConstraintViolation<AccessTestBusinessObject>> errors =
-              validator.validate(o1);
-        // assert, that field access 'next' is used and not getNext() is called!!!
+        Set<ConstraintViolation<AccessTestBusinessObject>> errors = validator.validate(o1);
+        // assert, that field access 'next' is used and not getNext() is
+        // called!!!
         assertEquals(1, errors.size());
         o2 = new AccessTestBusinessObject("1");
         o1.next(o2);
         errors = validator.validate(o1);
         assertEquals(0, errors.size());
 
-        // assert that toBeIgnored not validated, because not annotated with @Valid
+        // assert that toBeIgnored not validated, because not annotated with
+        // @Valid
         o1.setToBeIgnored(new AccessTestBusinessObject("99"));
         errors = validator.validate(o1);
         assertEquals(0, errors.size());
@@ -113,7 +147,6 @@ public class ValidationTest extends Test
     }
 
     public void testBook() {
-        Validator validator = getValidator();
         Author author = new Author();
         author.setLastName("Baudelaire");
         author.setFirstName("");
@@ -129,18 +162,16 @@ public class ValidationTest extends Test
         author.setCompany("Some random publisher with a very very very long name");
 
         // author.firstName fails to pass the NotEmpty constraint
-        //  author.company fails to pass the Size constraint
+        // author.company fails to pass the Size constraint
     }
 
     /**
-     * test:
-     * - dynamic resolution of associated object types.
-     * - inheritance of validation constraints
-     * - complex valiation, different groups, nested object net
+     * test: - dynamic resolution of associated object types. - inheritance of validation constraints - complex
+     * valiation, different groups, nested object net
      */
     public void testValidAnnotation() {
         Author a = new Author();
-        a.setAddresses(new ArrayList());
+        a.setAddresses(new ArrayList<Address>());
         BusinessAddress adr = new BusinessAddress();
         adr.setCountry(new Country());
         adr.setAddressline1("line1");
@@ -152,23 +183,22 @@ public class ValidationTest extends Test
         a.setFirstName("Karl");
         a.setLastName("May");
 
-        Validator v = getValidator();
-        Set found = v.validate(a, Default.class, First.class, Last.class);
+        Set<ConstraintViolation<Author>> found = validator.validate(a, Default.class, First.class, Last.class);
         Assert.assertTrue(!found.isEmpty());
         Assert.assertEquals(4, found.size());
 
         adr.setCity("Berlin");
         adr.setZipCode("12345");
         adr.setCompany("apache");
-        found = v.validate(a, Default.class, First.class, Last.class);
+        found = validator.validate(a, Default.class, First.class, Last.class);
         Assert.assertEquals(1, found.size());
-        ConstraintViolation ic = (ConstraintViolation) found.iterator().next();
+        ConstraintViolation<Author> ic = found.iterator().next();
         Assert.assertEquals("addresses[0].country.name", ic.getPropertyPath().toString());
     }
 
     public void testPropertyPathWithIndex() {
         Author a = new Author();
-        a.setAddresses(new ArrayList());
+        a.setAddresses(new ArrayList<Address>());
         Address adr = new Address();
         adr.setAddressline1("adr1");
         adr.setCity("Santiago");
@@ -182,14 +212,14 @@ public class ValidationTest extends Test
         adr.setCity("Trinidad");
         a.getAddresses().add(adr);
 
-        Set<ConstraintViolation<Author>> constraints = getValidator().validate(a);
+        Set<ConstraintViolation<Author>> constraints = validator.validate(a);
         Assert.assertTrue(!constraints.isEmpty());
 
         assertPropertyPath("addresses[0].country", constraints);
         assertPropertyPath("addresses[1].country", constraints);
         assertPropertyPath("addresses[2].country", constraints);
     }
-    
+
     /**
      * Check correct path reporting when validating a set of beans.
      */
@@ -201,73 +231,68 @@ public class ValidationTest extends Test
         country.setISO3Code("xxx");
         country.setName(null);
         c.countries.add(country);
-        
-        Set<ConstraintViolation<Continent>> constraints = getValidator().validate(c);
+
+        Set<ConstraintViolation<Continent>> constraints = validator.validate(c);
         Assert.assertEquals("Incorrect number of violations detected", 1, constraints.size());
         assertPropertyPath("countries[].name", constraints);
-        
+
     }
 
-    private <T> void assertPropertyPath(String propertyPath,
-                                        Set<ConstraintViolation<T>> constraints) {
-        for (ConstraintViolation each : constraints) {
-            if (each.getPropertyPath().toString().equals(propertyPath)) return;
+    private <T> void assertPropertyPath(String propertyPath, Set<ConstraintViolation<T>> constraints) {
+        for (ConstraintViolation<T> each : constraints) {
+            if (each.getPropertyPath().toString().equals(propertyPath))
+                return;
         }
         Assert.fail(propertyPath + " not found in " + constraints);
     }
 
     public void testPropertyPathRecursive() {
-        RecursiveFoo foo1 = new RecursiveFoo();
+        RecursiveFoo foo1 = new RecursiveFoo(); // root
         RecursiveFoo foo11 = new RecursiveFoo();
-        foo1.getFoos().add(foo11);
+        foo1.getFoos().add(foo11); // foos[0]
         RecursiveFoo foo12 = new RecursiveFoo();
-        foo1.getFoos().add(foo12);
+        foo1.getFoos().add(foo12); // foos[1]
         RecursiveFoo foo2 = new RecursiveFoo();
-        foo11.getFoos().add(foo2);
+        foo11.getFoos().add(foo2); // foos[0].foos[0]
 
-        Set<ConstraintViolation<RecursiveFoo>> constraints =
-              getValidator().validate(foo1);
+        Set<ConstraintViolation<RecursiveFoo>> constraints = validator.validate(foo1);
         assertPropertyPath("foos[0].foos[0].foos", constraints);
         assertPropertyPath("foos[1].foos", constraints);
     }
 
     public void testNullElementInCollection() {
         try {
-            getValidator().validate(null);
+            validator.validate(null);
             Assert.fail();
         } catch (IllegalArgumentException ex) {
         }
         RecursiveFoo foo = new RecursiveFoo();
         foo.getFoos().add(new RecursiveFoo());
         foo.getFoos().add(null);
-        Assert.assertTrue(!getValidator().validate(foo).isEmpty());
+        Assert.assertTrue(!validator.validate(foo).isEmpty());
         // check that no nullpointer exception gets thrown
     }
 
     public void testGroups() {
-        Validator validator = getValidator();
         Author author = new Author();
         author.setCompany("ACME");
         Book book = new Book();
         book.setTitle("");
         book.setAuthor(author);
         boolean foundTitleConstraint = false;
-        Set<ConstraintViolation<Book>> constraintViolations =
-              validator.validate(book, Book.All.class);
+        Set<ConstraintViolation<Book>> constraintViolations = validator.validate(book, Book.All.class);
         assertEquals(1, constraintViolations.size());
-        //assuming an english locale, the interpolated message is returned
-        for (ConstraintViolation constraintViolation : constraintViolations) {
+        // assuming an english locale, the interpolated message is returned
+        for (ConstraintViolation<Book> constraintViolation : constraintViolations) {
             if (constraintViolation.getRootBean().getClass() == Book.class) {
-                Assert.assertEquals(
-                      "may not be empty", constraintViolation.getMessage());
+                Assert.assertEquals("may not be empty", constraintViolation.getMessage());
                 Assert.assertTrue(book == constraintViolation.getRootBean());
 
-                //the offending property
+                // the offending property
                 if (constraintViolation.getPropertyPath().toString().equals("title")) {
                     foundTitleConstraint = true;
-                    //the offending value
-                    Assert.assertEquals(book.getTitle(),
-                          constraintViolation.getInvalidValue());
+                    // the offending value
+                    Assert.assertEquals(book.getTitle(), constraintViolation.getInvalidValue());
                 }
             }
         }
@@ -275,10 +300,9 @@ public class ValidationTest extends Test
     }
 
     /**
-     * Example 2.14. Using the fluent API to build custom constraint violations.
-     * test that:
-     * the {@link org.apache.bval.constraints.ZipCodeCityCoherenceValidator} adds
-     * custom messages to the context and suppresses the default message
+     * Example 2.14. Using the fluent API to build custom constraint violations. test that: the
+     * {@link org.apache.bval.constraints.ZipCodeCityCoherenceValidator} adds custom messages to the context and
+     * suppresses the default message
      */
     public void testConstraintValidatorContextFluentAPI() {
         Address ad = new Address();
@@ -287,91 +311,412 @@ public class ValidationTest extends Test
         ad.setAddressline1("something");
         ad.setCountry(new Country());
         ad.getCountry().setName("something");
-        Validator v = getValidator();
-        Set<ConstraintViolation<Address>> violations = v.validate(ad);
+        Set<ConstraintViolation<Address>> violations = validator.validate(ad);
         Assert.assertEquals(2, violations.size());
-        for (ConstraintViolation each : violations) {
+        for (ConstraintViolation<Address> each : violations) {
             Assert.assertTrue(each.getMessage().endsWith(" not OK"));
         }
         assertNotNull(TestUtils.getViolation(violations, "city"));
         assertNotNull(TestUtils.getViolation(violations, ""));
     }
 
-    public void testValidateNestedPropertyPath() throws InvocationTargetException,
-          NoSuchMethodException, IllegalAccessException {
+    public void testValidateNestedPropertyPath() throws InvocationTargetException, NoSuchMethodException,
+        IllegalAccessException {
         final String propPath = "addresses[0].country.ISO2Code";
 
-        Validator v = getValidator();
         Author author = new Author();
-        author.setAddresses(new ArrayList());
+        author.setAddresses(new ArrayList<Address>());
         Address adr = new Address();
         author.getAddresses().add(adr);
         Country country = new Country();
         adr.setCountry(country);
         country.setISO2Code("too_long");
 
-        Set<ConstraintViolation<Author>> iv = v.validateProperty(author, propPath);
+        Set<ConstraintViolation<Author>> iv = validator.validateProperty(author, propPath);
         Assert.assertEquals(1, iv.size());
+        ConstraintViolation<Author> vio = iv.iterator().next();
+        assertEquals(propPath, vio.getPropertyPath().toString());
+        assertSame(author, vio.getRootBean());
+        assertSame(author.getAddresses().get(0).getCountry(), vio.getLeafBean());
+
         country.setISO2Code("23");
-        iv = v.validateProperty(author, propPath);
+        iv = validator.validateProperty(author, propPath);
         Assert.assertEquals(0, iv.size());
-        iv = v.validateValue(Author.class, propPath, "345");
+
+        iv = validator.validateValue(Author.class, propPath, "345");
         Assert.assertEquals(1, iv.size());
-        iv = v.validateValue(Author.class, propPath, "34");
+        vio = iv.iterator().next();
+        assertEquals(propPath, vio.getPropertyPath().toString());
+        assertNull(vio.getRootBean());
+        assertNull(vio.getLeafBean());
+
+        iv = validator.validateValue(Author.class, propPath, "34");
         Assert.assertEquals(0, iv.size());
     }
 
+    public void testValidateCascadingNestedBean() throws InvocationTargetException, NoSuchMethodException,
+        IllegalAccessException {
+        final String propPath = "addresses[0]";
+
+        CascadingPropertyValidator v = validator.unwrap(CascadingPropertyValidator.class);
+        Author author = new Author();
+        author.setAddresses(new ArrayList<Address>());
+        Address adr = new Address();
+        author.getAddresses().add(adr);
+        Country country = new Country();
+        adr.setCity("dark");
+        adr.setCountry(country);
+
+        Set<ConstraintViolation<Author>> iv = v.validateProperty(author, propPath);
+        Assert.assertEquals(1, iv.size()); // null address line 1 (no cascade)
+
+        country.setISO2Code("too_long");
+        iv = v.validateProperty(author, propPath, true);
+        Assert.assertEquals(3, iv.size()); // null address line 1 + null
+        // country.name + too long
+        // country.iso2code
+
+        country.setISO2Code("23");
+        iv = v.validateProperty(author, propPath, true);
+        Assert.assertEquals(2, iv.size()); // null address line 1 + null
+        // country.name, country.iso2code
+        // fixed
+
+        Address value = new Address();
+        value.setCity("whatever");
+        value.setAddressline1("1 address line");
+        iv = v.validateValue(Author.class, propPath, value, true);
+        Assert.assertEquals(1, iv.size()); // null country
+
+        value.setCountry(new Country());
+        iv = v.validateValue(Author.class, propPath, value, true);
+        Assert.assertEquals(1, iv.size()); // null country.name
+
+        value.getCountry().setName("NWO");
+        iv = v.validateValue(Author.class, propPath, value, true);
+        Assert.assertEquals(0, iv.size());
+    }
+
+    public void testValidateCascadingNestedProperty() throws InvocationTargetException, NoSuchMethodException,
+        IllegalAccessException {
+        final String propPath = "addresses[0].country";
+
+        CascadingPropertyValidator v = validator.unwrap(CascadingPropertyValidator.class);
+        Author author = new Author();
+        author.setAddresses(new ArrayList<Address>());
+        Address adr = new Address();
+        author.getAddresses().add(adr);
+        Country country = new Country();
+        adr.setCity("dark");
+        adr.setCountry(country);
+
+        Set<ConstraintViolation<Author>> iv = v.validateProperty(author, propPath);
+        Assert.assertEquals(0, iv.size());
+
+        country.setISO2Code("too_long");
+        iv = v.validateProperty(author, propPath, true);
+        Assert.assertEquals(2, iv.size());
+        // country.name + too long
+        // country.iso2code
+
+        country.setISO2Code("23");
+        iv = v.validateProperty(author, propPath, true);
+        Assert.assertEquals(1, iv.size());
+        // country.name, country.iso2code
+
+        Country value = null;
+        iv = v.validateValue(Author.class, propPath, value, true);
+        Assert.assertEquals(1, iv.size()); // null country
+
+        value = new Country();
+        iv = v.validateValue(Author.class, propPath, value, true);
+        Assert.assertEquals(1, iv.size()); // null country.name
+
+        value.setName("NWO");
+        iv = v.validateValue(Author.class, propPath, value, true);
+        Assert.assertEquals(0, iv.size());
+    }
+
+    public void testValidateCascadingNestedTipProperty() {
+        final String propPath = "addresses[0].country.name";
+
+        CascadingPropertyValidator v = validator.unwrap(CascadingPropertyValidator.class);
+        Author author = new Author();
+        author.setAddresses(new ArrayList<Address>());
+        Address adr = new Address();
+        author.getAddresses().add(adr);
+        Country country = new Country();
+        adr.setCity("dark");
+        adr.setCountry(country);
+
+        Set<ConstraintViolation<Author>> iv = v.validateProperty(author, propPath);
+        Assert.assertEquals(1, iv.size());
+
+        iv = v.validateProperty(author, propPath, true);
+        Assert.assertEquals(1, iv.size());
+    }
+
+    public void testValidateCascadingKeyedElement() throws InvocationTargetException, NoSuchMethodException,
+        IllegalAccessException {
+        final String propPath = "[foo]";
+
+        CascadingPropertyValidator v = validator.unwrap(CascadingPropertyValidator.class);
+        final Address adr = new Address();
+        @SuppressWarnings("serial")
+        Object map = new HashMap<String, Address>() {
+            {
+                put("foo", adr);
+            }
+        };
+        Country country = new Country();
+        adr.setCity("dark");
+        adr.setCountry(country);
+        Set<ConstraintViolation<Object>> iv = v.validateProperty(map, propPath);
+        Assert.assertEquals(1, iv.size()); // null address line 1 (no cascade)
+
+        country.setISO2Code("too_long");
+        iv = v.validateProperty(map, propPath, true);
+        Assert.assertEquals(3, iv.size()); // null address line 1 + null
+        // country.name + too long
+        // country.iso2code
+
+        country.setISO2Code("23");
+        iv = v.validateProperty(map, propPath, true);
+        Assert.assertEquals(2, iv.size()); // null address line 1 + null
+        // country.name, country.iso2code
+        // fixed
+
+        Address value = new Address();
+        value.setCity("whatever");
+        value.setAddressline1("1 address line");
+
+        Set<?> iv2 = v.validateValue(map.getClass(), propPath, value, true);
+        Assert.assertEquals(1, iv2.size()); // null country
+
+        value.setCountry(new Country());
+        iv2 = v.validateValue(map.getClass(), propPath, value, true);
+        Assert.assertEquals(1, iv2.size()); // null country.name
+
+        value.getCountry().setName("NWO");
+        iv2 = v.validateValue(map.getClass(), propPath, value, true);
+        Assert.assertEquals(0, iv2.size());
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testValidateCascadingKeyedGenericElement() throws InvocationTargetException, NoSuchMethodException,
+        IllegalAccessException {
+        final String propPath = "[foo]";
+
+        CascadingPropertyValidator v = validator.unwrap(CascadingPropertyValidator.class);
+        final Address adr = new Address();
+        Object map = new HashMap<String, Address>();
+        ((Map<String, Address>) map).put("foo", adr);
+        Country country = new Country();
+        adr.setCity("dark");
+        adr.setCountry(country);
+        Set<?> iv = v.validateProperty(map, propPath);
+        Assert.assertEquals(1, iv.size()); // null address line 1 (no cascade)
+
+        country.setISO2Code("too_long");
+        iv = v.validateProperty(map, propPath, true);
+        Assert.assertEquals(3, iv.size()); // null address line 1 + null
+        // country.name + too long
+        // country.iso2code
+
+        country.setISO2Code("23");
+        iv = v.validateProperty(map, propPath, true);
+        Assert.assertEquals(2, iv.size()); // null address line 1 + null
+        // country.name, country.iso2code
+        // fixed
+
+        Address value = new Address();
+        value.setCity("whatever");
+        value.setAddressline1("1 address line");
+
+        Set<?> iv2 = v.validateValue(Map.class, propPath, value, true);
+        Assert.assertEquals(1, iv2.size()); // null country
+
+        value.setCountry(new Country());
+        iv2 = v.validateValue(Map.class, propPath, value, true);
+        Assert.assertEquals(1, iv2.size()); // null country.name
+
+        value.getCountry().setName("NWO");
+        iv2 = v.validateValue(Map.class, propPath, value, true);
+        Assert.assertEquals(0, iv2.size());
+    }
+
+    public void testValidateCascadingIndexedElement() throws InvocationTargetException, NoSuchMethodException,
+        IllegalAccessException {
+        final String propPath = "[0]";
+        CascadingPropertyValidator v = validator.unwrap(CascadingPropertyValidator.class);
+        Address value = new Address();
+        value.setCity("whatever");
+        value.setAddressline1("1 address line");
+        Set<ConstraintViolation<Address[]>> iv;
+        Address[] array = { value };
+        iv = v.validateProperty(array, propPath, true);
+        Assert.assertEquals(1, iv.size()); // null country
+
+        value.setCountry(new Country());
+        iv = v.validateProperty(array, propPath, true);
+        Assert.assertEquals(1, iv.size()); // null country.name
+
+        value.getCountry().setName("NWO");
+        iv = v.validateProperty(array, propPath, true);
+        Assert.assertEquals(0, iv.size());
+
+        value = new Address();
+        value.setCity("whatever");
+        value.setAddressline1("1 address line");
+        Set<?> iv2;
+        iv2 = v.validateValue(array.getClass(), propPath, value, true);
+        Assert.assertEquals(1, iv2.size()); // null country
+
+        value.setCountry(new Country());
+        iv2 = v.validateValue(array.getClass(), propPath, value, true);
+        Assert.assertEquals(1, iv2.size()); // null country.name
+
+        value.getCountry().setName("NWO");
+        iv2 = v.validateValue(array.getClass(), propPath, value, true);
+        Assert.assertEquals(0, iv2.size());
+    }
+
+    public void testValidateCascadingIndexedGenericElement() throws InvocationTargetException, NoSuchMethodException,
+    IllegalAccessException {
+        final String propPath = "[0]";
+        CascadingPropertyValidator v = validator.unwrap(CascadingPropertyValidator.class);
+        Address value = new Address();
+        value.setCity("whatever");
+        value.setAddressline1("1 address line");
+        Set<?> iv;
+        Object list = Collections.singletonList(value);
+        iv = v.validateProperty(list, propPath, true);
+        Assert.assertEquals(1, iv.size()); // null country
+        
+        value.setCountry(new Country());
+        iv = v.validateProperty(list, propPath, true);
+        Assert.assertEquals(1, iv.size()); // null country.name
+        
+        value.getCountry().setName("NWO");
+        iv = v.validateProperty(list, propPath, true);
+        Assert.assertEquals(0, iv.size());
+        
+        value = new Address();
+        value.setCity("whatever");
+        value.setAddressline1("1 address line");
+        Set<?> iv2;
+        iv2 = v.validateValue(List.class, propPath, value, true);
+        Assert.assertEquals(1, iv2.size()); // null country
+        
+        value.setCountry(new Country());
+        iv2 = v.validateValue(List.class, propPath, value, true);
+        Assert.assertEquals(1, iv2.size()); // null country.name
+        
+        value.getCountry().setName("NWO");
+        iv2 = v.validateValue(List.class, propPath, value, true);
+        Assert.assertEquals(0, iv2.size());
+    }
+    
+    public interface Foo {
+    }
+
+    public static class FooAddress extends Address {
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        @NotNull(groups = Foo.class)
+        public String getCity() {
+            return super.getCity();
+        }
+    }
+
+    public void testValidateCascadingPropertyWithMultipleGroupsIgnoresSiblingProperties() {
+        final String propPath = "addresses[0].country";
+
+        CascadingPropertyValidator v = validator.unwrap(CascadingPropertyValidator.class);
+        Author author = new Author();
+        author.setAddresses(new ArrayList<Address>());
+        Address adr = new FooAddress();
+        author.getAddresses().add(adr);
+        Country country = new Country();
+        adr.setCountry(country);
+
+        Set<ConstraintViolation<Author>> iv = v.validateProperty(author, propPath, true, Default.class, Foo.class);
+        Assert.assertEquals(1, iv.size());
+    }
+
     public void testMetadataAPI() {
-        Validator bookValidator = getValidator();
-        BeanDescriptor bookBeanDescriptor =
-              bookValidator.getConstraintsForClass(Book.class);
+        BeanDescriptor bookBeanDescriptor = validator.getConstraintsForClass(Book.class);
 
         // expect no constraints on Book's Class-Level
         Assert.assertFalse(bookBeanDescriptor.hasConstraints());
         // but there are constraints on Book's Property-Level
         Assert.assertTrue(bookBeanDescriptor.isBeanConstrained());
-        Assert.assertTrue(
-              bookBeanDescriptor.getConstraintDescriptors().size() == 0); //no constraint
-        //more specifically "author" and "title"
+        Assert.assertTrue(bookBeanDescriptor.getConstraintDescriptors().size() == 0); // no
+        // constraint
+        // more specifically "author" and "title"
         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");
+        // 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;
+        // 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)) {
+            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
+        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();
+        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.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"));
+    }
+
+    public void testKeyedMetadata() {
+        @SuppressWarnings("serial")
+        BeanDescriptor beanDescriptor = validator.getConstraintsForClass(new HashMap<String, Object>() {
+        }.getClass());
+        Assert.assertNotNull(beanDescriptor);
+        Assert.assertFalse(beanDescriptor.isBeanConstrained());
+        Assert.assertNull(beanDescriptor.getConstraintsForProperty("[foo]"));
+    }
+
+    public void testGenericKeyedMetadata() {
+        BeanDescriptor beanDescriptor = validator.getConstraintsForClass(Map.class);
+        Assert.assertNotNull(beanDescriptor);
+        Assert.assertFalse(beanDescriptor.isBeanConstrained());
+        Assert.assertNull(beanDescriptor.getConstraintsForProperty("[foo]"));
+    }
+    
+    public void testIndexedMetadata() {
+        BeanDescriptor beanDescriptor = validator.getConstraintsForClass(Array.newInstance(Author.class, 0).getClass());
+        Assert.assertNotNull(beanDescriptor);
+        Assert.assertFalse(beanDescriptor.isBeanConstrained());
+        Assert.assertNull(beanDescriptor.getConstraintsForProperty("[0]"));
+    }
+    
+    public void testGenericIndexedMetadata() {
+        BeanDescriptor beanDescriptor = validator.getConstraintsForClass(List.class);
+        Assert.assertNotNull(beanDescriptor);
+        Assert.assertFalse(beanDescriptor.isBeanConstrained());
+        Assert.assertNull(beanDescriptor.getConstraintsForProperty("[0]"));
     }
 }

Modified: incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/ValidatorResolutionTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/ValidatorResolutionTest.java?rev=1166451&r1=1166450&r2=1166451&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/ValidatorResolutionTest.java (original)
+++ incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/ValidatorResolutionTest.java Wed Sep  7 22:32:26 2011
@@ -37,7 +37,6 @@ import static java.lang.annotation.Reten
  * @author Carlos Vara
  */
 public class ValidatorResolutionTest extends TestCase {
-
     static ValidatorFactory factory;
 
     static {
@@ -45,7 +44,26 @@ public class ValidatorResolutionTest ext
         ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
     }
 
-    private Validator getValidator() {
+    /**
+     * Validator instance to test
+     */
+    protected Validator validator;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        validator = createValidator();
+    }
+
+    /**
+     * Create the validator instance.
+     * 
+     * @return Validator
+     */
+    protected Validator createValidator() {
         return factory.getValidator();
     }
 
@@ -54,7 +72,6 @@ public class ValidatorResolutionTest ext
      * only available validator is associated with a different annotation type.
      */
     public void testInvalidValidator() {
-        Validator validator = getValidator();
         try {
             validator.validate(new Person());
             fail("No exception thrown, but no valid validator available.");
@@ -62,30 +79,32 @@ public class ValidatorResolutionTest ext
             // correct
         }
     }
-    
-    
+
     public static class Person {
         @PersonName
         public String name;
     }
-    
-    @Constraint(validatedBy = {InvalidPersonNameValidator.class})
+
+    @Constraint(validatedBy = { InvalidPersonNameValidator.class })
     @Documented
-    @Target({ METHOD, FIELD, TYPE })
+    @Target( { METHOD, FIELD, TYPE })
     @Retention(RUNTIME)
     public static @interface PersonName {
         String message() default "Wrong person name";
-        Class<?>[] groups() default { };
+
+        Class<?>[] groups() default {};
+
         Class<? extends Payload>[] payload() default {};
     }
-    
+
     public static class InvalidPersonNameValidator implements ConstraintValidator<NotNull, String> {
         public void initialize(NotNull constraintAnnotation) {
             // Nothing
         }
+
         public boolean isValid(String value, ConstraintValidatorContext context) {
             return true;
         }
     }
-    
+
 }

Added: incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/example/IllustratedBook.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/example/IllustratedBook.java?rev=1166451&view=auto
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/example/IllustratedBook.java (added)
+++ incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/example/IllustratedBook.java Wed Sep  7 22:32:26 2011
@@ -0,0 +1,41 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.bval.jsr303.example;
+
+/**
+ * Add a non-cascaded bean to a book.
+ * 
+ * @version $Rev: 1004764 $ $Date: 2010-10-05 13:35:42 -0500 (Tue, 05 Oct 2010) $
+ */
+public class IllustratedBook extends Book {
+    private Person illustrator;
+
+    /**
+     * @return the illustrator
+     */
+    public Person getIllustrator() {
+        return illustrator;
+    }
+
+    /**
+     * @param illustrator
+     *            the illustrator to set
+     */
+    public void setIllustrator(Person illustrator) {
+        this.illustrator = illustrator;
+    }
+}

Propchange: incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/example/IllustratedBook.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/example/Library.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/example/Library.java?rev=1166451&r1=1166450&r2=1166451&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/example/Library.java (original)
+++ incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/example/Library.java Wed Sep  7 22:32:26 2011
@@ -18,9 +18,14 @@
  */
 package org.apache.bval.jsr303.example;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 import javax.validation.Valid;
 import javax.validation.constraints.NotNull;
-import java.util.*;
 
 /**
  * Description: <br/>
@@ -29,8 +34,8 @@ public class Library {
     @NotNull
     private String libraryName;
     @Valid
-    private final Map<String,Book> taggedBooks = new HashMap();
-    
+    private final Map<String, Book> taggedBooks = new HashMap<String, Book>();
+
     private Person[] persons;
 
     public String getLibraryName() {
@@ -55,11 +60,13 @@ public class Library {
 
     @Valid
     public List<Employee> getEmployees() {
-        if(persons == null) return Collections.emptyList();
+        if (persons == null)
+            return Collections.emptyList();
 
-        ArrayList<Employee> emps = new ArrayList(persons.length);
-        for(Person each : persons) {
-            if(each instanceof Employee) emps.add((Employee) each);
+        ArrayList<Employee> emps = new ArrayList<Employee>(persons.length);
+        for (Person each : persons) {
+            if (each instanceof Employee)
+                emps.add((Employee) each);
         }
         return emps;
     }

Modified: incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/example/RecursiveFoo.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/example/RecursiveFoo.java?rev=1166451&r1=1166450&r2=1166451&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/example/RecursiveFoo.java (original)
+++ incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/example/RecursiveFoo.java Wed Sep  7 22:32:26 2011
@@ -31,7 +31,7 @@ import java.util.Collection;
 public class RecursiveFoo {
     @NotEmpty
     @Valid
-    Collection<RecursiveFoo> foos = new ArrayList();
+    Collection<RecursiveFoo> foos = new ArrayList<RecursiveFoo>();
 
     public Collection<RecursiveFoo> getFoos() {
         return foos;

Modified: incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/extensions/MethodValidatorImplTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/extensions/MethodValidatorImplTest.java?rev=1166451&r1=1166450&r2=1166451&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/extensions/MethodValidatorImplTest.java (original)
+++ incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/extensions/MethodValidatorImplTest.java Wed Sep  7 22:32:26 2011
@@ -20,10 +20,13 @@ import junit.framework.Assert;
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
-import org.apache.bval.jsr303.ApacheValidatorFactory;
+
+import org.apache.bval.jsr303.ApacheValidationProvider;
+import org.apache.bval.jsr303.ApacheValidatorConfiguration;
 import org.apache.bval.jsr303.ClassValidator;
 import org.apache.bval.jsr303.extensions.ExampleMethodService.Person;
 
+import javax.validation.Validation;
 import javax.validation.ValidationException;
 import javax.validation.Validator;
 import javax.validation.constraints.NotNull;
@@ -39,6 +42,7 @@ import java.util.Set;
  * @version 1.0
  * @since <pre>11/11/2009</pre>
  */
+@SuppressWarnings({ "unchecked", "rawtypes" })
 public class MethodValidatorImplTest extends TestCase {
     public MethodValidatorImplTest(String name) {
         super(name);
@@ -276,6 +280,10 @@ public class MethodValidatorImplTest ext
     
 
     private Validator getValidator() {
-        return ApacheValidatorFactory.getDefault().getValidator();
+        return Validation
+            .byProvider(ApacheValidationProvider.class)
+            .configure()
+            .addProperty(ApacheValidatorConfiguration.Properties.METABEAN_FACTORY_CLASSNAMES,
+                MethodValidatorMetaBeanFactory.class.getName()).buildValidatorFactory().getValidator();
     }
 }



Mime
View raw message