craigmcc 01/04/24 20:12:03
Modified: tester/src/bin tester.xml
tester/web/WEB-INF web.xml
Added: tester/src/tester/org/apache/tester Resources06.java
Log:
[PFD2-3.5] Add unit test for ServletContext.getResourcePaths().
Note that this currently fails when the argument is "/" to retrieve the
top-level directory. It returns things like "//index.html" instead of
"/index.html".
Revision Changes Path
1.34 +17 -0 jakarta-tomcat-4.0/tester/src/bin/tester.xml
Index: tester.xml
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/tester/src/bin/tester.xml,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- tester.xml 2001/04/20 04:37:13 1.33
+++ tester.xml 2001/04/25 03:12:02 1.34
@@ -537,6 +537,23 @@
request="${context.path}/Resources05?mode=class&path=/org/apache/tester/Unpacked05.txt&stringify=true"
outContent="Resources05 PASSED"/>
+ <!-- ========== getResourcePaths() ==================================== -->
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ debug="${debug}"
+ request="${context.path}/Resources06?path=/"
+ outContent="Resources06 PASSED"/>
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ debug="${debug}"
+ request="${context.path}/Resources06?path=/golden"
+ outContent="Resources06 PASSED"/>
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ debug="${debug}"
+ request="${context.path}/Resources06?path=/WEB-INF"
+ outContent="Resources06 PASSED"/>
+
</target>
1.1
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/Resources06.java
Index: Resources06.java
===================================================================
/* ========================================================================= *
* *
* The Apache Software License, Version 1.1 *
* *
* Copyright (c) 1999, 2000, 2001 The Apache Software Foundation. *
* All rights reserved. *
* *
* ========================================================================= *
* *
* Redistribution and use in source and binary forms, with or without modi- *
* fication, are permitted provided that the following conditions are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice *
* notice, this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. The end-user documentation included with the redistribution, if any, *
* must include the following acknowlegement: *
* *
* "This product includes software developed by the Apache Software *
* Foundation <http://www.apache.org/>." *
* *
* Alternately, this acknowlegement may appear in the software itself, if *
* and wherever such third-party acknowlegements normally appear. *
* *
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software *
* Foundation" must not be used to endorse or promote products derived *
* from this software without prior written permission. For written *
* permission, please contact <[EMAIL PROTECTED]>. *
* *
* 5. Products derived from this software may not be called "Apache" nor may *
* "Apache" appear in their names without prior written permission of the *
* Apache Software Foundation. *
* *
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY *
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
* THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY *
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL *
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS *
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, *
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
* ========================================================================= *
* *
* This software consists of voluntary contributions made by many indivi- *
* duals on behalf of the Apache Software Foundation. For more information *
* on the Apache Software Foundation, please see <http://www.apache.org/>. *
* *
* ========================================================================= */
package org.apache.tester;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* Positive test for <code>getResourcePaths()</code>, which will specify the
* directory path indicated by the <strong>path</strong> request parameter.
* For known paths, at least the known set of included resources must be
* found in order to pass.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2001/04/25 03:12:03 $
*/
public class Resources06 extends HttpServlet {
// Resource Lists (incomplete) for known directory paths
String rootPaths[] =
{ "/ErrorPage06.html", "/ErrorPage06.jsp", "/Forward01.txt",
"/Include01.txt", "/WEB-INF/", "/Xerces00.jsp", "/Xerces01.xml",
"/Xerces02.jsp", "/golden/", "/includeme.txt", "/index.shtml",
"/ssidir/" };
String goldenPaths[] =
{ "/golden/Golden01.txt", "/golden/SSIConfig01.txt",
"/golden/SSIConfig03.txt", "/golden/SSIFsize02.txt",
"/golden/SSIInclude01.txt", "/golden/SSIInclude02.txt",
"/golden/Session05.txt" };
String webinfPaths[] =
{ "/WEB-INF/classes/", "/WEB-INF/lib/", "/WEB-INF/web.xml" };
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
// Prepare our output writer
response.setContentType("text/plain");
PrintWriter writer = response.getWriter();
// Identify our configuration parameters
StringBuffer sb = new StringBuffer();
String path = request.getParameter("path");
if (path == null)
path = "/";
String paths[] = null;
if ("/".equals(path))
paths = rootPaths;
else if ("/golden".equals(path))
paths = goldenPaths;
else if ("/WEB-INF".equals(path))
paths = webinfPaths;
else {
sb.append(" Unknown path '");
sb.append(path);
sb.append("'/");
}
int counts[] = null;
if (paths != null)
counts = new int[paths.length];
// Request the set of resources in the specified path
StaticLogger.write("Processing path '" + path + "'");
Set set = getServletContext().getResourcePaths(path);
if (set == null) {
sb.append(" No resources returned/");
set = new HashSet();
}
// Count the occurrences of the resources we know about
Iterator resources = set.iterator();
while (resources.hasNext()) {
String resource = (String) resources.next();
StaticLogger.write("Found resource '" + resource + "'");
for (int i = 0; i < paths.length; i++) {
if (paths[i].equals(resource)) {
counts[i]++;
break;
}
}
}
// Report on any missing or duplicated resources
for (int i = 0; i < paths.length; i++) {
if (counts[i] < 1) {
sb.append(" Missing resource '");
sb.append(paths[i]);
sb.append("'/");
} else if (counts[i] > 2) {
sb.append(" Resource '");
sb.append(paths[i]);
sb.append("' occurred ");
sb.append(counts[i]);
sb.append(" times/");
}
}
// Report any failures we have encountered
if (sb.length() > 0) {
writer.print("Resources06 FAILED -");
writer.println(sb.toString());
} else {
writer.println("Resources06 PASSED");
}
// Add wrapper messages as required
while (true) {
String message = StaticLogger.read();
if (message == null)
break;
writer.println(message);
}
StaticLogger.reset();
}
}
1.24 +20 -0 jakarta-tomcat-4.0/tester/web/WEB-INF/web.xml
Index: web.xml
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/tester/web/WEB-INF/web.xml,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- web.xml 2001/04/18 19:53:12 1.23
+++ web.xml 2001/04/25 03:12:03 1.24
@@ -184,6 +184,11 @@
<filter-mapping>
<filter-name>HttpFilter</filter-name>
+ <url-pattern>/WrappedResources06</url-pattern>
+ </filter-mapping>
+
+ <filter-mapping>
+ <filter-name>HttpFilter</filter-name>
<url-pattern>/WrappedSession01</url-pattern>
</filter-mapping>
@@ -398,6 +403,11 @@
</servlet>
<servlet>
+ <servlet-name>Resources06</servlet-name>
+ <servlet-class>org.apache.tester.Resources06</servlet-class>
+ </servlet>
+
+ <servlet>
<servlet-name>Session01</servlet-name>
<servlet-class>org.apache.tester.Session01</servlet-class>
</servlet>
@@ -738,6 +748,16 @@
<servlet-mapping>
<servlet-name>Resources05</servlet-name>
<url-pattern>/WrappedResources05</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>Resources06</servlet-name>
+ <url-pattern>/Resources06</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>Resources06</servlet-name>
+ <url-pattern>/WrappedResources06</url-pattern>
</servlet-mapping>
<servlet-mapping>