refactor and add tests, and pass it, still have bug and need to debug

This commit is contained in:
coderfengyun 2013-12-19 20:39:35 +08:00
parent e12b603e84
commit 20062f6809
17 changed files with 131 additions and 143 deletions

View File

@ -1,93 +1 @@
<html><!--###PHBoeHBhZ2U+PHRpbWVTdGFtcD4xMC8xMi8yMDEzIDA4OjM3OjQzPC90aW1lU3RhbXA+PHRpbWVUaWxsQ0NCTlJlZnJlc2g+MTgwPC90aW1lVGlsbENDQk5SZWZyZXNoPjwvcGh4cGFnZT4=###--><head><link href="http://phx.corporate-ir.net/HttpCombiner.ashx?s=RisenCSS&amp;v=B94A18012C20431FA6ADC43CFC76EDB2" type="text/css" rel="stylesheet" /><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Baidu | Business Overview</title><script language="JavaScript" src="http://media.corporate-ir.net/media_files/irol/global_js/phoenix.js"></script><link rel="stylesheet" type="text/css" href="client/18/188488/css/ccbnIR.css" /><script type="text/javascript"><!--
var iframeids=["myframe"]
var iframehide="yes"
var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers
function resizeCaller() {
var dyniframe=new Array()
for (i=0; i<iframeids.length; i++){
if (document.getElementById)
resizeIframe(iframeids[i])
//reveal iframe for lower end browsers? (see var above):
if ((document.all || document.getElementById) && iframehide=="no"){
var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
tempobj.style.display="block"
}
}
}
function resizeIframe(frameid){
var currentfr=document.getElementById(frameid)
if (currentfr && !window.opera){
if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight;
else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
currentfr.height = currentfr.Document.body.scrollHeight;
if (currentfr.addEventListener)
currentfr.addEventListener("load", readjustIframe, false)
else if (currentfr.attachEvent){
currentfr.detachEvent("onload", readjustIframe) // Bug fix line
currentfr.attachEvent("onload", readjustIframe)
}
}
}
function readjustIframe(loadevt) {
var crossevt=(window.event)? event : loadevt
var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
if (iframeroot)
resizeIframe(iframeroot.id);
}
function loadintoIframe(url){
if (document.getElementById)
document.getElementById("myframe").src=url
}
if (window.addEventListener)
window.addEventListener("load", resizeCaller, false)
else if (window.attachEvent)
window.attachEvent("onload", resizeCaller)
else
window.onload=resizeCaller
//-->
</script><script language="Javascript"><!--
function emailPage()
{
var loc = top.location;
var to = "";
var subject = top.document.title;
var body = document.location.href;
// BUILD MAIL MESSAGE COMPONENTS
var doc = "mailto:" + to +
"?subject=" + escape(subject) +
"&body=" + escape(body);
// POP UP EMAIL MESSAGE WINDOW
window.location = doc;
}
//-->
</script><script src="http://phx.corporate-ir.net/HttpCombiner.ashx?s=RisenJS&v=B94A18012C20431FA6ADC43CFC76EDB2" type="text/javascript"></script><script type="text/javascript">Phx.AjaxToken = 'b11f528329bbcb978c6263efe73939aa2452db019b4dead38bbb2a9ddfa7cb25';</script><script type="text/javascript">var s_CCSWebHostingAccount = "trcgclientweb2090";</script><script type="text/javascript" src="./WebSideStory/s_code.js"></script></head><body><table width="100%" border="0" cellspacing="0" cellpadding="0" class="BGLogo"><tr><td width="181" height="99" align="center" nowrap="nowrap">?????<a href="http://www.baidu.com"><img src="http://media.corporate-ir.net/media_files/irol/18/188488/images/logo.gif" border="0" align="absmiddle" /></a></td><td align="right" class="Banner" id="ObjBanner">?<script><!--
if (screen.width<= 800) document.getElementById("ObjBanner").style.backgroundImage = "url(http://media.corporate-ir.net/media_files/irol/18/188488/images/banner800.jpg)";//-->
</script></td></tr></table><table width="100%" border="0" cellspacing="0" cellpadding="0" class="BGBar"><tr><td width="225" height="29"></td><td class="DottedLine" style="padding-right:30px;"><div align="right"><span class="ccbnLnk"><a class="ccbnLnk" onclick="emailPage()" href="#"><img border="0" src="http://media.corporate-ir.net/media_files/irol/18/188488/images/icon_email.gif" /></a></span><span class="ccbnLnk"><a class="ccbnLnk" onclick="emailPage()" href="#"> Send????</a></span><span class="ccbnLnk"><a Class="ccbnLnk"Target="_blank" href="phoenix.zhtml?c=188488&p=irol-homeprofile_pf"><img src="http://media.corporate-ir.net/media_files/irol/18/188488/images/icon_print.gif" alt="Printer Friendly Version" border="0" /></a>?</span><span class="ccbnLnk"><a Class="ccbnLnk"Target="_blank" href="phoenix.zhtml?c=188488&p=irol-homeprofile_pf">Print????</a></span><span class="ccbnLnk"><A HREF="phoenix.zhtml?c=188488&p=rssSubscription&t=&id=&" NAME=""Class="ccbnLnk"><img src="http://media.corporate-ir.net/media_files/irol/global_images/toolkit_rss.gif" border="0" alt="RSS" /></A>?</span><span class="ccbnLnk"><A HREF="phoenix.zhtml?c=188488&p=rssSubscription&t=&id=&" NAME=""Class="ccbnLnk">RSS</A></span></div></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td width="225" valign="top"><table width="198" border="0" cellspacing="0" cellpadding="0"><tr><td width="198" class="MTitle">Corporate Information</td></tr></table><table width="198" border="0" cellpadding="0" cellspacing="0" class="MIBoxMargin"><tr><td width="198" class="MItem"><a href="phoenix.zhtml?c=188488&amp;p=irol-homeprofile">Business Overview</a></td></tr><tr><td class="MItem"><a href="phoenix.zhtml?c=188488&amp;p=irol-products">Products</a></td></tr><tr><td class="MItem"><a href="phoenix.zhtml?c=188488&amp;p=irol-govmanage">Management</a></td></tr><tr><td class="MItem"><a href="phoenix.zhtml?c=188488&amp;p=irol-govboard">Board of Directors</a></td></tr><tr><td class="MItem"><a href="phoenix.zhtml?c=188488&amp;p=irol-govhighlights">Corporate Governance</a></td></tr></table><table width="198" border="0" cellspacing="0" cellpadding="0"><tr><td width="198" class="MTitle">Investor Relations</td></tr></table><table width="198" border="0" cellpadding="0" cellspacing="0" class="MIBoxMargin"><tr><td width="198" class="MItem"><a href="phoenix.zhtml?c=188488&amp;p=irol-irhome">Fact Sheet</a></td></tr><tr><td class="MItem"><a href="phoenix.zhtml?c=188488&amp;p=irol-news&amp;nyo=0">Press Releases</a></td></tr><tr><td class="MItem"><a href="phoenix.zhtml?c=188488&amp;p=irol-reportsAnnual">Financial Reports</a></td></tr><tr><td class="MItem"><a href="phoenix.zhtml?c=188488&amp;p=irol-presentations">Webcasts</a></td></tr><tr><td class="MItem"><a href="phoenix.zhtml?c=188488&amp;p=irol-stockquote">Stock Information</a></td></tr><tr><td class="MItem"><a href="phoenix.zhtml?c=188488&amp;p=irol-sec">SEC Filings</a></td></tr><tr><td class="MItem"><a href="phoenix.zhtml?c=188488&amp;p=irol-analysts">Analyst Coverage</a></td></tr><tr><td class="MItem"><a href="phoenix.zhtml?c=188488&amp;p=irol-calendar">IR Calendar</a></td></tr><tr><td class="MItem"><a href="phoenix.zhtml?c=188488&amp;p=irol-faq">Investor FAQs</a></td></tr></table><table width="198" border="0" cellspacing="0" cellpadding="0"><tr><td width="198" class="MTitle">Contact Baidu</td></tr></table><table width="198" border="0" cellpadding="0" cellspacing="0" class="MIBoxMargin"><tr><td width="198" class="MItem"><a href="phoenix.zhtml?c=188488&amp;p=irol-contacts">IR Contacts</a></td></tr><tr><td class="MItem"><a href="phoenix.zhtml?c=188488&amp;p=irol-inforeq">Request Information</a></td></tr><tr><td class="MItem"><a href="phoenix.zhtml?c=188488&amp;p=irol-alerts">Email Alert</a></td></tr></table><table width="198" border="0" cellspacing="0" cellpadding="0"><tr align="center"><td width="198" align="center"><a href="http://www.baidu.com"><img src="http://media.corporate-ir.net/media_files/irol/18/188488/images/back1.gif" alt="back to baidu" width="164" border="0" /></a></td></tr></table></td><td valign="top"><br /><h1>The Baidu Story</h1><br /><br /><span class="ccbnTxt"><p>Our name was inspired by a poem written more than 800 years ago during the Song Dynasty. The poem compares the search for a retreating beauty amid chaotic glamour with the search for one's dream while confronted by life's many obstacles. "…hundreds and thousands of times, for her I searched in chaos, suddenly, I turned by chance, to where the lights were waning, and there she stood." Baidu, whose literal meaning is “hundreds of times”, represents a persistent search for the ideal. <br><br>
Baidu was founded in 2000 by Internet pioneer Robin Li, creator of visionary search technology Hyperlink Analysis, with the mission of providing the best way for people to find what theyre looking for online. Over the past decade we have strived to fulfill this mission by listening carefully to our users needs and wants. To provide intelligent, relevant search results for the tens of billions of queries that are entered into our search platform every day, we focus on powering the best technology optimized for up-to-date local tastes and preferences. Our deep understanding of Chinese language and culture is central to our success and this kind of knowledge allows us to tailor our search technology for our users needs. Just to cite one example, we believe there are at least 38 ways of saying "I" in the Chinese language. It is important that we recognize these nuances to effectively address our users requests.
<br><br>
We provide our users with many channels to find and share information. In addition to our core web search product, we power many popular community-based products, such as Baidu PostBar, the worlds first and largest Chinese-language query-based searchable online community platform, Baidu Knows, the worlds largest Chinese-language interactive knowledge-sharing platform, and Baidu Encyclopedia, the worlds largest user-generated Chinese-language encyclopedia, to name but a few. Beyond these marquee products we also offer dozens of helpful vertical search-based products, such as Maps, Image Search, Video Search, News Search, and many more. We power these through our cutting-edge technology, continually innovating to enhance these services. Our new Box Computing Open Platform brings users deep-linked content and even applications they can use directly through their search box. We believe that Box Computing will dramatically improve peoples search experience and become ubiquitous across all Internet devices including computers and mobile platforms.
<br><br>
In addition to serving individual users, we also serve as a media platform for online marketing customers. Our business model is mainly based on a performance-oriented marketing platform for businesses to cost effectively reach relevant Internet users. We offer performance-based online marketing services and display advertisements through both Baidu organic websites and our affiliated websites (our Union business). Our affiliated websites lead traffic to us through integrating a Baidu search box into their sites and/or by displaying relevant contextual promotional links for our customers. The majority of our revenue is derived from performance-based online marketing services and our customers pay on a cost per click basis that is, our customers only pay when their paid-link is clicked through and they get the “lead”. Our goal is to give our customers an online marketing platform that has a wide range of functions which they can use to meet their marketing needs and an extensive selection of tools for managing their accounts as well as data for analyzing and optimizing ROI.
<br><br>
To best serve our customers, our sales efforts consist of direct sales teams in first tier cities and third-party distributors in lower tier cities. This allows us to better penetrate each market and tailor our support and personal interaction based on customers needs. Today, our online marketing platform serves hundreds of thousands of small- and medium-sized enterprises (SMEs) and many branded multinational customers. The measurable ROI offered by our online marketing platform has made it one of the most effective marketing platforms for companies targeting the Chinese market. We will continue to strive to provide an extra level of value-added sales and customer service to address a wide range of customer needs. Our focus is to help the market continue to develop and educate the many companies who dont understand the benefits of search engine marketing so that we can help them grow their businesses.
<br><br>
You dont need us to tell you that Chinas Internet space is booming. With the worlds largest Internet user population 564 million as of end of 2012 and a long way to go to reach internet penetration levels of developed countries, Chinas internet is growing in both influence and sophistication. And as more and more Chinese come online, Baidu continues to innovate to meet their increasingly diverse tastes. With our goal of best serving the needs of our users and customers with intelligent and relevant solutions, we look forward to a robust future. </p>
</span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td><img src="http://media.corporate-ir.net/media_files/irol/global_images/spacer.gif" width="10" height="50" /></td></tr></table><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td height="27" align="center" style="border-top:1px solid #D6D6D6; font-family:Arial; font-size:12px;">Copyright ? <script language="JavaScript">
var year="";
mydate=new Date();
myyear= mydate.getYear();
year=(myyear > 200) ? myyear : 1900 + myyear;
document.write(year);
</script> Baidu, Inc. All Rights Reserved.</td></tr></table></body></html
<html><body></body></html

