|
What this is
Other links
The source code
/*
* Copyright 1999-2004 The Apache Sofware Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.tomcat.util.test;
import java.io.PrintWriter;
import java.util.Hashtable;
import java.util.Vector;
import org.apache.tomcat.util.test.matchers.GoldenMatch;
import org.apache.tomcat.util.test.matchers.HeaderMatch;
import org.apache.tomcat.util.test.matchers.HttpStatusMatch;
import org.apache.tomcat.util.test.matchers.ResponseMatch;
import org.apache.tomcat.util.test.matchers.ResponseMatchFile;
import org.apache.tools.ant.Project;
/** Original tester for a web application. Will send a http request and
verify the response code, compare the response with a golden
file or find strings.
This class is using the well-known ant patterns.
@deprecated Use HttpClient instead. This class has very limited
support for multiple matchers, requests, etc.
*/
public class GTest {
// Defaults
static int defaultDebug=0;
static boolean failureOnly=false;
// all test results will be available
static Hashtable testProperties=new Hashtable();
// Instance variables
Project project=null;
String ifProp=null;
String unlessProp=null;
// The "real" thing.
// GTest is here to support the old ( and simpler ) syntax .
// The real work is done in HttpClient, which is a lot more
// powerfull. For example it can handle multiple requests and
// matches, etc
HttpClient httpClient=new HttpClient();
// Gtest supports only one request.
HttpRequest httpRequest=new HttpRequest();
String failMessage="";
PrintWriter out=null;
String outType=null;
int debug=-1;
boolean result=false;
public GTest() {
httpClient.setDebug( debug );
httpClient.addHttpRequest( httpRequest );
// httpClient.addMatcher( matcher );
}
// -------------------- Defaults --------------------
public static void setDefaultDebug( int d ) {
defaultDebug=d;
}
public static void setDefaultWriter( PrintWriter pw ) {
Report.setDefaultWriter(pw);
}
/** @deprecated. Output will be text or none, with external
formater ( or event ? - it would be nice, but too serious, it's
still a simple test runner )
*/
public static void setDefaultOutput( String s ) {
Report.setDefaultOutput(s);
}
/** Vector of GTest elements, containing all test instances
* that were run.
*/
public static Vector getTestResults() {
return HttpClient.getTestResults();
}
/** Vector of GTest elements, containing all test instances
* that were run and failed.
*/
public static Vector getTestFailures() {
return HttpClient.getTestFailures();
}
/** Vector of GTest elements, containing all test instances
* that were run and failed.
*/
public static Vector getTestSuccess() {
return HttpClient.getTestSuccess();
}
/** Various global test propertis
*/
public static Hashtable getTestProperties() {
return testProperties;
}
public static void resetGTest() {
GTest.getTestResults().setSize(0);
GTest.getTestFailures().setSize(0);
GTest.getTestSuccess().setSize(0);
GTest.getTestProperties().clear();
HttpClient.getHttpClients().clear();
}
// ----------------- Ant Properties -----------------
public void setProject(Project p ) {
project=p;
}
public void setIf(String prop) {
ifProp=prop;
}
public void setUnless(String prop) {
unlessProp=prop;
}
// -------------------- GTest behavior --------------------
public void setWriter( PrintWriter pw ) {
out=pw;
}
/** text, xml, html
*/
public void setOutput( String t ) {
outType=t;
}
/** Report only tests that fail
*/
public void setFailureOnly( String e ) {
failureOnly=Boolean.valueOf(e).booleanValue();
}
// -------------------- Getters --------------------
public HttpClient getHttpClient() {
return httpClient;
}
public String getComment() {
return httpClient.getComment();
}
// -------------------- Local properties --------------------
/** Description should be in
|
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.