incubator-bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1136596 - in /incubator/bval/sandbox/lang3-work: bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/jsr303/dynamic/DynamicClassValidator.java bval-jsr303/src/test/java/org/apache/bval/jsr303/ValidationTest.java
Date Thu, 16 Jun 2011 18:46:50 GMT
Author: mbenson
Date: Thu Jun 16 18:46:49 2011
New Revision: 1136596

URL: http://svn.apache.org/viewvc?rev=1136596&view=rev
Log:
handle requests for indexed/keyed metadata

Modified:
    incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/jsr303/dynamic/DynamicClassValidator.java
    incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/ValidationTest.java

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/jsr303/dynamic/DynamicClassValidator.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/jsr303/dynamic/DynamicClassValidator.java?rev=1136596&r1=1136595&r2=1136596&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/jsr303/dynamic/DynamicClassValidator.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/jsr303/dynamic/DynamicClassValidator.java
Thu Jun 16 18:46:49 2011
@@ -26,6 +26,7 @@ import javax.validation.metadata.BeanDes
 import javax.validation.metadata.ConstraintDescriptor;
 import javax.validation.metadata.PropertyDescriptor;
 
+import org.apache.bval.DynamicMetaBean;
 import org.apache.bval.jsr303.BeanDescriptorImpl;
 import org.apache.bval.jsr303.ClassValidator;
 import org.apache.bval.jsr303.ElementDescriptorImpl;
@@ -153,7 +154,9 @@ public class DynamicClassValidator exten
             Validate.isTrue(StringUtils.isNotEmpty(propertyName), "Invalid path '%s'", propertyName);
 
             try {
-                GroupValidationContext<?> validationContext = createContext(metaBean,
null, metaBean.getBeanClass());
+                final DynamicMetaBean rootMetaBean = new DynamicMetaBean(getMetaBeanFinder());
+                rootMetaBean.setBeanClass(elementClass);
+                GroupValidationContext<?> validationContext = createContext(rootMetaBean,
null, elementClass);
 
                 try {
                     PathNavigation.navigate(propertyName, createValidationContextTraversal(validationContext));
@@ -161,7 +164,7 @@ public class DynamicClassValidator exten
                     return null;
                 }
 
-                boolean cascaded;
+                boolean cascaded = false;
                 Class<?> propertyType;
                 Validation[] validations;
                 MetaProperty prop = validationContext.getMetaProperty();
@@ -170,7 +173,6 @@ public class DynamicClassValidator exten
                     propertyType = prop.getTypeClass();
                     validations = prop.getValidations();
                 } else { // must be in iterable:
-                    cascaded = true;
                     propertyType = validationContext.getMetaBean().getBeanClass();
                     validations = validationContext.getMetaBean().getValidations();
                 }

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/ValidationTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/ValidationTest.java?rev=1136596&r1=1136595&r2=1136596&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/ValidationTest.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/ValidationTest.java
Thu Jun 16 18:46:49 2011
@@ -18,6 +18,7 @@
  */
 package org.apache.bval.jsr303;
 
+import java.lang.reflect.Array;
 import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -688,4 +689,34 @@ public class ValidationTest extends Test
         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]"));
+    }
 }



Mime
View raw message