incubator-bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romanst...@apache.org
Subject svn commit: r938836 - in /incubator/bval/trunk: bval-core/src/main/java/org/apache/bval/util/PrivilegedActions.java bval-jsr303/src/test/java/org/apache/bval/jsr303/ConstraintDefinitionsTest.java
Date Wed, 28 Apr 2010 09:25:13 GMT
Author: romanstumm
Date: Wed Apr 28 09:25:12 2010
New Revision: 938836

URL: http://svn.apache.org/viewvc?rev=938836&view=rev
Log:
BVAL-26 IllegalAccessException is thrown when accesing annotation values
merged fixed from Carlos

Added:
    incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/ConstraintDefinitionsTest.java
Modified:
    incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/util/PrivilegedActions.java

Modified: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/util/PrivilegedActions.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/util/PrivilegedActions.java?rev=938836&r1=938835&r2=938836&view=diff
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/util/PrivilegedActions.java
(original)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/util/PrivilegedActions.java
Wed Apr 28 09:25:12 2010
@@ -121,6 +121,7 @@ public class PrivilegedActions {
                 } catch (NoSuchMethodException ex) { /* do nothing */ }
                 if (null != valueMethod) {
                     try {
+                        valueMethod.setAccessible(true);
                         return valueMethod.invoke(annotation);
                     } catch (Exception e) {
                         throw new RuntimeException(e);

Added: 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=938836&view=auto
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/ConstraintDefinitionsTest.java
(added)
+++ incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/ConstraintDefinitionsTest.java
Wed Apr 28 09:25:12 2010
@@ -0,0 +1,90 @@
+/*
+ * 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.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;
+
+
+/**
+ * Checks the correct parsing of constraint definitions.
+ * 
+ * @author Carlos Vara
+ */
+public class ConstraintDefinitionsTest extends TestCase {
+    
+    static ValidatorFactory factory;
+
+    static {
+        factory = Validation.buildDefaultValidatorFactory();
+        ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
+    }
+
+    private Validator getValidator() {
+        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();
+        
+        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());
+        }
+    }
+
+    
+    public static class Person {
+        @MinList({
+            @Min(value=20),
+            @Min(value=30)
+        })
+        public Integer age;
+    }
+    
+}
+
+@Target({ METHOD, FIELD, ANNOTATION_TYPE })
+@Retention(RUNTIME)
+@Documented
+@interface MinList {
+    Min[] value();
+}
\ No newline at end of file



Mime
View raw message