From d6fc35085c6c0e69aed6fd97bf2aa77163b6f926 Mon Sep 17 00:00:00 2001 From: coderfengyun Date: Fri, 21 Feb 2014 16:15:26 +0800 Subject: [PATCH] build Monitor into TestPlanDB --- RecordScriptTestCase/baidu.html | 3771 +---------------- .../master/api/TestPlanController.java | 6 +- .../modelfactory/BusinessModelMapFactory.java | 22 +- .../master/domain/MonitorInBusiness.java | 23 - .../master/domain/TestPlanInBusiness.java | 70 +- .../bench4q/master/domain/entity/Monitor.java | 58 + .../master/domain/entity/TestPlanDB.java | 10 + .../domain/factory/TestPlanFactory.java | 13 + .../bench4q/master/config/hibernate.cfg.xml | 1 + .../master/test/TestBase_MakeUpTestPlan.java | 2 +- .../{recordscript => }/TestRecordBase.java | 98 +- .../bench4q/master/test/db/DataBaseTest.java | 8 - .../test/domain/Test_TestPlanContext.java | 3 +- .../test/recordscript/TestDomGenerator.java | 136 +- .../recordscript/TestHttpRequestHeader.java | 2 +- .../test/recordscript/TestParentRequest.java | 399 +- .../Test_Bench4QCodeGenerator.java | 1 + .../test/service/Test_TestPlanService.java | 11 +- 18 files changed, 472 insertions(+), 4162 deletions(-) delete mode 100644 src/main/java/org/bench4q/master/domain/MonitorInBusiness.java create mode 100644 src/main/java/org/bench4q/master/domain/entity/Monitor.java rename src/test/java/org/bench4q/master/test/{recordscript => }/TestRecordBase.java (94%) delete mode 100644 src/test/java/org/bench4q/master/test/db/DataBaseTest.java diff --git a/RecordScriptTestCase/baidu.html b/RecordScriptTestCase/baidu.html index 82cbc33e..373ced8a 100644 --- a/RecordScriptTestCase/baidu.html +++ b/RecordScriptTestCase/baidu.html @@ -1,3768 +1,17 @@ - - - -�ٶ�������������ȫ��������������ƽ̨ - - - - - - - - - - - - - - - - - - - - - - - - + Bench4Q Test Case + + + - -
- -
- - - - - -
-
- - - - - - - - - - - - - - -

����Ϻ�����Ͷ������ ͱ�������ϱ�ڼ�����ɱ

-

�׷�ս�Ѵ����׷澫�� ���ֵ���� ����ҳ� �ܾ��̻�����

- - -
-
- -
-
-
- - -
-
- -
-
-
- 8 - 7 - 6 - 5 - 4 - 3 - 2 - 1 -
-
- -
-
-
- - - - - - - -
-
��������
-
- �����У����Ժ�... -
-
-
- - - -
- -
- - - - - - - -
-
- - - - - - - - - - - - - - -
-
- - - -
- - - - -
- -
- - - -
-
-

ר���Ƽ�

- -
-
-
-
- -
-

��Ѷ������������������

-

-

�������Ƽ����ߣ�����ÿ���

-
-
-

���������ˣ����ǡ�ʷ����߹���ֻ���

-

-

����ר�����ҡ��Ƽ���ҵ������

-
-
-

����ѷ��������API����˾������

-

-

��������ҵ�۲�����ý���ˣ�ר�����ң�����ҵ�۲���

-
-
-
-

����ı�װ׿��������

-

-

�������ѧ�ߣ����Ϸ���ĩ��ר������

-
-
-

��Ϊ�ٲ��ס���������

-

-

�����С������һ�ҵ����Ž�������ܻ�ӭ��ý��ժ¼

-
-
-

�����Ǹ�������

-

-

������ʱ�¡���������Ա

-
-
-

AVŮ��Ϊ�λ��Ϊ��ҽ�ɣ�

-

-

Ҷ����ʫ�ˣ��Ļ�������

-
-
-
-
-
- -
- -
- - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- - - - - - - - -
- - - - - - - - - - - - - -
- - - - - - - - -
- - - - - - - - - - - - - - - - -
- - - - - - - - -
- - - - - - - - - - - - -
-
-

��ָ�ڻ����

-
- - -
-
- - - -
-
- - - -
-
- -
- - -
- - - - - - - -
- - - - - - - - - - - - - - - - -
- - - - - - - - -
- - - - - - - - - - - - - - - - -
- - - - - - - - -
- - - - - - - - - - - - - - - - -
- - - - - - - - - -
- - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - -
- - - - - - - -
- - - - - - - - - -
-
-
-

��ϷͼƬ

-
-
- -
- - -
- - - - - - - - - - -
-
- - -
-
-
- - - - - - -
- - - - - - - -
- -
- -
- - - - - - - -
-
-
-

���ͼƬ

-
- -
-
- -
- - - - - - - - - - - - - - -
-
- �ȴ� -
-
- ��ý -
- - -
-
-
- - - - - - - -
- - - -
-
- - -
-

�ٶ����Ŷ��ҳ�Ʒ

-

�����ɻ���ѡȡÿ5�����Զ�����

-

�ٶ���������Դ�ڻ�����������վ��Ƶ����ϵ�Զ��������У��ٶȲ����ǻ�ת���κ��������������

