build Monitor into TestPlanDB

This commit is contained in:
coderfengyun 2014-02-21 16:15:26 +08:00
parent 04f529eb9c
commit d6fc35085c
18 changed files with 472 additions and 4162 deletions

File diff suppressed because it is too large Load Diff

View File

@ -10,10 +10,10 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.bench4q.master.api.modelfactory.BusinessModelMapFactory;
import org.bench4q.master.domain.MonitorInBusiness;
import org.bench4q.master.domain.RunningScript;
import org.bench4q.master.domain.TestPlanContext;
import org.bench4q.master.domain.TestPlanInBusiness;
import org.bench4q.master.domain.entity.Monitor;
import org.bench4q.master.domain.entity.TestPlanDB;
import org.bench4q.master.domain.service.TestPlanEngine;
import org.bench4q.master.domain.service.TestPlanScriptResultService;
@ -190,8 +190,8 @@ public class TestPlanController extends BaseController {
runningScript));
}
List<MonitorModel> monitorModels = new ArrayList<MonitorModel>();
for (MonitorInBusiness monitorInBusiness : testPlanContext
.getTestPlan().getMonitors()) {
for (Monitor monitorInBusiness : testPlanContext.getTestPlan()
.getMonitors()) {
monitorModels.add(BusinessModelMapFactory
.toModel(monitorInBusiness));
}

View File

@ -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<MonitorInBusiness> monitors = new ArrayList<MonitorInBusiness>();
List<Monitor> monitors = new ArrayList<Monitor>();
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<MonitorModel> monitorModels = new ArrayList<MonitorModel>();
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());

View File

@ -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;
}
}

View File

@ -1,34 +1,36 @@
package org.bench4q.master.domain;
import java.util.List;
public class TestPlanInBusiness {
private String name = "";
private List<RunningScript> runningScripts;
private List<MonitorInBusiness> monitors;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<RunningScript> getRunningScripts() {
return runningScripts;
}
public void setRunningScripts(List<RunningScript> runningScripts) {
this.runningScripts = runningScripts;
}
public List<MonitorInBusiness> getMonitors() {
return monitors;
}
public void setMonitors(List<MonitorInBusiness> 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<RunningScript> runningScripts;
private List<Monitor> monitors;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<RunningScript> getRunningScripts() {
return runningScripts;
}
public void setRunningScripts(List<RunningScript> runningScripts) {
this.runningScripts = runningScripts;
}
public List<Monitor> getMonitors() {
return monitors;
}
public void setMonitors(List<Monitor> monitors) {
this.monitors = monitors;
}
}

View File

@ -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;
}
}

View File

@ -28,6 +28,7 @@ public class TestPlanDB implements IAggregate {
private String currentStatus;
private int failTimes;
private Set<TestPlanScript> testPlanScripts;
private Set<Monitor> 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<Monitor> getMonitors() {
return monitors;
}
public void setMonitors(Set<Monitor> monitors) {
this.monitors = monitors;
}
public TestPlanScript extracSpecifiedScript(Script script) {
for (TestPlanScript testPlanScript : testPlanScripts) {
if (testPlanScript.getScript().getId() == script.getId()) {

View File

@ -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<Monitor> monitors = new HashSet<Monitor>();
for (MonitorModel monitorModel : testPlanBusinessModel
.getMonitorModels()) {
Monitor monitorInBusiness = BusinessModelMapFactory
.toBusiness(monitorModel);
monitorInBusiness.setTestPlanDB(result);
monitors.add(monitorInBusiness);
}
result.setMonitors(monitors);
return result;
}

View File

@ -26,6 +26,7 @@
<mapping class="org.bench4q.master.domain.entity.TestPlanDB" />
<mapping class="org.bench4q.master.domain.entity.TestPlanScript" />
<mapping class="org.bench4q.master.domain.entity.TestPlanScriptResult" />
<mapping class="org.bench4q.master.domain.entity.Monitor" />
<mapping class="org.bench4q.master.domain.entity.MonitorResult" />
</session-factory>
</hibernate-configuration>

View File

@ -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";

View File

@ -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<ParameterModel> params = new ArrayList<ParameterModel>();
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<ParameterModel> params = new ArrayList<ParameterModel>();
ParameterModel param = new ParameterModel();
param.setKey("url");
param.setValue(url);
params.add(param);
return BehaviorModel.UserBehaviorBuilder(1, "Get", "http", params);
}
}

View File

@ -1,8 +0,0 @@
package org.bench4q.master.test.db;
public class DataBaseTest {
public void testConnection() {
}
}

View File

@ -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

View File

@ -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);
}
}

View File

@ -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());

View File

@ -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<BatchModel> 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<BatchModel> 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<ParameterModel> params = new ArrayList<ParameterModel>();
// 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<BatchModel> 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<BatchModel> 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<BatchModel> 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<BatchModel> 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<BatchModel> 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<ParameterModel> params = new ArrayList<ParameterModel>();
// 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<BatchModel> 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<BatchModel> 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<BatchModel> 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);
}
}

View File

@ -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;

View File

@ -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<TestPlanScript> testPlanScripts = this.getTestPlanRepository()
.getTestPlan(randomUUID).getTestPlanScripts();
TestPlanDB testPlan = this.getTestPlanRepository().getTestPlan(
randomUUID);
Set<TestPlanScript> 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