WW-2587 @SkipValidation not found on superclass method

git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@663335 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Musachy Barroso
2008-06-04 18:15:36 +00:00
parent 6f47a90767
commit 2c54264bcc
2 changed files with 34 additions and 2 deletions
@@ -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 @@ public class AnnotationValidationInterceptor extends ValidationInterceptor {
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();
}
}
@@ -67,13 +67,19 @@ public class AnnotationValidationInterceptorTest extends StrutsTestCase {
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 class AnnotationValidationInterceptorTest extends StrutsTestCase {
public String skipMe2() {
return "skipme2";
}
public String skipMeBase() {
return "skipme";
}
}
public static class TestActionBase {
@@ -105,6 +115,11 @@ public class AnnotationValidationInterceptorTest extends StrutsTestCase {
return "skipme";
}
@SkipValidation
public String skipMeBase2() {
return "skipme";
}
public String dontSkipMeBase() {
return "dontskipme";
}