struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From musa...@apache.org
Subject svn commit: r661795 - in /struts/struts2/trunk/core/src: main/java/org/apache/struts2/interceptor/validation/AnnotationValidationInterceptor.java test/java/org/apache/struts2/interceptor/validation/AnnotationValidationInterceptorTest.java
Date Fri, 30 May 2008 17:30:20 GMT
Author: musachy
Date: Fri May 30 10:30:19 2008
New Revision: 661795

URL: http://svn.apache.org/viewvc?rev=661795&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=661795&r1=661794&r2=661795&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
Fri May 30 10:30:19 2008
@@ -22,8 +22,10 @@
 package org.apache.struts2.interceptor.validation;
 
 import java.lang.reflect.Method;
+import java.util.Collection;
 
 import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.util.AnnotationUtils;
 import com.opensymphony.xwork2.validator.ValidationInterceptor;
 
 /**
@@ -31,24 +33,24 @@
  * annotation, and if found, don't validate this action method
  */
 public class AnnotationValidationInterceptor extends ValidationInterceptor {
-    
+
     /** Auto-generated serialization id */
     private static final long serialVersionUID = 1813272797367431184L;
 
     protected String doIntercept(ActionInvocation invocation) throws Exception {
-        
+
         Object action = invocation.getAction();
         if (action != null) {
             Method method = getActionMethod(action.getClass(), invocation.getProxy().getMethod());
-            SkipValidation skip = (SkipValidation) method.getAnnotation(SkipValidation.class);
-            if (skip != null) {
+            Collection<Method> annotatedMethods = AnnotationUtils.getAnnotatedMethods(action.getClass(),
SkipValidation.class);
+            if (annotatedMethods.contains(method)) {
                 return invocation.invoke();
             }
         }
-        
+
         return super.doIntercept(invocation);
     }
-    
+
     // FIXME: This is copied from DefaultActionInvocation but should be exposed through the
interface
     protected Method getActionMethod(Class actionClass, String methodName) throws NoSuchMethodException
{
         Method method;

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=661795&r1=661794&r2=661795&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
Fri May 30 10:30:19 2008
@@ -54,22 +54,64 @@
         interceptor.doIntercept((ActionInvocation)mockActionInvocation.proxy());
         mockActionProxy.verify();
     }
-    
+
     public void testShouldSkip() throws Exception {
         mockActionProxy.expectAndReturn("getMethod", "skipMe");
         interceptor.doIntercept((ActionInvocation)mockActionInvocation.proxy());
         mockActionProxy.verify();
     }
-    
-    public static class TestAction  {
-        
+
+    public void testShouldSkipBase() throws Exception {
+        mockActionProxy.expectAndReturn("getMethod", "skipMeBase");
+        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 {
+        mockActionProxy.expectAndReturn("getMethod", "dontSkipMeBase");
+        mockActionProxy.expectAndReturn("getActionName", "foo");
+        mockActionProxy.expectAndReturn("getMethod", "dontSkipMeBase");
+        interceptor.doIntercept((ActionInvocation)mockActionInvocation.proxy());
+        mockActionProxy.verify();
+    }
+
+    public static class TestAction extends TestActionBase {
+
         public String execute() {
             return "execute";
         }
-        
+
         @SkipValidation
         public String skipMe() {
             return "skipme";
         }
+
+        @SkipValidation
+        public String skipMe2() {
+            return "skipme2";
+        }
+    }
+
+    public static class TestActionBase  {
+
+        @SkipValidation
+        public String skipMeBase() {
+            return "skipme";
+        }
+
+        public String dontSkipMeBase() {
+            return "dontskipme";
+        }
+
+        public String skipMe2() {
+            return "skipme2";
+        }
     }
+
 }



Mime
View raw message