You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by mu...@apache.org on 2008/06/04 20:15:37 UTC

svn commit: r663335 - in /struts/struts2/trunk/core/src: main/java/org/apache/struts2/interceptor/validation/AnnotationValidationInterceptor.java test/java/org/apache/struts2/interceptor/validation/AnnotationValidationInterceptorTest.java

Author: musachy
Date: Wed Jun  4 11:15:36 2008
New Revision: 663335

URL: http://svn.apache.org/viewvc?rev=663335&view=rev
Log:
WW-2587 @SkipValidation not found on superclass method

Modified:
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/validation/AnnotationValidationInterceptor.java
    struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/validation/AnnotationValidationInterceptorTest.java

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/validation/AnnotationValidationInterceptor.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/validation/AnnotationValidationInterceptor.java?rev=663335&r1=663334&r2=663335&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/validation/AnnotationValidationInterceptor.java (original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/validation/AnnotationValidationInterceptor.java Wed Jun  4 11:15:36 2008
@@ -22,8 +22,11 @@
 package org.apache.struts2.interceptor.validation;
 
 import java.lang.reflect.Method;
+import java.util.Arrays;
 import java.util.Collection;
 
+import org.apache.commons.lang.ArrayUtils;
+
 import com.opensymphony.xwork2.ActionInvocation;
 import com.opensymphony.xwork2.util.AnnotationUtils;
 import com.opensymphony.xwork2.validator.ValidationInterceptor;
@@ -43,8 +46,22 @@
         if (action != null) {
             Method method = getActionMethod(action.getClass(), invocation.getProxy().getMethod());
             Collection<Method> annotatedMethods = AnnotationUtils.getAnnotatedMethods(action.getClass(), SkipValidation.class);
-            if (annotatedMethods.contains(method)) {
+            if (annotatedMethods.contains(method))
                 return invocation.invoke();
+
+            //check if method overwites an annotated method
+            Class clazz = action.getClass().getSuperclass();
+            while (clazz != null) {
+                annotatedMethods = AnnotationUtils.getAnnotatedMethods(clazz, SkipValidation.class);
+                if (annotatedMethods != null) {
+                    for (Method annotatedMethod : annotatedMethods) {
+                        if (annotatedMethod.getName().equals(method.getName())
+                                && Arrays.equals(annotatedMethod.getParameterTypes(), method.getParameterTypes())
+                                && Arrays.equals(annotatedMethod.getExceptionTypes(), method.getExceptionTypes()))
+                            return invocation.invoke();
+                    }
+                }
+                clazz = clazz.getSuperclass();
             }
         }
 

Modified: struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/validation/AnnotationValidationInterceptorTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/validation/AnnotationValidationInterceptorTest.java?rev=663335&r1=663334&r2=663335&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/validation/AnnotationValidationInterceptorTest.java (original)
+++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/validation/AnnotationValidationInterceptorTest.java Wed Jun  4 11:15:36 2008
@@ -67,13 +67,19 @@
         mockActionProxy.verify();
     }
 
+    public void testShouldSkipBase2() throws Exception {
+        mockActionProxy.expectAndReturn("getMethod", "skipMeBase2");
+        interceptor.doIntercept((ActionInvocation)mockActionInvocation.proxy());
+        mockActionProxy.verify();
+    }
+
     public void testShouldSkip2() throws Exception {
         mockActionProxy.expectAndReturn("getMethod", "skipMe2");
         interceptor.doIntercept((ActionInvocation)mockActionInvocation.proxy());
         mockActionProxy.verify();
     }
 
-    public void testDontShouldSkipBase() throws Exception {
+    public void testShouldNotSkipBase() throws Exception {
         mockActionProxy.expectAndReturn("getMethod", "dontSkipMeBase");
         mockActionProxy.expectAndReturn("getActionName", "foo");
         mockActionProxy.expectAndReturn("getMethod", "dontSkipMeBase");
@@ -96,6 +102,10 @@
         public String skipMe2() {
             return "skipme2";
         }
+
+        public String skipMeBase() {
+            return "skipme";
+        }
     }
 
     public static class TestActionBase  {
@@ -105,6 +115,11 @@
             return "skipme";
         }
 
+        @SkipValidation
+        public String skipMeBase2() {
+            return "skipme";
+        }
+
         public String dontSkipMeBase() {
             return "dontskipme";
         }