Commits

Anonymous committed 62fc6f4

-XW-416
- DefaultWorkflowInterceptor should throw exception occured in validateXXX and validateDoXXX methods

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@1136e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits 8b30c2c

Comments (0)

Files changed (2)

src/java/com/opensymphony/xwork2/interceptor/DefaultWorkflowInterceptor.java

         
         
         if (action instanceof Validateable) {
+        	// keep exception that might occured in validateXXX or validateDoXXX
+        	Exception exception = null; 
         	
             Validateable validateable = (Validateable) action;
             if (_log.isDebugEnabled()) {
             			new String[] { VALIDATE_PREFIX, ALT_VALIDATE_PREFIX });
             }
             catch(Exception e) {
-            	e.printStackTrace();
             	// If any exception occurred while doing reflection, we want 
             	// validate() to be executed
             	_log.warn("an exception occured while executing the prefix method", e);
+            	exception = e;
             }
             
             
             if (alwaysInvokeValidate) {
             	validateable.validate();
             }
+            
+            if (exception != null) { 
+            	// rethrow if something is wrong while doing validateXXX / validateDoXXX 
+            	throw exception;
+            }
         }
         
 

src/test/com/opensymphony/xwork2/interceptor/DefaultWorkflowInterceptor2Test.java

+package com.opensymphony.xwork2.interceptor;
+
+import junit.framework.TestCase;
+
+import org.easymock.MockControl;
+
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.ActionProxy;
+import com.opensymphony.xwork2.ActionSupport;
+import com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor;
+
+public class DefaultWorkflowInterceptor2Test extends TestCase {
+	
+	public void testValidateXXXThrowsException() throws Exception {
+		
+		ValidateXXXAction action = new ValidateXXXAction();
+		
+		MockControl actionProxyControl = MockControl.createControl(ActionProxy.class);
+		ActionProxy actionProxy = (ActionProxy) actionProxyControl.getMock();
+		actionProxy.getMethod();
+		actionProxyControl.expectAndDefaultReturn(null, "execute");
+		
+		
+		MockControl actionInvocationControl = MockControl.createControl(ActionInvocation.class);
+		ActionInvocation actionInvocation = (ActionInvocation) actionInvocationControl.getMock();
+		actionInvocation.invoke();
+		actionInvocationControl.expectAndDefaultReturn(null, "test");
+		actionInvocation.getProxy();
+		actionInvocationControl.expectAndDefaultReturn(null, actionProxy);
+		actionInvocation.getAction();
+		actionInvocationControl.expectAndDefaultReturn(null, action);
+		
+		actionInvocationControl.replay();
+		actionProxyControl.replay();
+		
+		DefaultWorkflowInterceptor interceptor = new DefaultWorkflowInterceptor();
+		try {
+			interceptor.intercept(actionInvocation);
+			fail();
+		}
+		catch(Exception e) {
+			assertTrue(true);
+		}
+		
+		assertTrue(action.isExecuted);
+		actionInvocationControl.verify();
+		actionProxyControl.verify();
+	}
+	
+	
+	public void testValidateDoXXXThowsException() throws Exception {
+		ValidateDoXXXAction action = new ValidateDoXXXAction();
+		
+		MockControl actionProxyControl = MockControl.createControl(ActionProxy.class);
+		ActionProxy actionProxy = (ActionProxy) actionProxyControl.getMock();
+		actionProxy.getMethod();
+		actionProxyControl.expectAndDefaultReturn(null, "execute");
+		
+		
+		MockControl actionInvocationControl = MockControl.createControl(ActionInvocation.class);
+		ActionInvocation actionInvocation = (ActionInvocation) actionInvocationControl.getMock();
+		actionInvocation.invoke();
+		actionInvocationControl.expectAndDefaultReturn(null, "test");
+		actionInvocation.getProxy();
+		actionInvocationControl.expectAndDefaultReturn(null, actionProxy);
+		actionInvocation.getAction();
+		actionInvocationControl.expectAndDefaultReturn(null, action);
+		
+		actionInvocationControl.replay();
+		actionProxyControl.replay();
+		
+		DefaultWorkflowInterceptor interceptor = new DefaultWorkflowInterceptor();
+		try {
+			interceptor.intercept(actionInvocation);
+			fail();
+		}
+		catch(Exception e) {
+			assertTrue(true);
+		}
+		
+		assertTrue(action.isExecuted);
+		actionInvocationControl.verify();
+		actionProxyControl.verify();
+	}
+	
+	
+	public class ValidateXXXAction extends ActionSupport {
+		
+		private static final long serialVersionUID = 1161896580929473760L;
+		
+		public boolean isExecuted = false;
+		public void validateExecute() throws Exception {
+			isExecuted = true;
+			throw new Exception("testing");
+		}
+	}
+	
+	public class ValidateDoXXXAction extends ActionSupport {
+		
+		private static final long serialVersionUID = 2923102033415402386L;
+		
+		public boolean isExecuted = false;
+		public void validateDoExecute() throws Exception {
+			isExecuted = true;
+			throw new Exception ("testing");
+		}
+	}
+}