-
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - + + + monitorModels = new ArrayList(); - for (MonitorInBusiness monitorInBusiness : testPlanContext - .getTestPlan().getMonitors()) { + for (Monitor monitorInBusiness : testPlanContext.getTestPlan() + .getMonitors()) { monitorModels.add(BusinessModelMapFactory .toModel(monitorInBusiness)); } diff --git a/src/main/java/org/bench4q/master/api/modelfactory/BusinessModelMapFactory.java b/src/main/java/org/bench4q/master/api/modelfactory/BusinessModelMapFactory.java index 06480692..2e784184 100644 --- a/src/main/java/org/bench4q/master/api/modelfactory/BusinessModelMapFactory.java +++ b/src/main/java/org/bench4q/master/api/modelfactory/BusinessModelMapFactory.java @@ -3,11 +3,11 @@ package org.bench4q.master.api.modelfactory; import java.util.ArrayList; import java.util.List; -import org.bench4q.master.domain.MonitorInBusiness; import org.bench4q.master.domain.RunningAgent; import org.bench4q.master.domain.RunningScript; import org.bench4q.master.domain.TestPlanInBusiness; import org.bench4q.master.domain.entity.Agent; +import org.bench4q.master.domain.entity.Monitor; import org.bench4q.master.domain.entity.Port; import org.bench4q.master.domain.entity.Script; import org.bench4q.master.domain.entity.TestPlanDB; @@ -121,11 +121,12 @@ public class BusinessModelMapFactory { public static TestPlanInBusiness toBusiness( TestPlanBusinessModel testPlanModel) { TestPlanInBusiness ret = new TestPlanInBusiness(); - List monitors = new ArrayList(); + List monitors = new ArrayList(); guardMonitorListNotNull(testPlanModel); if (testPlanModel.getMonitorModels() != null) { for (MonitorModel monitorModel : testPlanModel.getMonitorModels()) { - monitors.add(toBusiness(monitorModel)); + Monitor monitorInBusiness = toBusiness(monitorModel); + monitors.add(monitorInBusiness); } } ret.setMonitors(monitors); @@ -157,22 +158,21 @@ public class BusinessModelMapFactory { } ret.setRunningScriptModels(runningScriptModels); List monitorModels = new ArrayList(); - for (MonitorInBusiness monitorInBusiness : testPlanInBusiness - .getMonitors()) { + for (Monitor monitorInBusiness : testPlanInBusiness.getMonitors()) { monitorModels.add(toModel(monitorInBusiness)); } ret.setMonitorModels(monitorModels); return ret; } - public static MonitorInBusiness toBusiness(MonitorModel monitorModel) { - MonitorInBusiness ret = new MonitorInBusiness(); - ret.setHostName(monitorModel.getHostName()); - ret.setPort(monitorModel.getPort()); - return ret; + public static Monitor toBusiness(MonitorModel monitorModel) { + Monitor monitor = new Monitor(); + monitor.setHostName(monitorModel.getHostName()); + monitor.setPort(monitorModel.getPort()); + return monitor; } - public static MonitorModel toModel(MonitorInBusiness monitorInBusiness) { + public static MonitorModel toModel(Monitor monitorInBusiness) { MonitorModel ret = new MonitorModel(); ret.setHostName(monitorInBusiness.getHostName()); ret.setPort(monitorInBusiness.getPort()); diff --git a/src/main/java/org/bench4q/master/domain/MonitorInBusiness.java b/src/main/java/org/bench4q/master/domain/MonitorInBusiness.java deleted file mode 100644 index 3699dca1..00000000 --- a/src/main/java/org/bench4q/master/domain/MonitorInBusiness.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.bench4q.master.domain; - -public class MonitorInBusiness { - private String hostName; - private int port; - - public String getHostName() { - return hostName; - } - - public void setHostName(String hostName) { - this.hostName = hostName; - } - - public int getPort() { - return port; - } - - public void setPort(int port) { - this.port = port; - } - -} diff --git a/src/main/java/org/bench4q/master/domain/TestPlanInBusiness.java b/src/main/java/org/bench4q/master/domain/TestPlanInBusiness.java index d8666026..47d2c7ce 100644 --- a/src/main/java/org/bench4q/master/domain/TestPlanInBusiness.java +++ b/src/main/java/org/bench4q/master/domain/TestPlanInBusiness.java @@ -1,34 +1,36 @@ -package org.bench4q.master.domain; - -import java.util.List; - -public class TestPlanInBusiness { - private String name = ""; - private List runningScripts; - private List monitors; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public List getRunningScripts() { - return runningScripts; - } - - public void setRunningScripts(List runningScripts) { - this.runningScripts = runningScripts; - } - - public List getMonitors() { - return monitors; - } - - public void setMonitors(List monitors) { - this.monitors = monitors; - } - -} +package org.bench4q.master.domain; + +import java.util.List; + +import org.bench4q.master.domain.entity.Monitor; + +public class TestPlanInBusiness { + private String name = ""; + private List runningScripts; + private List monitors; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getRunningScripts() { + return runningScripts; + } + + public void setRunningScripts(List runningScripts) { + this.runningScripts = runningScripts; + } + + public List getMonitors() { + return monitors; + } + + public void setMonitors(List monitors) { + this.monitors = monitors; + } + +} diff --git a/src/main/java/org/bench4q/master/domain/entity/Monitor.java b/src/main/java/org/bench4q/master/domain/entity/Monitor.java new file mode 100644 index 00000000..5f045331 --- /dev/null +++ b/src/main/java/org/bench4q/master/domain/entity/Monitor.java @@ -0,0 +1,58 @@ +package org.bench4q.master.domain.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "monitor") +public class Monitor { + private int id; + private String hostName; + private int port; + private TestPlanDB testPlanDB; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", nullable = false) + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Column(name = "hostName", nullable = false) + public String getHostName() { + return hostName; + } + + public void setHostName(String hostName) { + this.hostName = hostName; + } + + @Column(name = "port", nullable = false) + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + @ManyToOne + @JoinColumn(name = "testPlanId") + public TestPlanDB getTestPlanDB() { + return testPlanDB; + } + + public void setTestPlanDB(TestPlanDB testPlanDB) { + this.testPlanDB = testPlanDB; + } +} diff --git a/src/main/java/org/bench4q/master/domain/entity/TestPlanDB.java b/src/main/java/org/bench4q/master/domain/entity/TestPlanDB.java index 09f80878..0b198d35 100644 --- a/src/main/java/org/bench4q/master/domain/entity/TestPlanDB.java +++ b/src/main/java/org/bench4q/master/domain/entity/TestPlanDB.java @@ -28,6 +28,7 @@ public class TestPlanDB implements IAggregate { private String currentStatus; private int failTimes; private Set testPlanScripts; + private Set monitors; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -104,6 +105,15 @@ public class TestPlanDB implements IAggregate { this.testPlanScripts = testPlanScripts; } + @OneToMany(mappedBy = "testPlanDB", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER) + public Set getMonitors() { + return monitors; + } + + public void setMonitors(Set monitors) { + this.monitors = monitors; + } + public TestPlanScript extracSpecifiedScript(Script script) { for (TestPlanScript testPlanScript : testPlanScripts) { if (testPlanScript.getScript().getId() == script.getId()) { diff --git a/src/main/java/org/bench4q/master/domain/factory/TestPlanFactory.java b/src/main/java/org/bench4q/master/domain/factory/TestPlanFactory.java index a576154f..e4b9167d 100644 --- a/src/main/java/org/bench4q/master/domain/factory/TestPlanFactory.java +++ b/src/main/java/org/bench4q/master/domain/factory/TestPlanFactory.java @@ -5,12 +5,15 @@ import java.util.HashSet; import java.util.Set; import java.util.UUID; +import org.bench4q.master.api.modelfactory.BusinessModelMapFactory; +import org.bench4q.master.domain.entity.Monitor; import org.bench4q.master.domain.entity.PlanedConfig; import org.bench4q.master.domain.entity.TestPlanDB; import org.bench4q.master.domain.entity.TestPlanScript; import org.bench4q.master.domain.entity.User; import org.bench4q.master.domain.service.ScriptService; import org.bench4q.share.enums.master.TestPlanStatus; +import org.bench4q.share.models.master.MonitorModel; import org.bench4q.share.models.master.RunningScriptModel; import org.bench4q.share.models.master.TestPlanBusinessModel; import org.bench4q.share.models.master.TestScriptConfig; @@ -48,6 +51,16 @@ public class TestPlanFactory { runningScriptModel.getConfig(), result)); } result.setTestPlanScripts(testPlanScripts); + + Set monitors = new HashSet(); + for (MonitorModel monitorModel : testPlanBusinessModel + .getMonitorModels()) { + Monitor monitorInBusiness = BusinessModelMapFactory + .toBusiness(monitorModel); + monitorInBusiness.setTestPlanDB(result); + monitors.add(monitorInBusiness); + } + result.setMonitors(monitors); return result; } diff --git a/src/main/resources/org/bench4q/master/config/hibernate.cfg.xml b/src/main/resources/org/bench4q/master/config/hibernate.cfg.xml index 0889c63f..ac6b0b06 100644 --- a/src/main/resources/org/bench4q/master/config/hibernate.cfg.xml +++ b/src/main/resources/org/bench4q/master/config/hibernate.cfg.xml @@ -26,6 +26,7 @@ + \ No newline at end of file diff --git a/src/test/java/org/bench4q/master/test/TestBase_MakeUpTestPlan.java b/src/test/java/org/bench4q/master/test/TestBase_MakeUpTestPlan.java index a5283846..7d4a57c7 100644 --- a/src/test/java/org/bench4q/master/test/TestBase_MakeUpTestPlan.java +++ b/src/test/java/org/bench4q/master/test/TestBase_MakeUpTestPlan.java @@ -36,7 +36,7 @@ public class TestBase_MakeUpTestPlan extends TestBase { private User testUser; protected static final int USE_SCRIPT = 61; // private static int EACH_SCRIPT_LOAD_LargeSCALE = 12000; - private static int EACH_SCRIPT_LOAD_SMALLSCALE = 10; + protected static int EACH_SCRIPT_LOAD_SMALLSCALE = 10; // private static int EACH_SCRIPT_LOAD_MIDDLESCALE = 800; private static String Monitor_Host_Name = "127.0.0.1"; private static String monitor_port = "5556"; diff --git a/src/test/java/org/bench4q/master/test/recordscript/TestRecordBase.java b/src/test/java/org/bench4q/master/test/TestRecordBase.java similarity index 94% rename from src/test/java/org/bench4q/master/test/recordscript/TestRecordBase.java rename to src/test/java/org/bench4q/master/test/TestRecordBase.java index f0daf63b..af4a4787 100644 --- a/src/test/java/org/bench4q/master/test/recordscript/TestRecordBase.java +++ b/src/test/java/org/bench4q/master/test/TestRecordBase.java @@ -1,49 +1,49 @@ -package org.bench4q.master.test.recordscript; - -import java.util.ArrayList; -import java.util.List; - -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.RunScenarioModel; -import org.bench4q.share.models.agent.scriptrecord.BehaviorModel; - -public abstract class TestRecordBase { - private IScriptAdapter adapter; - private Bench4qCodeGenerator codeGenerator; - protected static String parentUrl = "http://localhost:8080/Bench4QTestCase/testcase.html"; - protected static String independentUrl = "www.baidu.com"; - protected static String childrenUrl1 = "http://localhost:8080/Bench4QTestCase/script/agenttable.js"; - - protected IScriptAdapter getAdpater() { - return adapter; - } - - private void setAdpater(IScriptAdapter adapter) { - this.adapter = adapter; - } - - protected Bench4qCodeGenerator getCodeGenerator() { - return codeGenerator; - } - - private void setCodeGenerator(Bench4qCodeGenerator codeGenerator) { - this.codeGenerator = codeGenerator; - } - - protected void init() { - this.setAdpater(new Bench4qTestScriptAdapter(new RunScenarioModel())); - this.setCodeGenerator(new Bench4qCodeGenerator(this.getAdpater())); - } - - protected BehaviorModel createUserBehaviorModel(String url) { - List params = new ArrayList(); - ParameterModel param = new ParameterModel(); - param.setKey("url"); - param.setValue(url); - params.add(param); - return BehaviorModel.UserBehaviorBuilder(1, "Get", "http", params); - } -} +package org.bench4q.master.test; + +import java.util.ArrayList; +import java.util.List; + +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.RunScenarioModel; +import org.bench4q.share.models.agent.scriptrecord.BehaviorModel; + +public abstract class TestRecordBase { + private IScriptAdapter adapter; + private Bench4qCodeGenerator codeGenerator; + protected static String parentUrl = "http://localhost:8080/Bench4QTestCase/testcase.html"; + protected static String independentUrl = "www.baidu.com"; + protected static String childrenUrl1 = "http://localhost:8080/Bench4QTestCase/script/agenttable.js"; + + protected IScriptAdapter getAdpater() { + return adapter; + } + + private void setAdpater(IScriptAdapter adapter) { + this.adapter = adapter; + } + + protected Bench4qCodeGenerator getCodeGenerator() { + return codeGenerator; + } + + private void setCodeGenerator(Bench4qCodeGenerator codeGenerator) { + this.codeGenerator = codeGenerator; + } + + protected void init() { + this.setAdpater(new Bench4qTestScriptAdapter(new RunScenarioModel())); + this.setCodeGenerator(new Bench4qCodeGenerator(this.getAdpater())); + } + + protected BehaviorModel createUserBehaviorModel(String url) { + List params = new ArrayList(); + ParameterModel param = new ParameterModel(); + param.setKey("url"); + param.setValue(url); + params.add(param); + return BehaviorModel.UserBehaviorBuilder(1, "Get", "http", params); + } +} diff --git a/src/test/java/org/bench4q/master/test/db/DataBaseTest.java b/src/test/java/org/bench4q/master/test/db/DataBaseTest.java deleted file mode 100644 index 9a7eb827..00000000 --- a/src/test/java/org/bench4q/master/test/db/DataBaseTest.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.bench4q.master.test.db; - -public class DataBaseTest { - - public void testConnection() { - - } -} diff --git a/src/test/java/org/bench4q/master/test/domain/Test_TestPlanContext.java b/src/test/java/org/bench4q/master/test/domain/Test_TestPlanContext.java index e26832f6..48a1f314 100644 --- a/src/test/java/org/bench4q/master/test/domain/Test_TestPlanContext.java +++ b/src/test/java/org/bench4q/master/test/domain/Test_TestPlanContext.java @@ -56,7 +56,8 @@ public class Test_TestPlanContext extends TestBase_MakeUpTestPlan { @Test public void testGetTotalLoad() { - assertEquals(40, this.getTestPlanContext().getTotalLoad()); + assertEquals(EACH_SCRIPT_LOAD_SMALLSCALE, this.getTestPlanContext() + .getTotalLoad()); } @Test diff --git a/src/test/java/org/bench4q/master/test/recordscript/TestDomGenerator.java b/src/test/java/org/bench4q/master/test/recordscript/TestDomGenerator.java index 9663cff5..7b264229 100644 --- a/src/test/java/org/bench4q/master/test/recordscript/TestDomGenerator.java +++ b/src/test/java/org/bench4q/master/test/recordscript/TestDomGenerator.java @@ -1,67 +1,69 @@ -package org.bench4q.master.test.recordscript; - -import static org.junit.Assert.*; - -import java.io.File; -import java.io.IOException; -import java.net.URL; -import org.apache.commons.io.FileUtils; -import org.bench4q.master.scriptrecord.httpcapture.generator.ChildrenUrl; -import org.junit.Test; - -public class TestDomGenerator extends TestRecordBase { - private URL url = this.getClass().getResource("testcase.html"); - - public TestDomGenerator() { - init(); - } - - @Test - public void testDomParser() throws IOException { - this.getCodeGenerator() - .getScriptAdapter() - .insertUserBehaviorsToScenario( - createUserBehaviorModel(parentUrl)); - this.getCodeGenerator().doParseHtmlContent( - FileUtils.readFileToString(new File(url.getPath())), parentUrl); - assertTrue(this.getCodeGenerator().getScriptAdapter().getChildrenUrls() - .size() == 8); - for (ChildrenUrl childrenUrl : this.getCodeGenerator() - .getScriptAdapter().getChildrenUrls()) { - assertTrue(childrenUrl.getParentBatchId() == 0); - } - } - - @Test - public void testDomParserWithinAdapter() throws IOException { - this.getAdpater().insertUserBehaviorsToScenario( - createUserBehaviorModel(independentUrl)); - this.getAdpater().insertUserBehaviorsToScenario( - createUserBehaviorModel(parentUrl)); - this.getCodeGenerator().doParseHtmlContent( - FileUtils.readFileToString(new File(this.url.getPath())), - parentUrl); - System.out.println(this.getCodeGenerator().getScriptAdapter() - .getChildrenUrls().size()); - assertTrue(this.getCodeGenerator().getScriptAdapter().getChildrenUrls() - .size() == 8); - - for (ChildrenUrl childrenUrl : this.getAdpater().getChildrenUrls()) { - assertTrue(childrenUrl.getParentBatchId() == 1); - } - } - - @Test - public void testDomParserWithIncorrectParentUrl() throws IOException { - this.getAdpater().insertUserBehaviorsToScenario( - createUserBehaviorModel(parentUrl)); - this.getAdpater().insertUserBehaviorsToScenario( - createUserBehaviorModel(independentUrl)); - this.getCodeGenerator().doParseHtmlContent( - FileUtils.readFileToString(new File(this.url.getPath())), - parentUrl + "error"); - assertTrue(this.getCodeGenerator().getScriptAdapter().getChildrenUrls() - .size() == 0); - } - -} +package org.bench4q.master.test.recordscript; + +import static org.junit.Assert.*; + +import java.io.File; +import java.io.IOException; +import java.net.URL; + +import org.apache.commons.io.FileUtils; +import org.bench4q.master.scriptrecord.httpcapture.generator.ChildrenUrl; +import org.bench4q.master.test.TestRecordBase; +import org.junit.Test; + +public class TestDomGenerator extends TestRecordBase { + private URL url = this.getClass().getResource("testcase.html"); + + public TestDomGenerator() { + init(); + } + + @Test + public void testDomParser() throws IOException { + this.getCodeGenerator() + .getScriptAdapter() + .insertUserBehaviorsToScenario( + createUserBehaviorModel(parentUrl)); + this.getCodeGenerator().doParseHtmlContent( + FileUtils.readFileToString(new File(url.getPath())), parentUrl); + assertTrue(this.getCodeGenerator().getScriptAdapter().getChildrenUrls() + .size() == 8); + for (ChildrenUrl childrenUrl : this.getCodeGenerator() + .getScriptAdapter().getChildrenUrls()) { + assertTrue(childrenUrl.getParentBatchId() == 0); + } + } + + @Test + public void testDomParserWithinAdapter() throws IOException { + this.getAdpater().insertUserBehaviorsToScenario( + createUserBehaviorModel(independentUrl)); + this.getAdpater().insertUserBehaviorsToScenario( + createUserBehaviorModel(parentUrl)); + this.getCodeGenerator().doParseHtmlContent( + FileUtils.readFileToString(new File(this.url.getPath())), + parentUrl); + System.out.println(this.getCodeGenerator().getScriptAdapter() + .getChildrenUrls().size()); + assertTrue(this.getCodeGenerator().getScriptAdapter().getChildrenUrls() + .size() == 8); + + for (ChildrenUrl childrenUrl : this.getAdpater().getChildrenUrls()) { + assertTrue(childrenUrl.getParentBatchId() == 1); + } + } + + @Test + public void testDomParserWithIncorrectParentUrl() throws IOException { + this.getAdpater().insertUserBehaviorsToScenario( + createUserBehaviorModel(parentUrl)); + this.getAdpater().insertUserBehaviorsToScenario( + createUserBehaviorModel(independentUrl)); + this.getCodeGenerator().doParseHtmlContent( + FileUtils.readFileToString(new File(this.url.getPath())), + parentUrl + "error"); + assertTrue(this.getCodeGenerator().getScriptAdapter().getChildrenUrls() + .size() == 0); + } + +} diff --git a/src/test/java/org/bench4q/master/test/recordscript/TestHttpRequestHeader.java b/src/test/java/org/bench4q/master/test/recordscript/TestHttpRequestHeader.java index 31a9d607..98dbae7b 100644 --- a/src/test/java/org/bench4q/master/test/recordscript/TestHttpRequestHeader.java +++ b/src/test/java/org/bench4q/master/test/recordscript/TestHttpRequestHeader.java @@ -50,7 +50,7 @@ public class TestHttpRequestHeader { assertEquals("multipart", this.getRequestHeader().contentType.trim()); assertEquals(100, this.getRequestHeader().contentLength); assertEquals(true, this.getRequestHeader().pragmaNoCache); - assertEquals(" zh-CN,zh;q=0.8", this.getRequestHeader().acceptLanguage); + assertEquals("zh-CN,zh;q=0.8", this.getRequestHeader().acceptLanguage); // assertEquals("Mon, 22 Mar 2010 14:14:40 GMT; old-content-length=200", // this.getRequestHeader().ifModifiedSince.trim()); diff --git a/src/test/java/org/bench4q/master/test/recordscript/TestParentRequest.java b/src/test/java/org/bench4q/master/test/recordscript/TestParentRequest.java index 882f2502..023d129c 100644 --- a/src/test/java/org/bench4q/master/test/recordscript/TestParentRequest.java +++ b/src/test/java/org/bench4q/master/test/recordscript/TestParentRequest.java @@ -1,199 +1,200 @@ -package org.bench4q.master.test.recordscript; - -import static org.junit.Assert.*; - -import java.util.List; - -import org.bench4q.master.helper.RunScenarioModelHelper; -import org.bench4q.master.scriptrecord.httpcapture.Bench4qTestScriptAdapter; -import org.bench4q.master.scriptrecord.httpcapture.IScriptAdapter; -import org.bench4q.master.scriptrecord.httpcapture.generator.ChildrenUrl; -import org.bench4q.share.models.agent.RunScenarioModel; -import org.bench4q.share.models.agent.scriptrecord.BatchModel; -import org.junit.Test; - -public class TestParentRequest extends TestRecordBase { - private IScriptAdapter adapater; - private static String parentUrl = "www.apache.com"; - private static String childUrl = "www.yahoo.com"; - private static String independentUrl = "www.baidu.com"; - private static String independentUrl2 = "www.eclipse.org"; - private static String childUrl2 = "www.tomcat.com"; - - private IScriptAdapter getAdapater() { - return adapater; - } - - private void setAdapater(IScriptAdapter adapater) { - this.adapater = adapater; - } - - public TestParentRequest() { - this.setAdapater(new Bench4qTestScriptAdapter(new RunScenarioModel())); - } - - @Test - public void testAddOneBehaviorWihoutChildrenUrl() { - this.getAdapater().insertUserBehaviorsToScenario( - createUserBehaviorModel(parentUrl)); - assertNotNull(this.getAdapater().getRunScenarioModel()); - List batches = RunScenarioModelHelper.getBatches(this - .getAdapater().getRunScenarioModel()); - assertNotNull(batches); - assertNotNull(batches.get(0)); - assertTrue(batches.get(0).getId() == 0); - - } - - @Test - public void testAddTwoBehaviorWithOutChildrenUrl() { - this.getAdapater().insertUserBehaviorsToScenario( - createUserBehaviorModel(parentUrl)); - this.getAdapater().getChildrenUrls() - .add(createChildrenUrl(childUrl, 0)); - - this.getAdapater().insertUserBehaviorsToScenario( - createUserBehaviorModel(independentUrl)); - this.getAdapater().insertUserBehaviorsToScenario( - createUserBehaviorModel(independentUrl2)); - RunScenarioModel runScenarioModel = this.getAdapater() - .getRunScenarioModel(); - assertNotNull(runScenarioModel); - List batches = RunScenarioModelHelper - .getBatches(runScenarioModel); - assertNotNull(batches); - assertTrue(batches.size() == 3); - assertTrue(batches.get(1).getBehaviors().size() == 1); - assertTrue(batches.get(2).getBehaviors().size() == 1); - assertTrue(batches.get(1).getBehaviors().get(0).getParameters().get(0) - .getValue().equals(independentUrl)); - assertTrue(batches.get(2).getBehaviors().get(0).getParameters().get(0) - .getValue().equals(independentUrl2)); - } - - // private UserBehaviorModel createUserBehavior(String url) { - // UserBehaviorModel model = new UserBehaviorModel(); - // model.setId(1); - // model.setName("Get"); - // model.setUse("http"); - // List params = new ArrayList(); - // ParameterModel param = new ParameterModel(); - // param.setKey("url"); - // param.setValue(url); - // params.add(param); - // model.setParameters(params); - // return model; - // } - - @Test - public void testAddBehaviorWithInChildrenUrl() { - this.getAdapater().insertUserBehaviorsToScenario( - createUserBehaviorModel(parentUrl)); - this.getAdapater().getChildrenUrls() - .add(createChildrenUrl(childUrl, 0)); - this.getAdapater().insertUserBehaviorsToScenario( - createUserBehaviorModel(childUrl)); - RunScenarioModel runScenarioModel = this.getAdapater() - .getRunScenarioModel(); - assertNotNull(runScenarioModel); - List batches = RunScenarioModelHelper - .getBatches(runScenarioModel); - assertNotNull(batches); - assertNotNull(batches.get(0)); - assertNotNull(batches.get(1)); - assertTrue(batches.get(1).getId() == 1); - assertEquals(batches.get(0).getChildId(), batches.get(1).getId()); - assertEquals(batches.get(1).getParentId(), batches.get(0).getId()); - } - - private ChildrenUrl createChildrenUrl(String url, int parentBatchId) { - ChildrenUrl childrenUrl = new ChildrenUrl(); - childrenUrl.setParentBatchId(parentBatchId); - childrenUrl.setUrl(url); - return childrenUrl; - } - - @Test - public void testAddBehaviorsIncludeInAndOut() { - this.getAdapater().insertUserBehaviorsToScenario( - createUserBehaviorModel(parentUrl)); - - this.getAdapater().getChildrenUrls() - .add(createChildrenUrl(childUrl, 0)); - - this.getAdapater().insertUserBehaviorsToScenario( - createUserBehaviorModel(childUrl)); - this.getAdapater().insertUserBehaviorsToScenario( - createUserBehaviorModel(independentUrl)); - List batches = RunScenarioModelHelper.getBatches(this - .getAdapater().getRunScenarioModel()); - assertTrue(batches.get(1).getBehaviors().size() == 1); - assertTrue(batches.get(2).getBehaviors().size() == 1); - assertTrue(batches.get(1).getBehaviors().get(0).getParameters().get(0) - .getValue().equals(childUrl)); - assertTrue(batches.get(2).getBehaviors().get(0).getParameters().get(0) - .getValue().equals(independentUrl)); - assertEquals(batches.get(0).getChildId(), batches.get(1).getId()); - assertEquals(batches.get(1).getParentId(), batches.get(0).getId()); - } - - @Test - public void addTwoBehaviorsInChildrenUrl() { - this.getAdapater().insertUserBehaviorsToScenario( - createUserBehaviorModel(parentUrl)); - this.getAdapater().getChildrenUrls() - .add(createChildrenUrl(childUrl, 0)); - this.getAdapater().getChildrenUrls() - .add(createChildrenUrl(childUrl2, 0)); - this.getAdapater().insertUserBehaviorsToScenario( - createUserBehaviorModel(childUrl)); - this.getAdapater().insertUserBehaviorsToScenario( - createUserBehaviorModel(childUrl2)); - List batches = RunScenarioModelHelper.getBatches(this - .getAdapater().getRunScenarioModel()); - System.out.println(batches.size()); - assertTrue(batches.size() == 2); - assertTrue(batches.get(0).getBehaviors().get(0).getParameters().get(0) - .getValue().equals(parentUrl)); - assertTrue(batches.get(1).getBehaviors().get(0).getParameters().get(0) - .getValue().equals(childUrl)); - assertTrue(batches.get(1).getBehaviors().get(1).getParameters().get(0) - .getValue().equals(childUrl2)); - } - - @Test - public void addTwoInTwoOut() { - this.getAdapater().insertUserBehaviorsToScenario( - createUserBehaviorModel(parentUrl)); - this.getAdapater().getChildrenUrls() - .add(createChildrenUrl(childUrl, 0)); - this.getAdapater().getChildrenUrls() - .add(createChildrenUrl(childUrl2, 0)); - this.getAdapater().insertUserBehaviorsToScenario( - createUserBehaviorModel(childUrl)); - this.getAdapater().insertUserBehaviorsToScenario( - createUserBehaviorModel(childUrl2)); - this.getAdapater().insertUserBehaviorsToScenario( - createUserBehaviorModel(independentUrl)); - this.getAdapater().insertUserBehaviorsToScenario( - createUserBehaviorModel(independentUrl2)); - assertTrue(RunScenarioModelHelper.getBatches( - this.getAdapater().getRunScenarioModel()).size() == 4); - } - - @Test - public void testGetParentUrl() { - this.getAdapater().insertUserBehaviorsToScenario( - createUserBehaviorModel(parentUrl)); - this.getAdapater().insertUserBehaviorsToScenario( - createUserBehaviorModel(independentUrl)); - this.getAdapater().insertUserBehaviorsToScenario( - createUserBehaviorModel(independentUrl2)); - - assertTrue(this.getAdapater().getParentBatchIdWithParentUrl(parentUrl) == 0); - assertTrue(this.getAdapater().getParentBatchIdWithParentUrl( - independentUrl) == 1); - assertTrue(this.getAdapater().getParentBatchIdWithParentUrl( - independentUrl2) == 2); - } -} +package org.bench4q.master.test.recordscript; + +import static org.junit.Assert.*; + +import java.util.List; + +import org.bench4q.master.helper.RunScenarioModelHelper; +import org.bench4q.master.scriptrecord.httpcapture.Bench4qTestScriptAdapter; +import org.bench4q.master.scriptrecord.httpcapture.IScriptAdapter; +import org.bench4q.master.scriptrecord.httpcapture.generator.ChildrenUrl; +import org.bench4q.master.test.TestRecordBase; +import org.bench4q.share.models.agent.RunScenarioModel; +import org.bench4q.share.models.agent.scriptrecord.BatchModel; +import org.junit.Test; + +public class TestParentRequest extends TestRecordBase { + private IScriptAdapter adapater; + private static String parentUrl = "www.apache.com"; + private static String childUrl = "www.yahoo.com"; + private static String independentUrl = "www.baidu.com"; + private static String independentUrl2 = "www.eclipse.org"; + private static String childUrl2 = "www.tomcat.com"; + + private IScriptAdapter getAdapater() { + return adapater; + } + + private void setAdapater(IScriptAdapter adapater) { + this.adapater = adapater; + } + + public TestParentRequest() { + this.setAdapater(new Bench4qTestScriptAdapter(new RunScenarioModel())); + } + + @Test + public void testAddOneBehaviorWihoutChildrenUrl() { + this.getAdapater().insertUserBehaviorsToScenario( + createUserBehaviorModel(parentUrl)); + assertNotNull(this.getAdapater().getRunScenarioModel()); + List batches = RunScenarioModelHelper.getBatches(this + .getAdapater().getRunScenarioModel()); + assertNotNull(batches); + assertNotNull(batches.get(0)); + assertTrue(batches.get(0).getId() == 0); + + } + + @Test + public void testAddTwoBehaviorWithOutChildrenUrl() { + this.getAdapater().insertUserBehaviorsToScenario( + createUserBehaviorModel(parentUrl)); + this.getAdapater().getChildrenUrls() + .add(createChildrenUrl(childUrl, 0)); + + this.getAdapater().insertUserBehaviorsToScenario( + createUserBehaviorModel(independentUrl)); + this.getAdapater().insertUserBehaviorsToScenario( + createUserBehaviorModel(independentUrl2)); + RunScenarioModel runScenarioModel = this.getAdapater() + .getRunScenarioModel(); + assertNotNull(runScenarioModel); + List batches = RunScenarioModelHelper + .getBatches(runScenarioModel); + assertNotNull(batches); + assertTrue(batches.size() == 3); + assertTrue(batches.get(1).getBehaviors().size() == 1); + assertTrue(batches.get(2).getBehaviors().size() == 1); + assertTrue(batches.get(1).getBehaviors().get(0).getParameters().get(0) + .getValue().equals(independentUrl)); + assertTrue(batches.get(2).getBehaviors().get(0).getParameters().get(0) + .getValue().equals(independentUrl2)); + } + + // private UserBehaviorModel createUserBehavior(String url) { + // UserBehaviorModel model = new UserBehaviorModel(); + // model.setId(1); + // model.setName("Get"); + // model.setUse("http"); + // List params = new ArrayList(); + // ParameterModel param = new ParameterModel(); + // param.setKey("url"); + // param.setValue(url); + // params.add(param); + // model.setParameters(params); + // return model; + // } + + @Test + public void testAddBehaviorWithInChildrenUrl() { + this.getAdapater().insertUserBehaviorsToScenario( + createUserBehaviorModel(parentUrl)); + this.getAdapater().getChildrenUrls() + .add(createChildrenUrl(childUrl, 0)); + this.getAdapater().insertUserBehaviorsToScenario( + createUserBehaviorModel(childUrl)); + RunScenarioModel runScenarioModel = this.getAdapater() + .getRunScenarioModel(); + assertNotNull(runScenarioModel); + List batches = RunScenarioModelHelper + .getBatches(runScenarioModel); + assertNotNull(batches); + assertNotNull(batches.get(0)); + assertNotNull(batches.get(1)); + assertTrue(batches.get(1).getId() == 1); + assertEquals(batches.get(0).getChildId(), batches.get(1).getId()); + assertEquals(batches.get(1).getParentId(), batches.get(0).getId()); + } + + private ChildrenUrl createChildrenUrl(String url, int parentBatchId) { + ChildrenUrl childrenUrl = new ChildrenUrl(); + childrenUrl.setParentBatchId(parentBatchId); + childrenUrl.setUrl(url); + return childrenUrl; + } + + @Test + public void testAddBehaviorsIncludeInAndOut() { + this.getAdapater().insertUserBehaviorsToScenario( + createUserBehaviorModel(parentUrl)); + + this.getAdapater().getChildrenUrls() + .add(createChildrenUrl(childUrl, 0)); + + this.getAdapater().insertUserBehaviorsToScenario( + createUserBehaviorModel(childUrl)); + this.getAdapater().insertUserBehaviorsToScenario( + createUserBehaviorModel(independentUrl)); + List batches = RunScenarioModelHelper.getBatches(this + .getAdapater().getRunScenarioModel()); + assertTrue(batches.get(1).getBehaviors().size() == 1); + assertTrue(batches.get(2).getBehaviors().size() == 1); + assertTrue(batches.get(1).getBehaviors().get(0).getParameters().get(0) + .getValue().equals(childUrl)); + assertTrue(batches.get(2).getBehaviors().get(0).getParameters().get(0) + .getValue().equals(independentUrl)); + assertEquals(batches.get(0).getChildId(), batches.get(1).getId()); + assertEquals(batches.get(1).getParentId(), batches.get(0).getId()); + } + + @Test + public void addTwoBehaviorsInChildrenUrl() { + this.getAdapater().insertUserBehaviorsToScenario( + createUserBehaviorModel(parentUrl)); + this.getAdapater().getChildrenUrls() + .add(createChildrenUrl(childUrl, 0)); + this.getAdapater().getChildrenUrls() + .add(createChildrenUrl(childUrl2, 0)); + this.getAdapater().insertUserBehaviorsToScenario( + createUserBehaviorModel(childUrl)); + this.getAdapater().insertUserBehaviorsToScenario( + createUserBehaviorModel(childUrl2)); + List batches = RunScenarioModelHelper.getBatches(this + .getAdapater().getRunScenarioModel()); + System.out.println(batches.size()); + assertTrue(batches.size() == 2); + assertTrue(batches.get(0).getBehaviors().get(0).getParameters().get(0) + .getValue().equals(parentUrl)); + assertTrue(batches.get(1).getBehaviors().get(0).getParameters().get(0) + .getValue().equals(childUrl)); + assertTrue(batches.get(1).getBehaviors().get(1).getParameters().get(0) + .getValue().equals(childUrl2)); + } + + @Test + public void addTwoInTwoOut() { + this.getAdapater().insertUserBehaviorsToScenario( + createUserBehaviorModel(parentUrl)); + this.getAdapater().getChildrenUrls() + .add(createChildrenUrl(childUrl, 0)); + this.getAdapater().getChildrenUrls() + .add(createChildrenUrl(childUrl2, 0)); + this.getAdapater().insertUserBehaviorsToScenario( + createUserBehaviorModel(childUrl)); + this.getAdapater().insertUserBehaviorsToScenario( + createUserBehaviorModel(childUrl2)); + this.getAdapater().insertUserBehaviorsToScenario( + createUserBehaviorModel(independentUrl)); + this.getAdapater().insertUserBehaviorsToScenario( + createUserBehaviorModel(independentUrl2)); + assertTrue(RunScenarioModelHelper.getBatches( + this.getAdapater().getRunScenarioModel()).size() == 4); + } + + @Test + public void testGetParentUrl() { + this.getAdapater().insertUserBehaviorsToScenario( + createUserBehaviorModel(parentUrl)); + this.getAdapater().insertUserBehaviorsToScenario( + createUserBehaviorModel(independentUrl)); + this.getAdapater().insertUserBehaviorsToScenario( + createUserBehaviorModel(independentUrl2)); + + assertTrue(this.getAdapater().getParentBatchIdWithParentUrl(parentUrl) == 0); + assertTrue(this.getAdapater().getParentBatchIdWithParentUrl( + independentUrl) == 1); + assertTrue(this.getAdapater().getParentBatchIdWithParentUrl( + independentUrl2) == 2); + } +} diff --git a/src/test/java/org/bench4q/master/test/recordscript/Test_Bench4QCodeGenerator.java b/src/test/java/org/bench4q/master/test/recordscript/Test_Bench4QCodeGenerator.java index 89a944c6..8d5df62d 100644 --- a/src/test/java/org/bench4q/master/test/recordscript/Test_Bench4QCodeGenerator.java +++ b/src/test/java/org/bench4q/master/test/recordscript/Test_Bench4QCodeGenerator.java @@ -20,6 +20,7 @@ import org.bench4q.master.scriptrecord.httpcapture.generator.Bench4qCodeGenerato import org.bench4q.master.scriptrecord.httpcapture.generator.ContentDecoder; import org.bench4q.master.scriptrecord.httpcapture.generator.IScriptGenerator; import org.bench4q.master.scriptrecord.httpcapture.generator.ResponseParser; +import org.bench4q.master.test.TestRecordBase; import org.bench4q.share.models.agent.RunScenarioModel; import org.bench4q.share.models.agent.scriptrecord.BehaviorModel; import org.junit.Test; diff --git a/src/test/java/org/bench4q/master/test/service/Test_TestPlanService.java b/src/test/java/org/bench4q/master/test/service/Test_TestPlanService.java index 49224f15..ef60740b 100644 --- a/src/test/java/org/bench4q/master/test/service/Test_TestPlanService.java +++ b/src/test/java/org/bench4q/master/test/service/Test_TestPlanService.java @@ -7,6 +7,7 @@ import java.util.UUID; import org.bench4q.master.api.modelfactory.BusinessModelMapFactory; import org.bench4q.master.domain.TestPlanInBusiness; +import org.bench4q.master.domain.entity.TestPlanDB; import org.bench4q.master.domain.entity.TestPlanScript; import org.bench4q.master.domain.entity.User; import org.bench4q.master.test.TestBase_MakeUpTestPlan; @@ -101,16 +102,18 @@ public class Test_TestPlanService extends TestBase_MakeUpTestPlan { int planCountAfterSubmit = this.getTestPlanRepository() .loadEntities(user).size(); assertEquals(planCountBeforeSubmit + 1, planCountAfterSubmit); - Set testPlanScripts = this.getTestPlanRepository() - .getTestPlan(randomUUID).getTestPlanScripts(); + TestPlanDB testPlan = this.getTestPlanRepository().getTestPlan( + randomUUID); + Set testPlanScripts = testPlan.getTestPlanScripts(); assertNotNull(testPlanScripts); assertEquals(1, testPlanScripts.size()); + assertNotNull(testPlan.getMonitors()); + assertEquals(1, testPlan.getMonitors().size()); for (TestPlanScript testPlanScript : testPlanScripts) { assertEquals(getScriptId(), testPlanScript.getScript().getId()); assertEquals(20, testPlanScript.getPlanedConfig().getWarmUp()); } - assertTrue(this.getTestPlanRepository().detach( - this.getTestPlanRepository().getTestPlan(randomUUID).getId())); + assertTrue(this.getTestPlanRepository().detach(testPlan.getId())); } @Test