Author: mrdon
Date: Mon Apr 25 17:22:12 2005
New Revision: 164696

URL: http://svn.apache.org/viewcvs?rev=164696&view=rev
Log:
 * Added null check for forward path before processing
 * Added unit test for PerformForward to ensure correct behavior

PR: 26803 

Added:
    
struts/core/trunk/src/test/org/apache/struts/chain/commands/servlet/TestPerformForward.java
Modified:
    
struts/core/trunk/src/share/org/apache/struts/action/ActionResources.properties
    
struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/PerformForward.java

Modified: 
struts/core/trunk/src/share/org/apache/struts/action/ActionResources.properties
URL: 
http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/action/ActionResources.properties?rev=164696&r1=164695&r2=164696&view=diff
==============================================================================
--- 
struts/core/trunk/src/share/org/apache/struts/action/ActionResources.properties 
(original)
+++ 
struts/core/trunk/src/share/org/apache/struts/action/ActionResources.properties 
Mon Apr 25 17:22:12 2005
@@ -15,6 +15,7 @@
 configWebXml=The /WEB-INF/web.xml was not found.
 finalizing=Finalizing this controller servlet
 formBean=Error creating form bean of class {0}
+forwardPathNull=The path of an ForwardConfig cannot be null
 initProcessor=Exception initializing RequestProcessor
 mappingType=Must specify one of "forward", "include" or "type" for path {0}
 notAuthorized=User is not authorized to access action {0}

Modified: 
struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/PerformForward.java
URL: 
http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/PerformForward.java?rev=164696&r1=164695&r2=164696&view=diff
==============================================================================
--- 
struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/PerformForward.java
 (original)
+++ 
struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/PerformForward.java
 Mon Apr 25 17:22:12 2005
@@ -20,12 +20,15 @@
 import javax.servlet.RequestDispatcher;
 import javax.servlet.http.HttpServletRequest;
 
+import org.apache.struts.action.ActionServlet;
 import org.apache.struts.chain.commands.AbstractPerformForward;
 import org.apache.struts.chain.contexts.ActionContext;
 import org.apache.struts.chain.contexts.ServletActionContext;
+import org.apache.struts.config.ActionConfig;
 import org.apache.struts.config.ForwardConfig;
 import org.apache.struts.config.ModuleConfig;
 import org.apache.struts.upload.MultipartRequestWrapper;
+import org.apache.struts.util.MessageResources;
 import org.apache.struts.util.RequestUtils;
 
 
@@ -55,6 +58,13 @@
         ServletActionContext sacontext = (ServletActionContext) context;
         String forwardPath = forwardConfig.getPath();
         String uri = null;
+
+        if (forwardPath == null) {
+            // Retrieve internal message resources
+            ActionServlet servlet =  (ActionServlet) 
sacontext.getActionServlet();
+            MessageResources resources = servlet.getInternal();
+            throw new 
IllegalArgumentException(resources.getMessage("forwardPathNull"));      
+        }
 
         ModuleConfig moduleConfig  = context.getModuleConfig();
         // Resolve module-relative paths

Added: 
struts/core/trunk/src/test/org/apache/struts/chain/commands/servlet/TestPerformForward.java
URL: 
http://svn.apache.org/viewcvs/struts/core/trunk/src/test/org/apache/struts/chain/commands/servlet/TestPerformForward.java?rev=164696&view=auto
==============================================================================
--- 
struts/core/trunk/src/test/org/apache/struts/chain/commands/servlet/TestPerformForward.java
 (added)
+++ 
struts/core/trunk/src/test/org/apache/struts/chain/commands/servlet/TestPerformForward.java
 Mon Apr 25 17:22:12 2005
@@ -0,0 +1,70 @@
+package org.apache.struts.chain.commands.servlet;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.chain.web.servlet.ServletWebContext;
+import org.apache.struts.chain.commands.UnauthorizedActionException;
+import org.apache.struts.chain.contexts.ServletActionContext;
+import org.apache.struts.config.ActionConfig;
+import org.apache.struts.config.ForwardConfig;
+import org.apache.struts.mock.MockActionServlet;
+import org.apache.struts.mock.MockHttpServletRequest;
+import org.apache.struts.mock.MockHttpServletResponse;
+import org.apache.struts.mock.MockPrincipal;
+import org.apache.struts.mock.MockServletConfig;
+import org.apache.struts.mock.MockServletContext;
+
+/* JUnitTest case for class: 
org.apache.struts.chain.commands.servlet.PerformForward */
+public class TestPerformForward extends TestCase {
+
+    MockHttpServletRequest request = null;
+    MockPrincipal principal = null;
+
+    ServletWebContext swContext = null;
+    ServletActionContext saContext = null;
+    PerformForward command = null;
+
+    public TestPerformForward(String _name) {
+        super(_name);
+    }
+
+
+    /* setUp method for test case */
+    protected void setUp() throws Exception {
+        this.request = new MockHttpServletRequest();
+        this.principal = new MockPrincipal("Mr. Macri", new String[]{ 
"administrator" });
+        this.request.setUserPrincipal(principal);
+        MockServletConfig servletConfig = new MockServletConfig();
+        MockServletContext servletContext = new MockServletContext();
+        MockActionServlet servlet = new MockActionServlet(servletContext, 
servletConfig);
+        servlet.initInternal();
+
+        this.saContext = new ServletActionContext(servletContext, request, new 
MockHttpServletResponse());
+
+        this.saContext.setActionServlet(servlet);
+        this.command = new PerformForward();
+    }
+
+    /* tearDown method for test case */
+    protected void tearDown() {
+    }
+
+    public void testNullForwardPath() throws Exception {
+        ForwardConfig config = new ForwardConfig();
+        config.setPath(null);
+        try {
+            command.perform(saContext, config);
+            fail("Didn't throw an illegal argument exception on null forward 
path");
+        } catch (IllegalArgumentException ex) {
+            System.out.println("exception: "+ex.getMessage());
+            // Do nothing, the test passed
+        }
+        
+    }
+
+    /* Executes the test case */
+    public static void main(String[] argv) {
+        String[] testCaseList = {TestPerformForward.class.getName()};
+        junit.textui.TestRunner.main(testCaseList);
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to