package com.bitmechanic.maxq.generator;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import com.bitmechanic.maxq.*;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.StringTokenizer;
import java.util.List;
import java.util.Iterator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Abstract class providing general useful utility methods for code generation.
* @author Robert Dawson robert@rojotek.com
* @author Wayne Hearn wayne_hearn@dell.com
*/
public abstract class AbstractCodeGenerator
implements IScriptGenerator,
ProxyServer.Observer,
Runnable {
private static Log log = LogFactory.getLog(AbstractCodeGenerator.class);
private static String cpRspTo = System.getProperty("http.cpRspTo");
private static boolean cpRspToStdout;
private static boolean cpRspToFile = false;
private static final String MIME_DEFAULTS[] = {
"text/plain",
"text/html",
"text/comma-separated-values" };
private static HashMap mimeTypes;
private IScriptAdapter scriptAdapter;
private String testName;
private String defaultTestName;
private String testPath;
private boolean ignoreNextResponse;
private Pattern[] namePatterns;
private LinkedList outstandingInserts;
private Thread insertThread;
protected long assertNumber = 0;
protected static final String END_STATEMENT = ";" + EOL;
/*
* Routines for our descendents.
*/
/**
* Implementer must add script code for the parameters provided.
* This will only be called if there is at least one parameter.
*
* @param params One or more parameters.
*/
public abstract void doParameterList(Param[] params) throws Utils.UserException;
// Not yet documented.
public abstract void doTestUrlMessage(String url) throws Utils.UserException;
public abstract void doSetData(String data) throws Utils.UserException;
public abstract void doCallUrl(String url,
String method,
String data,
String contentLength) throws Utils.UserException;
public abstract void doAssertResponse(String respCode) throws Utils.UserException;
public abstract void doTidyCode(String url) throws Utils.UserException;
public abstract void doResponseForStdOut(String url) throws Utils.UserException;
public abstract void doResponseForFile() throws Utils.UserException;
/**
* Called after all other calls for a particular transaction (request +
* response).
*/
public abstract void doEndTransaction() throws Utils.UserException;
/** jtidyConfigFile variable serves two purpose:
* one as a flag indicating we need spit out jtidy integration code,
* and as a variable indicating the location of jtidy.cfg file.
*/
protected static String jtidyConfigFile = System.getProperty("jtidy.config");
static {
if (cpRspTo != null) {
if (cpRspTo.toLowerCase().compareTo("stdout") == 0)
cpRspToStdout = true;
else if (cpRspTo.toLowerCase().compareTo("file") == 0)
cpRspToFile = true;
}
mimeTypes = new HashMap();
for (int i = 0; i < MIME_DEFAULTS.length; i++) {
mimeTypes.put(MIME_DEFAULTS[i], MIME_DEFAULTS[i]);
}
}
public static boolean isCpRspToStdout() {
return cpRspToStdout;
}
public static boolean isCpRspToFile() {
return cpRspToFile;
}
/**
* @param nameRegExps A list of regular expressions. Each finds an
* instance of the script's name embedded in the
* script. This class will use the regular expressions
* to keep these names up-to-date when the user saves.
*/
public AbstractCodeGenerator(IScriptAdapter adapter, String[] nameRegExps) {
this.scriptAdapter = adapter;
int i;
namePatterns = new Pattern[nameRegExps.length];
for (i = 0; i < nameRegExps.length; i ++)
namePatterns[i] = Pattern.compile(nameRegExps[i],
Pattern.MULTILINE);
testName = Config.getProperty("test.default_testname", "MaxQTest");
defaultTestName = testName;
// Create a thread to allow multiple inserts to be collated and
// inserted together.
insertThread = new Thread(this);
insertThread.start();
}
/**
* Necessary because the thread started in the constructor will otherwise
* never exit.
*/
public void close() {
insertThread.interrupt();
}
public IScriptAdapter getScriptAdapter() {
return scriptAdapter;
}
/**
* Returns the name of the test.
* Currently the same as the name of the file the test is stored in
* @return testName
*/
public String getTestName() {
return testName;
}
/**
* Sets the name of the test class.
* Defaults to value set in maxq.properties under test.default_testname
* @param testName
*/
public void setTestName(String testName) {
this.testName = testName;
}
public String getDefaultTestName() {
return defaultTestName;
}
public void setDefaultTestName(String defaultTestName) {
this.defaultTestName = defaultTestName;
}
/**
* Returns the file path of the test. Null if test is not previously saved.
* @return
*/
public String getTestPath() {
return testPath;
}
/**
* Sets the file path of the test
* @param testPath
*/
public void setTestPath(String testPath) {
this.testPath = testPath;
}
/**
* Returns the full script from the ScriptAdapter.
*/
protected String getScript() {
return this.scriptAdapter.getText();
}
/**
* Processes the response and generates test events for the code generator implementation class.
* @param header
* @param response
*/
public void processResponse(HttpRequestHeader header, byte[] response)
throws Exception {
if (ignoreNextResponse) {
log.debug("Ignoring response");
ignoreNextResponse = false;
return;
}
String respStr = new String(response).toLowerCase();
String respCode = parseResponseCode(respStr);
String contentType = parseContentType(respStr);
if(contentType != null &&
mimeTypes.get(contentType) != null &&
respCode != null ) {
doAssertResponse(respCode);
if (respCode.startsWith("200")) {
if (contentType.toLowerCase().compareTo("text/html") == 0) {
doTidyCode(HttpTestCase.staticUrlDecode(header.url));
if (cpRspToStdout) {
doResponseForStdOut(HttpTestCase.staticUrlDecode(header.url).trim());
} else if (cpRspToFile) {
doResponseForFile();
}
} //text/html
}// respCode.startsWith("200")
doEndTransaction(); // add in an empty line for readability
} else {
log.debug("Ignoring response because content type is not known: " + contentType);
}
}
private String parseContentType(String response){
String contentType = null;
int pos = response.indexOf("content-type:");
if (pos > -1) {
pos += 14; // okay we found 'content-type:', advance 14 char positions
int end = response.indexOf("\r\n", pos);
int end2 = response.indexOf(";", pos);
if (end2 > -1 && end2 < end) end = end2;
if (end > -1){
contentType = response.substring(pos, end).trim();
没有合适的资源?快使用搜索试试~ 我知道了~
maxq0.98测试工具
共108个文件
html:56个
java:27个
jar:7个
需积分: 15 1 下载量 37 浏览量
2008-10-29
11:45:59
上传
评论
收藏 1.42MB ZIP 举报
温馨提示
maxq-0.98 测 试 工 具不错的 工具
资源详情
资源评论
资源推荐
收起资源包目录
maxq0.98测试工具 (108个子文件)
maxq.bat 1KB
CHANGES 3KB
stylesheet.css 1KB
inherit.gif 57B
index-all.html 102KB
AbstractCodeGenerator.html 40KB
JavaCodeGenerator.html 35KB
JythonCodeGenerator.html 32KB
HttpTestCase.html 31KB
CompactGenerator.html 29KB
SampleGenerator.html 28KB
Config.html 24KB
RunTestDialog.html 22KB
PrefsDialog.html 21KB
Action.html 18KB
HttpRequestHeader.html 18KB
Test.html 16KB
JTextAreaTestScriptAdapter.html 16KB
ProxyServer.html 16KB
DBUtil.html 16KB
IScriptGenerator.html 15KB
Utils.html 14KB
GeneratorFactory.html 14KB
Preferences.html 14KB
RequestProcessor.html 13KB
Main.html 13KB
MainTest.html 13KB
SwingMain.html 12KB
overview-tree.html 12KB
Validator.html 12KB
IScriptAdapter.html 11KB
package-summary.html 11KB
MainTest.html 11KB
package-tree.html 10KB
Main.CommandLineResults.html 10KB
Param.html 10KB
ProxyServer.Observer.html 9KB
ProxyObserver.html 9KB
Utils.UserException.html 9KB
RequestObserver.html 9KB
Utils.SilentException.html 9KB
serialized-form.html 9KB
RequestHandler.html 9KB
Config.ProxySettings.html 8KB
help-doc.html 8KB
package-summary.html 8KB
package-tree.html 7KB
constant-values.html 7KB
package-tree.html 6KB
package-summary.html 5KB
overview-summary.html 5KB
allclasses-frame.html 5KB
deprecated-list.html 5KB
allclasses-noframe.html 4KB
package-frame.html 4KB
package-frame.html 2KB
overview-frame.html 1KB
package-frame.html 913B
index.html 896B
packages.html 665B
jython.jar 703KB
commons-httpclient.jar 217KB
commons-lang.jar 166KB
junit.jar 118KB
maxq.jar 73KB
commons-logging.jar 31KB
commons-cli.jar 29KB
AbstractCodeGenerator.java 19KB
JavaCodeGenerator.java 13KB
RequestHandler.java 11KB
SwingMain.java 10KB
HttpTestCase.java 9KB
Config.java 9KB
HttpRequestHeader.java 8KB
JythonCodeGenerator.java 8KB
Main.java 8KB
Test.java 5KB
GeneratorFactory.java 4KB
DBUtil.java 4KB
CompactGenerator.java 4KB
Utils.java 4KB
RunTestDialog.java 4KB
ProxyServer.java 3KB
Action.java 3KB
IScriptGenerator.java 2KB
SampleGenerator.java 2KB
Validator.java 2KB
PrefsDialog.java 2KB
MainTest.java 2KB
IScriptAdapter.java 1KB
Preferences.java 1004B
JTextAreaTestScriptAdapter.java 985B
MainTest.java 780B
Param.java 205B
LICENSE 3KB
LICENSE-HTTPCLIENT 3KB
LICENSE-JUNIT 123B
LICENSE-JYTHON 6KB
maxq 732B
package-list 78B
共 108 条
- 1
- 2
goodco
- 粉丝: 2
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0