Author: craigmcc Date: Tue Aug 2 22:03:33 2005 New Revision: 227161 URL: http://svn.apache.org/viewcvs?rev=227161&view=rev Log: Make it possible for a test case to define the "document root" directory to MockServletContext, so that getRealPath() calls can be resolved correctly. Also, add warnings about calling the superclass setUp() and tearDown() methods in order to acquire functionality provided by the base classes.
Inspired by user@struts.apache.org mail from David Thielen <david AT windward.net>. Modified: struts/shale/trunk/test-framework/src/java/org/apache/shale/test/base/AbstractJsfTestCase.java struts/shale/trunk/test-framework/src/java/org/apache/shale/test/base/AbstractViewControllerTestCase.java struts/shale/trunk/test-framework/src/java/org/apache/shale/test/mock/MockServletContext.java Modified: struts/shale/trunk/test-framework/src/java/org/apache/shale/test/base/AbstractJsfTestCase.java URL: http://svn.apache.org/viewcvs/struts/shale/trunk/test-framework/src/java/org/apache/shale/test/base/AbstractJsfTestCase.java?rev=227161&r1=227160&r2=227161&view=diff ============================================================================== --- struts/shale/trunk/test-framework/src/java/org/apache/shale/test/base/AbstractJsfTestCase.java (original) +++ struts/shale/trunk/test-framework/src/java/org/apache/shale/test/base/AbstractJsfTestCase.java Tue Aug 2 22:03:33 2005 @@ -75,6 +75,12 @@ * <code>RenderKit</code> instances. The created <code>FacesContext</code> * instance will also have been registered in the apppriate thread local * variable, to simulate what a servlet container would do.</p> + * + * <p><strong>WARNING</strong> - If you choose to subclass this class, be sure + * your <code>setUp()</code> and <code>tearDown()</code> methods call + * <code>super.setUp()</code> and <code>super.tearDown()</code> respectively, + * and that you implement your own <code>suite()</code> method that exposes + * the test methods for your test case.</p> */ public abstract class AbstractJsfTestCase extends TestCase { Modified: struts/shale/trunk/test-framework/src/java/org/apache/shale/test/base/AbstractViewControllerTestCase.java URL: http://svn.apache.org/viewcvs/struts/shale/trunk/test-framework/src/java/org/apache/shale/test/base/AbstractViewControllerTestCase.java?rev=227161&r1=227160&r2=227161&view=diff ============================================================================== --- struts/shale/trunk/test-framework/src/java/org/apache/shale/test/base/AbstractViewControllerTestCase.java (original) +++ struts/shale/trunk/test-framework/src/java/org/apache/shale/test/base/AbstractViewControllerTestCase.java Tue Aug 2 22:03:33 2005 @@ -22,7 +22,11 @@ * <p>Abstract base class for testing <code>ViewController</code> * implementations.</p> * - * $Id$ + * <p><strong>WARNING</strong> - If you choose to subclass this class, be sure + * your <code>setUp()</code> and <code>tearDown()</code> methods call + * <code>super.setUp()</code> and <code>super.tearDown()</code> respectively, + * and that you implement your own <code>suite()</code> method that exposes + * the test methods for your test case.</p> */ public abstract class AbstractViewControllerTestCase extends AbstractJsfTestCase { Modified: struts/shale/trunk/test-framework/src/java/org/apache/shale/test/mock/MockServletContext.java URL: http://svn.apache.org/viewcvs/struts/shale/trunk/test-framework/src/java/org/apache/shale/test/mock/MockServletContext.java?rev=227161&r1=227160&r2=227161&view=diff ============================================================================== --- struts/shale/trunk/test-framework/src/java/org/apache/shale/test/mock/MockServletContext.java (original) +++ struts/shale/trunk/test-framework/src/java/org/apache/shale/test/mock/MockServletContext.java Tue Aug 2 22:03:33 2005 @@ -16,6 +16,7 @@ package org.apache.shale.test.mock; +import java.io.File; import java.io.InputStream; import java.io.IOException; import java.net.MalformedURLException; @@ -42,15 +43,32 @@ // ----------------------------------------------------- Mock Object Methods + /** + * <p>Add a context initialization parameter to the set of + * parameters recognized by this instance.</p> + */ public void addInitParameter(String name, String value) { parameters.put(name, value); } + /** + * <p>Set the document root for <code>getRealPath()</code> + * resolution. This parameter <strong>MUST</strong> represent + * a directory.</p> + * + * @param documentRoot The new base directory + */ + public void setDocumentRoot(File documentRoot) { + this.documentRoot = documentRoot; + } + + // ------------------------------------------------------ Instance Variables private Hashtable attributes = new Hashtable(); + private File documentRoot = null; private Hashtable parameters = new Hashtable(); @@ -122,7 +140,20 @@ public String getRealPath(String path) { - throw new UnsupportedOperationException(); + if (documentRoot != null) { + if (!path.startsWith("/")) { + throw new IllegalArgumentException("The specified path ('" + + path + "') does not start with a '/' character"); + } + File resolved = new File(documentRoot, path.substring(1)); + try { + return resolved.getCanonicalPath(); + } catch (IOException e) { + return resolved.getAbsolutePath(); + } + } else { + return null; + } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]