View File

@ -0,0 +1,16 @@
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/7.0
CachedXSLT: true
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Vary: Accept-Encoding
Cache-Control: private, max-age=31
Date: Tue, 10 Dec 2013 08:40:29 GMT
Content-Length: 26
Connection: keep-alive
Set-Cookie: agentscape-tag-devtype=desktop; Path=/
Set-Cookie: agentscape-proc=noop; Path=/
x-agentscape-info: c=1.0-r9869; v=3; fp=f844b0e65e9b5458; ts=1333395837
<html><body></body></html>

View File

@ -0,0 +1,16 @@
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Server: Microsoft-IIS/7.0
CachedXSLT: true
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Vary: Accept-Encoding
Cache-Control: private, max-age=31
Date: Tue, 10 Dec 2013 08:40:29 GMT
Content-Length: 6
Connection: keep-alive
Set-Cookie: agentscape-tag-devtype=desktop; Path=/
Set-Cookie: agentscape-proc=noop; Path=/
x-agentscape-info: c=1.0-r9869; v=3; fp=f844b0e65e9b5458; ts=1333395837
adnddm

View File

@ -3,13 +3,12 @@ package org.bench4q.master.helper;
import java.util.ArrayList;
import java.util.List;
import org.bench4q.master.model.Page;
import org.bench4q.master.model.RunScenarioModelNew;
import org.bench4q.share.models.agent.ParameterModel;
import org.bench4q.share.models.agent.scriptrecord.BatchBehavior;
import org.bench4q.share.models.agent.scriptrecord.UserBehaviorModel;
import ModelTest.Page;
import ModelTest.RunScenarioModelNew;
public class RunScenarioModelHelper {
public static List<BatchBehavior> getBatches(
RunScenarioModelNew runScenarioModelNew) {

View File

@ -1,4 +1,4 @@
package ModelTest;
package org.bench4q.master.model;
import java.util.ArrayList;
import java.util.List;

View File

@ -1,4 +1,4 @@
package ModelTest;
package org.bench4q.master.model;
import java.util.ArrayList;
import java.util.List;

View File

@ -11,6 +11,8 @@ import javax.xml.bind.Marshaller;
import org.apache.log4j.Logger;
import org.bench4q.master.exception.ExceptionLog;
import org.bench4q.master.helper.RunScenarioModelHelper;
import org.bench4q.master.model.Page;
import org.bench4q.master.model.RunScenarioModelNew;
import org.bench4q.master.scriptrecord.httpcapture.generator.ChildrenUrl;
import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.agent.ParameterModel;
@ -18,9 +20,6 @@ import org.bench4q.share.models.agent.scriptrecord.BatchBehavior;
import org.bench4q.share.models.agent.scriptrecord.BehaviorBaseModel;
import org.bench4q.share.models.agent.scriptrecord.UsePluginModel;
import ModelTest.Page;
import ModelTest.RunScenarioModelNew;
public class Bench4qTestScriptAdapter implements IScriptAdapter {
private int pageCount;
private RunScenarioModelNew runScenarioModel;
@ -101,7 +100,10 @@ public class Bench4qTestScriptAdapter implements IScriptAdapter {
private Page getCurrentPage() {
if (!pageCountEqualWithPageSizeInScenario()) {
logger.error("The page count is not equal with the size of scenario pages");
logger.error("The page count is not equal with the size of scenario pages, and the page count is"
+ this.getPageCount()
+ " , and pageSize is "
+ this.getRunScenarioModel().getPages().size());
return new Page();
}
return this.getRunScenarioModel().getPages()
@ -199,7 +201,7 @@ public class Bench4qTestScriptAdapter implements IScriptAdapter {
public void setText(String text) {
if (text == null || text.isEmpty()) {
this.setRunScenarioModel(new RunScenarioModelNew());
// this.setRunScenarioModel(new RunScenarioModelNew());
return;
}
try {

View File

@ -8,7 +8,7 @@ import java.util.concurrent.Executors;
import javax.swing.JTextArea;
import org.apache.log4j.Logger;
import ModelTest.RunScenarioModelNew;
import org.bench4q.master.model.RunScenarioModelNew;
public class HttpCapture {
private int localport;

View File

@ -66,24 +66,25 @@ public class HttpRequestHeader {
this.method = this.httpRequest.getRequestLine().getMethod();
this.version = this.httpRequest.getRequestLine()
.getProtocolVersion().toString();
this.accept = this.httpRequest.getFirstHeader(
HeaderValue.REQUEST_ACCEPT).getValue();
this.referer = this.httpRequest.getFirstHeader(
HeaderValue.REQUEST_REFERER).getValue();
this.userAgent = this.httpRequest.getFirstHeader(
HeaderValue.REQUEST_USER_AGENT).getValue();
this.ifModifiedSince = this.httpRequest.getFirstHeader(
"if-modified-since").getValue();
this.authorization = this.httpRequest.getFirstHeader(
HeaderValue.REQUEST_AUTHORIZATION).getValue();
this.contentType = this.httpRequest.getFirstHeader(
HeaderValue.ENTITY_CONTENT_TYPE).getValue();
this.pragmaNoCache = this.httpRequest
.getFirstHeader(HeaderValue.GENERAL_PRAGMA).getValue()
this.accept = this.getHeaderValue(HeaderValue.REQUEST_ACCEPT);
this.referer = this.getHeaderValue(HeaderValue.REQUEST_REFERER);
this.userAgent = this
.getHeaderValue(HeaderValue.REQUEST_USER_AGENT);
this.ifModifiedSince = this.getHeaderValue("if-modified-since");
this.authorization = this
.getHeaderValue(HeaderValue.REQUEST_AUTHORIZATION);
this.contentType = this
.getHeaderValue(HeaderValue.ENTITY_CONTENT_TYPE);
this.pragmaNoCache = this
.getHeaderValue(HeaderValue.GENERAL_PRAGMA)
.equalsIgnoreCase("NO-CACHE");
this.contentLength = Integer.parseInt(this.httpRequest
.getFirstHeader(HeaderValue.ENTITY_CONTENT_LENGHT)
.getValue());
if (this.getHttpRequest().containsHeader(
HeaderValue.ENTITY_CONTENT_LENGHT)) {
this.contentLength = Integer.parseInt(this.httpRequest
.getFirstHeader(HeaderValue.ENTITY_CONTENT_LENGHT)
.getValue());
}
} catch (IOException e) {
throw e;
} catch (HttpException e) {
@ -101,11 +102,11 @@ public class HttpRequestHeader {
*
* @param name
* @return if contains this header return the header's value; if not return
* null
* ""
*/
public String getHeaderValue(String name) {
if (this.containsHeader(name)) {
return null;
if (!this.containsHeader(name)) {
return "";
}
return this.getHttpRequest().getFirstHeader(name).getValue();
}

View File

@ -2,12 +2,11 @@ package org.bench4q.master.scriptrecord.httpcapture;
import java.util.List;
import org.bench4q.master.model.RunScenarioModelNew;
import org.bench4q.master.scriptrecord.httpcapture.generator.ChildrenUrl;
import org.bench4q.share.models.agent.scriptrecord.BehaviorBaseModel;
import org.bench4q.share.models.agent.scriptrecord.UsePluginModel;
import ModelTest.RunScenarioModelNew;
public interface IScriptAdapter {
public abstract RunScenarioModelNew getRunScenarioModel();

View File

@ -19,6 +19,7 @@ import javax.xml.bind.Marshaller;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.bench4q.master.model.RunScenarioModelNew;
import org.bench4q.master.scriptrecord.httpcapture.Action;
import org.bench4q.master.scriptrecord.httpcapture.Config;
import org.bench4q.master.scriptrecord.httpcapture.HeaderValue;
@ -31,8 +32,6 @@ import org.bench4q.master.scriptrecord.httpcapture.Utils;
import org.bench4q.master.scriptrecord.httpcapture.Utils.UserException;
import org.bench4q.share.models.agent.scriptrecord.BehaviorBaseModel;
import ModelTest.RunScenarioModelNew;
public abstract class AbstractCodeGenerator implements IScriptGenerator,
ProxyServer.Observer, Runnable {
private Config config = Config.getConfig();
@ -341,6 +340,12 @@ public abstract class AbstractCodeGenerator implements IScriptGenerator,
if (responseHeader.isGoodRequest()
&& responseHeader.isHtmlContent()) {
dealWithHtmlResponse(header, responseParser);
doParseRequest(header, requestBody);
doParseHtmlContent(responseParser.getResponseBody(), header.url);
setStruts(new String(response).toLowerCase().indexOf(
"org.apache.struts.taglib.html.token") > 0);
doEndTransaction();
return;
}
setStruts(new String(response).toLowerCase().indexOf(
"org.apache.struts.taglib.html.token") > 0);
@ -360,7 +365,6 @@ public abstract class AbstractCodeGenerator implements IScriptGenerator,
this.getScriptAdapter().resetChildrenUrls();
this.setFirstHtmlResponse(false);
doTidyCode(HttpTestCase.staticUrlDecode(header.url));
doParseHtmlContent(responseParser.getResponseBody(), header.url);
copyResponseToSpecificOut(header.url);
}

View File

@ -31,6 +31,8 @@ public class ContentDecoder {
while ((len = inputStream.read(buf)) > 0) {
outputStream.write(buf, 0, len);
}
System.out.println(outputStream.toString());
System.out.println("ouputStream's size is" + outputStream.size());
return outputStream.toByteArray();
} catch (Exception e) {
logger.error(ExceptionLog.getExceptionStackTrace(e));

View File

@ -17,7 +17,7 @@ import org.bench4q.share.models.master.ScriptModel;
import org.junit.Test;
public class RecordScriptControllerTest extends TestBase {
private static final int RECORD_TIME = 60000;
private static final int RECORD_TIME = 600000;
private final String SCRIPT_URL = TestBase.BASE_URL + "/RecordScript";
public OperateScriptServerResponseModel startRecord() throws IOException,

View File

@ -6,12 +6,11 @@ import java.util.ArrayList;
import java.util.List;
import org.bench4q.master.helper.RunScenarioModelHelper;
import org.bench4q.master.model.RunScenarioModelNew;
import org.bench4q.master.scriptrecord.httpcapture.Bench4qTestScriptAdapter;
import org.bench4q.share.models.agent.ParameterModel;
import org.junit.Test;
import ModelTest.RunScenarioModelNew;
public class TestBench4qTestScriptAdapter {
private Bench4qTestScriptAdapter bench4qTestScriptAdapter;

View File

@ -5,11 +5,13 @@ import static org.junit.Assert.*;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.zip.GZIPInputStream;
import org.apache.commons.io.FileUtils;
import org.bench4q.master.model.RunScenarioModelNew;
import org.bench4q.master.scriptrecord.httpcapture.Bench4qTestScriptAdapter;
import org.bench4q.master.scriptrecord.httpcapture.HttpRequestHeader;
import org.bench4q.master.scriptrecord.httpcapture.generator.Bench4qCodeGenerator;
@ -18,8 +20,6 @@ import org.bench4q.master.scriptrecord.httpcapture.generator.IScriptGenerator;
import org.bench4q.master.scriptrecord.httpcapture.generator.ResponseParser;
import org.junit.Test;
import ModelTest.RunScenarioModelNew;
public class TestCodeGenerator extends TestRecordBase {
private Bench4qTestScriptAdapter scriptAdapter = new Bench4qTestScriptAdapter(
new RunScenarioModelNew());
@ -27,27 +27,70 @@ public class TestCodeGenerator extends TestRecordBase {
this.scriptAdapter);
public static String dealWithSerie = "RecordScriptTestCase/gzip/gzipBaiduIR";
@Test
public void testProcessResponseOnceWithHtmlResponseButHaveNoBody()
throws Exception, IOException, FileNotFoundException {
IScriptGenerator scriptGenerator = this.codeGenerator;
scriptGenerator.processResponse(
makeAHeader("www.makeup.com"),
new byte[0],
FileUtils.readFileToByteArray(new File(dealWithSerie
+ "BlankBody.html")));
assertEquals(0, this.scriptAdapter.getChildrenUrls().size());
}
@Test
public void testProcessResponseWithOneHtmlResponseHaveBody()
throws Exception {
HttpRequestHeader header = new HttpRequestHeader(new FileInputStream(
new File(dealWithSerie + "Request.txt")));
header.url = "ir.baidu.com";
// this.scriptAdapter
// .insertUserBehaviorsToScenario(createUserBehaviorModel(header.url));
HttpRequestHeader header = makeAHeader("ir.baidu.com");
IScriptGenerator scriptGenerator = this.codeGenerator;
scriptGenerator.processResponse(
header,
new byte[0],
FileUtils.readFileToByteArray(new File(dealWithSerie
+ "Response.txt")));
assertTrue(this.scriptAdapter.getChildrenUrls().size() > 0);
assertEquals(11, this.scriptAdapter.getChildrenUrls().size());
}
private HttpRequestHeader makeAHeader(String url) throws IOException,
FileNotFoundException {
HttpRequestHeader header = new HttpRequestHeader(new FileInputStream(
new File(dealWithSerie + "Request.txt")));
header.url = url;
return header;
}
@Test
public void testProcessResponseTwiceWithTwoHtmlResponseButTheSecondHaveNoBody()
throws Exception {
testProcessResponseWithOneHtmlResponseHaveBody();
testProcessResponseOnceWithHtmlResponseButHaveNoBody();
assertEquals(0, this.scriptAdapter.getChildrenUrls().size());
}
@Test
public void testProcessResponseTwiceWithTwoHtmlResponseOneHtmlSecondNot()
throws Exception {
testProcessResponseWithOneHtmlResponseHaveBody();
testProcessResponseWithNotHtmlResponse();
assertEquals(11, this.scriptAdapter.getChildrenUrls().size());
}
@Test
public void testProcessResponseWithTwoHtmlResponseFirstNoBodySecondHave()
throws FileNotFoundException, IOException, Exception {
testProcessResponseOnceWithHtmlResponseButHaveNoBody();
testProcessResponseWithOneHtmlResponseHaveBody();
}
private void testProcessResponseWithNotHtmlResponse() throws Exception,
IOException, FileNotFoundException {
IScriptGenerator scriptGenerator = this.codeGenerator;
scriptGenerator.processResponse(
makeAHeader("www.makeup2.com"),
new byte[0],
FileUtils.readFileToByteArray(new File(dealWithSerie
+ "NotHtmlResponse.html")));
}
@Test

View File

@ -6,6 +6,7 @@ import java.util.ArrayList;
import java.util.List;
import org.bench4q.master.helper.RunScenarioModelHelper;
import org.bench4q.master.model.RunScenarioModelNew;
import org.bench4q.master.scriptrecord.httpcapture.Bench4qTestScriptAdapter;
import org.bench4q.master.scriptrecord.httpcapture.IScriptAdapter;
import org.bench4q.master.scriptrecord.httpcapture.generator.ChildrenUrl;
@ -14,8 +15,6 @@ import org.bench4q.share.models.agent.scriptrecord.BatchBehavior;
import org.bench4q.share.models.agent.scriptrecord.UserBehaviorModel;
import org.junit.Test;
import ModelTest.RunScenarioModelNew;
public class TestParentRequest {
private IScriptAdapter adapater;
private static String parentUrl = "www.apache.com";

View File

@ -3,12 +3,12 @@ package org.bench4q.master.test.recordscript;
import java.util.ArrayList;
import java.util.List;
import org.bench4q.master.model.RunScenarioModelNew;
import org.bench4q.master.scriptrecord.httpcapture.Bench4qTestScriptAdapter;
import org.bench4q.master.scriptrecord.httpcapture.IScriptAdapter;
import org.bench4q.master.scriptrecord.httpcapture.generator.Bench4qCodeGenerator;
import org.bench4q.share.models.agent.ParameterModel;
import org.bench4q.share.models.agent.scriptrecord.UserBehaviorModel;
import ModelTest.RunScenarioModelNew;
public abstract class TestRecordBase {
private IScriptAdapter adapter;