craigmcc 01/01/02 21:50:46
Modified: tester/src/bin tester.xml
tester/src/tester/org/apache/tester TestClient.java
tester/web/WEB-INF web.xml
Added: tester/src/tester/org/apache/tester SetLocale01.java
Log:
Refactor TestClient so that common validation logic is shared. Also, add
the missing logic to validate the output headers.
Add a positive test for ServletResponse.setLocale() since the current
Watchdog 4.0 version of this test is broken.
Revision Changes Path
1.6 +11 -1 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- tester.xml 2001/01/03 02:46:07 1.5
+++ tester.xml 2001/01/03 05:50:45 1.6
@@ -188,9 +188,19 @@
request="${context.path}/SetBufferSize01"
outContent="SetBufferSize01 PASSED"/>
- <tester host="${host}" port="${port}" protocol="${protocol}"
+ <tester host="${host}" port="${port}" protocol="${protocol}" debug="0"
request="${context.path}/WrappedSetBufferSize01"
outContent="SetBufferSize01 PASSED"/>
+
+ <tester host="${host}" port="${port}" protocol="${protocol}" debug="0"
+ request="${context.path}/SetLocale01"
+ outContent="SetLocale01 PASSED"
+ outHeaders="Content-Language:en"/>
+
+ <tester host="${host}" port="${port}" protocol="${protocol}" debug="0"
+ request="${context.path}/WrappedSetLocale01"
+ outContent="SetLocale01 PASSED"
+ outHeaders="Content-Language:en"/>
</target>
1.4 +188 -35
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/TestClient.java
Index: TestClient.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/TestClient.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TestClient.java 2000/12/26 18:57:44 1.3
+++ TestClient.java 2001/01/03 05:50:45 1.4
@@ -67,6 +67,9 @@
import java.net.HttpURLConnection;
import java.net.Socket;
import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
@@ -112,12 +115,23 @@
* </ul>
*
* @author Craig R. McClanahan
- * @version $Revision: 1.3 $ $Date: 2000/12/26 18:57:44 $
+ * @version $Revision: 1.4 $ $Date: 2001/01/03 05:50:45 $
*/
public class TestClient extends Task {
+ // ----------------------------------------------------- Instance Variables
+
+
+ /**
+ * The saved headers we received in our response. The key is the header
+ * name (converted to lower case), and the value is an ArrayList of the
+ * string value(s) received for that header.
+ */
+ protected HashMap saveHeaders = new HashMap();
+
+
// ------------------------------------------------------------- Properties
@@ -304,6 +318,7 @@
*/
public void execute() throws BuildException {
+ saveHeaders.clear();
if ((protocol == null) || (protocol.length() == 0))
executeHttp();
else
@@ -400,36 +415,45 @@
}
// Dump out the response stuff
- if (debug >= 1) {
+ if (debug >= 1)
System.out.println("RESP: " + conn.getResponseCode() + " " +
conn.getResponseMessage());
- for (int i = 0; i < 1000; i++) {
- String name = conn.getHeaderFieldKey(i);
- String value = conn.getHeaderField(i);
- if ((name == null) || (value == null))
- break;
+ for (int i = 1; i < 1000; i++) {
+ String name = conn.getHeaderFieldKey(i);
+ String value = conn.getHeaderField(i);
+ if ((name == null) || (value == null))
+ break;
+ if (debug >= 1)
System.out.println("HEAD: " + name + ": " + value);
- }
+ save(name, value);
+ }
+ if (debug >= 1) {
System.out.println("DATA: " + outData);
if (outText.length() > 2)
System.out.println("TEXT: " + outText);
}
// Validate the response against our criteria
- if (status != conn.getResponseCode()) {
- success = false;
- result = "Expected status=" + status + ", got status=" +
- conn.getResponseCode();
- } else if ((message != null) &&
- !message.equals(conn.getResponseMessage())) {
- success = false;
- result = "Expected message='" + message + "', got message='" +
- conn.getResponseMessage() + "'";
- } else if ((outContent != null) &&
- !outData.startsWith(outContent)) {
- success = false;
- result = outData;
+ if (success) {
+ result = validateStatus(conn.getResponseCode());
+ if (result != null)
+ success = false;
+ }
+ if (success) {
+ result = validateMessage(conn.getResponseMessage());
+ if (result != null)
+ success = false;
+ }
+ if (success) {
+ result = validateData(outData);
+ if (result != null)
+ success = false;
}
+ if (success) {
+ result = validateHeaders();
+ if (result != null)
+ success = false;
+ }
} catch (Throwable t) {
if (t instanceof FileNotFoundException) {
@@ -594,7 +618,7 @@
if (debug >= 1)
System.out.println("HEAD: " + headerName + ": " +
headerValue);
- ; // FIXME - record them?
+ save(headerName, headerValue);
}
}
@@ -623,20 +647,26 @@
}
// Validate the response against our criteria
- if (status != outStatus) {
- success = false;
- result = "Expected status=" + status + ", got status=" +
- outStatus;
- } else if ((message != null) &&
- !message.equals(outMessage)) {
- success = false;
- result = "Expected message='" + message + "', got message='" +
- outMessage + "'";
- } else if ((outContent != null) &&
- !outData.startsWith(outContent)) {
- success = false;
- result = outData;
+ if (success) {
+ result = validateStatus(status);
+ if (result != null)
+ success = false;
}
+ if (success) {
+ result = validateMessage(message);
+ if (result != null)
+ success = false;
+ }
+ if (success) {
+ result = validateData(outData);
+ if (result != null)
+ success = false;
+ }
+ if (success) {
+ result = validateHeaders();
+ if (result != null)
+ success = false;
+ }
} catch (Throwable t) {
success = false;
@@ -714,6 +744,129 @@
result.append(c);
}
return (result.toString());
+
+ }
+
+
+ /**
+ * Save the specified header name and value in our collection.
+ *
+ * @param name Header name to save
+ * @param value Header value to save
+ */
+ protected void save(String name, String value) {
+
+ String key = name.toLowerCase();
+ ArrayList list = (ArrayList) saveHeaders.get(key);
+ if (list == null) {
+ list = new ArrayList();
+ saveHeaders.put(key, list);
+ }
+ list.add(value);
+
+ }
+
+
+ /**
+ * Validate the output data against what we expected. Return
+ * <code>null</code> for no problems, or an error message.
+ *
+ * @param data The output data to be tested
+ */
+ protected String validateData(String data) {
+
+ if (outContent == null)
+ return (null);
+ else if (data.startsWith(outContent))
+ return (null);
+ else
+ return ("Expected data '" + outContent + "', got data '" +
+ data + "'");
+
+ }
+
+
+ /**
+ * Validate the saved headers against the <code>outHeaders</code>
+ * property, and return an error message if there is anything missing.
+ * If all of the expected headers are present, return <code>null</code>.
+ */
+ protected String validateHeaders() {
+
+ // Do we have any headers to check for?
+ if (outHeaders == null)
+ return (null);
+
+ // Check each specified name:value combination
+ String headers = outHeaders;
+ while (headers.length() > 0) {
+ // Parse the next name:value combination
+ int delimiter = headers.indexOf("##");
+ String header = null;
+ if (delimiter < 0) {
+ header = headers;
+ headers = "";
+ } else {
+ header = headers.substring(0, delimiter);
+ headers = headers.substring(delimiter + 2);
+ }
+ int colon = header.indexOf(":");
+ String name = header.substring(0, colon).trim();
+ String value = header.substring(colon + 1).trim();
+ // Check for the occurrence of this header
+ ArrayList list = (ArrayList) saveHeaders.get(name.toLowerCase());
+ if (list == null)
+ return ("Missing header name '" + name + "'");
+ boolean found = false;
+ for (int i = 0; i < list.size(); i++) {
+ if (value.equals((String) list.get(i))) {
+ found = true;
+ break;
+ }
+ }
+ if (!found)
+ return ("Missing header name '" + name + "' with value '" +
+ value + "'");
+ }
+
+ // Everything was found successfully
+ return (null);
+
+ }
+
+
+ /**
+ * Validate the returned response message against what we expected.
+ * Return <code>null</code> for no problems, or an error message.
+ *
+ * @param message The returned response message
+ */
+ protected String validateMessage(String message) {
+
+ if (this.message == null)
+ return (null);
+ else if (this.message.equals(message))
+ return (null);
+ else
+ return ("Expected message='" + this.message + "', got message='" +
+ message + "'");
+
+ }
+
+
+ /**
+ * Validate the returned status code against what we expected. Return
+ * <code>null</code> for no problems, or an error message.
+ *
+ * @param status The returned status code
+ */
+ protected String validateStatus(int status) {
+
+ if (this.status == status)
+ return (null);
+ else
+ return ("Expected status=" + this.status + ", got status=" +
+ status);
}
1.1
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/SetLocale01.java
Index: SetLocale01.java
===================================================================
/* ========================================================================= *
* *
* The Apache Software License, Version 1.1 *
* *
* Copyright (c) 1999, 2000 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.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* Positive test for ServletResponse.setLocale().
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2001/01/03 05:50:45 $
*/
public class SetLocale01 extends GenericServlet {
// --------------------------------------------------------- Public Methods
/**
* Process a servlet request and create the corresponding response.
*
* @param request The request we are processing
* @param response The response we are creating
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet error occurs
*/
public void service(ServletRequest request, ServletResponse response)
throws IOException, ServletException {
response.setContentType("text/plain");
response.setLocale(new Locale("en", "US"));
PrintWriter writer = response.getWriter();
writer.println("SetLocale01 PASSED");
while (true) {
String message = StaticLogger.read();
if (message == null)
break;
writer.println(message);
}
StaticLogger.reset();
}
}
1.5 +22 -2 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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- web.xml 2001/01/03 02:46:07 1.4
+++ web.xml 2001/01/03 05:50:46 1.5
@@ -61,6 +61,11 @@
</filter-mapping>
<filter-mapping>
+ <filter-name>HttpFilter</filter-name>
+ <url-pattern>/WrappedGetQueryString01</url-pattern>
+ </filter-mapping>
+
+ <filter-mapping>
<filter-name>GenericFilter</filter-name>
<url-pattern>/WrappedReset01</url-pattern>
</filter-mapping>
@@ -71,8 +76,8 @@
</filter-mapping>
<filter-mapping>
- <filter-name>HttpFilter</filter-name>
- <url-pattern>/WrappedGetQueryString01</url-pattern>
+ <filter-name>GenericFilter</filter-name>
+ <url-pattern>/WrappedSetLocale01</url-pattern>
</filter-mapping>
@@ -123,6 +128,11 @@
<servlet-class>org.apache.tester.SetBufferSize01</servlet-class>
</servlet>
+ <servlet>
+ <servlet-name>SetLocale01</servlet-name>
+ <servlet-class>org.apache.tester.SetLocale01</servlet-class>
+ </servlet>
+
<!-- ========== Servlet Mappings ====================================== -->
<servlet-mapping>
@@ -208,6 +218,16 @@
<servlet-mapping>
<servlet-name>SetBufferSize01</servlet-name>
<url-pattern>/WrappedSetBufferSize01</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>SetLocale01</servlet-name>
+ <url-pattern>/SetLocale01</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>SetLocale01</servlet-name>
+ <url-pattern>/WrappedSetLocale01</url-pattern>
</servlet-mapping>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]