incubator-bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romanst...@apache.org
Subject svn commit: r941210 - in /incubator/bval/trunk/bval-jsr303/src: main/java/org/apache/bval/jsr303/AnnotationConstraintBuilder.java test/java/org/apache/bval/jsr303/BeanDescriptorTest.java
Date Wed, 05 May 2010 09:09:30 GMT
Author: romanstumm
Date: Wed May  5 09:09:30 2010
New Revision: 941210

URL: http://svn.apache.org/viewvc?rev=941210&view=rev
Log:
BVAL-38 Groups and payload values must be part of the ConstraintDescriptor attributes - from
Carlos Varla

Added:
    incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/BeanDescriptorTest.java
Modified:
    incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/AnnotationConstraintBuilder.java

Modified: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/AnnotationConstraintBuilder.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/AnnotationConstraintBuilder.java?rev=941210&r1=941209&r2=941210&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/AnnotationConstraintBuilder.java
(original)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/AnnotationConstraintBuilder.java
Wed May  5 09:09:30 2010
@@ -65,18 +65,17 @@ final class AnnotationConstraintBuilder 
                     for (Method method : constraintValidation.getAnnotation()
                           .annotationType()
                           .getDeclaredMethods()) {
-                        // enhancement: clarify: should groups + payload also appear in attributes?
+                        // groups + payload must also appear in attributes (also checked
by TCK-Tests)
                         if (method.getParameterTypes().length == 0) {
                             try {
                                 if (ANNOTATION_PAYLOAD.equals(method.getName())) {
                                     buildPayload(method);
                                 } else if (ANNOTATION_GROUPS.equals(method.getName())) {
                                     buildGroups(method);
-                                } else {
-                                    constraintValidation.getAttributes()
-                                          .put(method.getName(), method.invoke(
-                                                constraintValidation.getAnnotation()));
                                 }
+                                constraintValidation.getAttributes()
+                                      .put(method.getName(), method.invoke(
+                                            constraintValidation.getAnnotation()));
                             } catch (Exception e) { // do nothing
                                 log.warn("error processing annotation: " +
                                       constraintValidation.getAnnotation(), e);
@@ -177,16 +176,16 @@ final class AnnotationConstraintBuilder 
             if ( override != null ) {
                 override.applyOn(composite);
             }
-            
+
         }
     }
 
-    
+
     /**
      * Calculates the index of the composite constraint. The index represents
      * the order in which it is added in reference to other constraints of the
      * same type.
-     * 
+     *
      * @param composite
      *            The composite constraint (not yet added).
      * @return An integer index always >= 0
@@ -263,7 +262,7 @@ final class AnnotationConstraintBuilder 
         public void applyOn(ConstraintValidation composite) {
             // Update the attributes
             composite.getAttributes().putAll(values);
-            
+
             // And the annotation
             Annotation originalAnnot = composite.getAnnotation();
             AnnotationProxyBuilder<Annotation> apb = new AnnotationProxyBuilder<Annotation>(originalAnnot);

Added: incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/BeanDescriptorTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/BeanDescriptorTest.java?rev=941210&view=auto
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/BeanDescriptorTest.java
(added)
+++ incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/BeanDescriptorTest.java
Wed May  5 09:09:30 2010
@@ -0,0 +1,73 @@
+/*
+ * 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;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import javax.validation.Validation;
+import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
+import javax.validation.constraints.NotNull;
+import javax.validation.metadata.BeanDescriptor;
+import javax.validation.metadata.ConstraintDescriptor;
+import java.util.Locale;
+import java.util.Set;
+
+/**
+ * Tests the implementation of {@link BeanDescriptor} and its dependent
+ * interfaces.
+ * 
+ * @author Carlos Vara
+ */
+public class BeanDescriptorTest extends TestCase {
+
+    static ValidatorFactory factory;
+
+    static {
+        factory = Validation.buildDefaultValidatorFactory();
+        ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
+    }
+
+    private Validator getValidator() {
+        return factory.getValidator();
+    }
+    
+    
+    /**
+     * Check that groups(), message() and payload() are always in the
+     * attributes.
+     */
+    public void testMandatoryAttributesPresentInConstraintDescriptor() {
+        Validator validator = getValidator();
+        
+        Set<ConstraintDescriptor<?>> nameDescriptors = validator.getConstraintsForClass(Form.class).getConstraintsForProperty("name").getConstraintDescriptors();
+        Assert.assertEquals("Incorrect number of descriptors", 1, nameDescriptors.size());
+        ConstraintDescriptor<?> nameDescriptor = nameDescriptors.iterator().next();
+        Assert.assertTrue("groups attribute not present", nameDescriptor.getAttributes().containsKey("groups"));
+        Assert.assertTrue("payload attribute not present", nameDescriptor.getAttributes().containsKey("payload"));
+        Assert.assertTrue("message attribute not present", nameDescriptor.getAttributes().containsKey("message"));
+    }
+    
+    public static class Form {
+        @NotNull
+        public String name;
+    }
+    
+}



Mime
View raw message