From cbc19f8207a370ad8e149540bf3df0a3b8b3a912 Mon Sep 17 00:00:00 2001 From: coderfengyun Date: Tue, 23 Sep 2014 08:45:33 +0800 Subject: [PATCH] refactor ing refactor ing --- .../agent/plugin/basic/http/HttpPlugin.java | 2 +- .../scenario/node/ConditionBehavior.java | 10 +- .../bench4q/agent/test/model/ModelTest.java | 24 +++ .../agent/test/scenario/Test_Behavior.java | 11 +- .../RecordScriptTestCase/baidu.html | 8 +- .../RecordScriptTestCase/baidu.html | 17 ++ .../models/agent/scriptrecord/BatchModel.java | 13 +- .../agent/scriptrecord/BehaviorModel.java | 5 +- .../agent/scriptrecord/IfBehaviorModel.java | 8 +- .../scriptrecord/PluginedBehaviorModel.java | 70 +++++++ .../AgentManagerMessagerTest.java | 102 --------- .../test/masterMessager/MessagerTestBase.java | 29 --- .../masterMessager/MonitorMessageTest.java | 83 -------- .../masterMessager/ParamInfoModel_Test.java | 29 --- .../masterMessager/PluginMessageTest.java | 127 ----------- .../test/masterMessager/PortMessageTest.java | 101 --------- .../masterMessager/ScriptMessagerTest.java | 197 ------------------ .../masterMessager/TestPlanMessageTest.java | 176 ---------------- .../test/masterMessager/UserMessageTest.java | 104 --------- 19 files changed, 143 insertions(+), 973 deletions(-) create mode 100644 Bench4Q-Recorder/RecordScriptTestCase/baidu.html create mode 100644 Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/PluginedBehaviorModel.java delete mode 100644 Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/AgentManagerMessagerTest.java delete mode 100644 Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/MessagerTestBase.java delete mode 100644 Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/MonitorMessageTest.java delete mode 100644 Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/ParamInfoModel_Test.java delete mode 100644 Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/PluginMessageTest.java delete mode 100644 Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/PortMessageTest.java delete mode 100644 Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/ScriptMessagerTest.java delete mode 100644 Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/TestPlanMessageTest.java delete mode 100644 Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/UserMessageTest.java diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/HttpPlugin.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/HttpPlugin.java index 12d8f317..a70d27fd 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/HttpPlugin.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/HttpPlugin.java @@ -232,7 +232,7 @@ public class HttpPlugin extends ParameterBarn { long contentLength = 0; String contentType = ""; try { - System.out.println(method.getURI().toString()); + // System.out.println(method.getURI().toString()); responseCode = this.getHttpClient().executeMethod(method); method.getStatusLine().toString(); Header[] responseHeaders = method.getResponseHeaders(); diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/node/ConditionBehavior.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/node/ConditionBehavior.java index f0bb86fc..4a9efd51 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/node/ConditionBehavior.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/node/ConditionBehavior.java @@ -6,12 +6,18 @@ import java.util.Stack; import org.bench4q.agent.datacollector.DataCollector; import org.bench4q.agent.scenario.instruction.Instruction; import org.bench4q.agent.scenario.instruction.TestInstruction; -import org.bench4q.share.models.agent.scriptrecord.ConditionBehaviorModel; +import org.bench4q.share.exception.Bench4QRunTimeException; +import org.bench4q.share.models.agent.scriptrecord.BehaviorModel; import org.bench4q.share.models.agent.statistics.BehaviorBriefModel; public class ConditionBehavior extends PluginImplementBehavior { - public ConditionBehavior(ConditionBehaviorModel condition) { + public ConditionBehavior(BehaviorModel condition) { + if (!condition.getType().equalsIgnoreCase(TEST_BEHAVIOR)) { + throw new Bench4QRunTimeException( + "Expected type is TEST_BEHAVIOR, but is " + + condition.getType()); + } buildAndGenerateParameterPart(condition); } diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/model/ModelTest.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/model/ModelTest.java index b11ce4b3..a76aeff3 100644 --- a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/model/ModelTest.java +++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/model/ModelTest.java @@ -2,12 +2,19 @@ package org.bench4q.agent.test.model; import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlElements; import javax.xml.bind.annotation.XmlRootElement; +import org.bench4q.share.helper.MarshalHelper; import org.bench4q.share.models.agent.scriptrecord.BehaviorModel; +import org.bench4q.share.models.agent.scriptrecord.IfBehaviorModel; import org.junit.Test; import static org.junit.Assert.*; @@ -27,4 +34,21 @@ public class ModelTest { assertTrue(object instanceof BehaviorModel); } + @Test + public void testMarshalInheritence() { + Container batchModel = new Container(); + batchModel.behaviorModels.add(new IfBehaviorModel()); + batchModel.behaviorModels.add(new BehaviorModel()); + System.out.println(MarshalHelper.tryMarshal(batchModel)); + } + + @XmlRootElement + private static class Container { + @XmlElementWrapper(name = "behaviorModels") + @XmlElements({ + @XmlElement(name = "behavior", type = BehaviorModel.class), + @XmlElement(name = "ifBehavior", type = IfBehaviorModel.class) }) + private List behaviorModels = new ArrayList(); + + } } diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/scenario/Test_Behavior.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/scenario/Test_Behavior.java index 21cd51ef..1dbaff6f 100644 --- a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/scenario/Test_Behavior.java +++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/scenario/Test_Behavior.java @@ -83,11 +83,12 @@ public class Test_Behavior { @Test public void testCompileIfBehavior2Instruction() { + // TODO: List elseBehaviors = new ArrayList(), thenBehaviors = new ArrayList(); - // Behavior behavior = - // Behavior.buildWith(BehaviorModel.IfBehaviorBuilder( - // BehaviorModel.testBehaviorBuilder(1, "isDefined", "context", - // Arrays.asList(ParameterModel.createParameter("name", - // "a"))), thenBehaviors, elseBehaviors)); + Behavior behavior = Behavior.buildWith(BehaviorModel.IfBehaviorBuilder( + BehaviorModel.testBehaviorBuilder(1, "isDefined", "context", + Arrays.asList(ParameterModel.createParameter("name", + "a"))), thenBehaviors, elseBehaviors)); + assertNotNull(behavior); } } diff --git a/Bench4Q-Master/RecordScriptTestCase/baidu.html b/Bench4Q-Master/RecordScriptTestCase/baidu.html index 0ed0a974..8824626a 100644 --- a/Bench4Q-Master/RecordScriptTestCase/baidu.html +++ b/Bench4Q-Master/RecordScriptTestCase/baidu.html @@ -1,7 +1 @@ - - - - - - - + + Bench4Q Test Case + + + + + + No this one + No this one + No this one + + + + + + getBehaviors() { return behaviors; @@ -50,12 +54,13 @@ public class BatchModel { public void setBehaviors(List behaviors) { this.behaviors = behaviors; } - - public BatchModel(int id){ + + public BatchModel(int id) { this.id = id; this.behaviors = new ArrayList(); } - public BatchModel(){ - + + public BatchModel() { + } } diff --git a/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/BehaviorModel.java b/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/BehaviorModel.java index a66371de..adf61716 100644 --- a/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/BehaviorModel.java +++ b/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/BehaviorModel.java @@ -108,8 +108,9 @@ public class BehaviorModel { } public static BehaviorModel IfBehaviorBuilder( - BehaviorModel testBehaviorBuilder) { - // TODo: + BehaviorModel testBehaviorBuilder, + List thenBehaviors, List elseBehaviors) { + // TODO: return null; } diff --git a/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/IfBehaviorModel.java b/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/IfBehaviorModel.java index 453ca241..35e69818 100644 --- a/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/IfBehaviorModel.java +++ b/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/IfBehaviorModel.java @@ -6,18 +6,18 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; -@XmlRootElement +@XmlRootElement(name = "ifBehaviorModel") public class IfBehaviorModel extends BehaviorModel { - private ConditionBehaviorModel condition; + private BehaviorModel condition; private List thenBehaviors; private List elseBehaviors; @XmlElement - public ConditionBehaviorModel getCondition() { + public BehaviorModel getCondition() { return condition; } - public void setCondition(ConditionBehaviorModel condition) { + public void setCondition(BehaviorModel condition) { this.condition = condition; } diff --git a/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/PluginedBehaviorModel.java b/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/PluginedBehaviorModel.java new file mode 100644 index 00000000..67412c6e --- /dev/null +++ b/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/PluginedBehaviorModel.java @@ -0,0 +1,70 @@ +package org.bench4q.share.models.agent.scriptrecord; + +import java.util.List; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; + +import org.bench4q.share.models.agent.ParameterModel; + +@XmlRootElement +public class PluginedBehaviorModel extends BehaviorModel { + private String use; + private String name; + private String type; + private List parameters; + + @XmlElement + public String getUse() { + return use; + } + + public void setUse(String use) { + this.use = use; + } + + @XmlElement + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @XmlElement + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + @XmlElementWrapper(name = "parameters") + @XmlElement(name = "parameter") + public List getParameters() { + return parameters; + } + + public void setParameters(List parameters) { + this.parameters = parameters; + } + + @XmlRootElement + public static class UserBehaviorModel extends PluginedBehaviorModel { + } + + @XmlRootElement + public static class TimerBehaviorModel extends PluginedBehaviorModel { + } + + @XmlRootElement + public static class ControlBehaviorModel extends PluginedBehaviorModel { + } + + @XmlRootElement + public static class ConditionBehaviorModel extends PluginedBehaviorModel { + } +} diff --git a/Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/AgentManagerMessagerTest.java b/Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/AgentManagerMessagerTest.java deleted file mode 100644 index b9f8f37d..00000000 --- a/Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/AgentManagerMessagerTest.java +++ /dev/null @@ -1,102 +0,0 @@ -package org.bench4q.web.test.masterMessager; - -import static com.github.tomakehurst.wiremock.client.WireMock.*; -import static org.junit.Assert.*; - -import org.bench4q.share.helper.MarshalHelper; -import org.bench4q.share.models.master.AgentModel; -import org.bench4q.share.models.master.AgentResponseModel; -import org.bench4q.web.masterMessager.AgentManagerMessager; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = { "file:src/test/resources/bench4qweb-servlet.xml" }) -public class AgentManagerMessagerTest extends MessagerTestBase { - private AgentManagerMessager agentManagerMessager; - private String baseUrl = "/agentManage"; - - public AgentManagerMessager getAgentManagerMessager() { - return agentManagerMessager; - } - - @Autowired - public void setAgentManagerMessager( - AgentManagerMessager agentManagerMessager) { - this.agentManagerMessager = agentManagerMessager; - } - - @BeforeClass - public static void setUp() { - startServer(); - } - - @AfterClass - public static void clear() { - stopServer(); - } - - @Test - public void test_addAgent() { - String url = baseUrl + "/addAgentToPool"; - - this.getWireMock().register( - post(urlEqualTo(url)) - .withRequestBody( - equalToXml(MarshalHelper - .tryMarshal(createAgentModel()))) - .willReturn( - aResponse() - .withStatus(200) - .withHeader("Content-Type", - "application/xml") - .withBody(this.createResponse()))); - assertNotNull(this.agentManagerMessager.addAgent(null, - MarshalHelper.tryMarshal(createAgentModel()))); - } - - private AgentModel createAgentModel() { - AgentModel agentModel = new AgentModel(); - agentModel.setMaxLoad(500); - agentModel.setPort(6565); - return agentModel; - } - - @Test - public void test_deleteAgent() { - String url = baseUrl + "/removeAgentFromPool?hostName=&agentId="; - this.getWireMock().register( - get(urlEqualTo(url)).willReturn( - aResponse().withStatus(200) - .withHeader("Content-Type", "text/xml") - .withBody(this.createResponse()))); - assertNotNull(this.agentManagerMessager.deleteAgent(null, "", "")); - assertTrue(this.agentManagerMessager.deleteAgent(null, "", "") - .isSuccess()); - } - - @Test - public void test_loadAgents() { - String url = baseUrl + "/queryAgentList"; - this.getWireMock().register( - get(urlEqualTo(url)).willReturn( - aResponse().withStatus(200) - .withHeader("Content-Type", "text/xml") - .withBody(this.createResponse()))); - assertNotNull(this.agentManagerMessager.loadAgents(null)); - assertTrue(this.agentManagerMessager.loadAgents(null).isSuccess()); - } - - private String createResponse() { - AgentResponseModel agentResponseModel = new AgentResponseModel(); - agentResponseModel.setSuccess(true); - return MarshalHelper.tryMarshal(agentResponseModel); - - } - -} diff --git a/Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/MessagerTestBase.java b/Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/MessagerTestBase.java deleted file mode 100644 index c2a076a5..00000000 --- a/Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/MessagerTestBase.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.bench4q.web.test.masterMessager; - -import com.github.tomakehurst.wiremock.WireMockServer; -import com.github.tomakehurst.wiremock.client.WireMock; -import com.github.tomakehurst.wiremock.core.WireMockConfiguration; - -public abstract class MessagerTestBase { - private static WireMockServer wireMockServer; - private static WireMock wireMock; - private static final int port = 6000; - - protected static void startServer() { - WireMockConfiguration wmc = new WireMockConfiguration(); - wmc.bindAddress("localhost"); - wmc.port(port); - wireMockServer = new WireMockServer(wmc); - wireMockServer.start(); - wireMock = new WireMock("localhost", port); - } - - protected static void stopServer() { - wireMockServer.stop(); - } - - public WireMock getWireMock() { - return wireMock; - } - -} diff --git a/Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/MonitorMessageTest.java b/Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/MonitorMessageTest.java deleted file mode 100644 index 9fa2d031..00000000 --- a/Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/MonitorMessageTest.java +++ /dev/null @@ -1,83 +0,0 @@ -//package org.bench4q.web.test.masterMessager; -// -//import static com.github.tomakehurst.wiremock.client.WireMock.*; -// -//import static org.junit.Assert.*; -// -//import org.bench4q.share.helper.MarshalHelper; -//import org.bench4q.share.models.master.MonitorMemoryResponseModel; -//import org.bench4q.share.models.master.MonitorProcessorResponseModel; -//import org.bench4q.web.masterMessager.MonitorMessager; -// -//import org.junit.AfterClass; -//import org.junit.BeforeClass; -//import org.junit.Test; -//import org.junit.runner.RunWith; -// -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.test.context.ContextConfiguration; -//import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -// -//@RunWith(SpringJUnit4ClassRunner.class) -//@ContextConfiguration("file:src/test/resources/bench4qweb-servlet.xml") -//public class MonitorMessageTest extends MessagerTestBase { -// private MonitorMessager monitorMessager; -// private String baseUrl = "/monitorController"; -// -// public MonitorMessager getMonitorMessager() { -// return monitorMessager; -// } -// -// @Autowired -// public void setMonitorMessager(MonitorMessager monitorMessager) { -// this.monitorMessager = monitorMessager; -// } -// -// @BeforeClass -// public static void setUp() { -// startServer(); -// } -// -// @AfterClass -// public static void clear() { -// stopServer(); -// } -// -// @Test -// public void test_memory() { -// String url = baseUrl + "/memorySUTInfo"; -// MonitorMemoryResponseModel monitorMemoryResponseModel = new MonitorMemoryResponseModel(); -// String response = MarshalHelper.tryMarshal(monitorMemoryResponseModel); -// this.getWireMock().register( -// post(urlEqualTo(url)) -// .withRequestBody(containing("testPlanId")) -// .withRequestBody(containing("hostName")) -// .withRequestBody(containing("port")) -// .withRequestBody(containing("duationBegin")) -// .willReturn( -// aResponse().withStatus(200) -// .withHeader("Content-Type", "text/xml") -// .withBody(response))); -// assertNotNull(this.monitorMessager.memory(null, "", "", "", "")); -// } -// -// @Test -// public void test_porcessor() { -// String url = baseUrl + "/processorSUTInfo"; -// MonitorProcessorResponseModel monitorProcessorResponseModel = new MonitorProcessorResponseModel(); -// String response = MarshalHelper -// .tryMarshal(monitorProcessorResponseModel); -// this.getWireMock().register( -// post(urlEqualTo(url)) -// .withRequestBody(containing("testPlanId")) -// .withRequestBody(containing("hostName")) -// .withRequestBody(containing("port")) -// .withRequestBody(containing("duationBegin")) -// .willReturn( -// aResponse().withStatus(200) -// .withHeader("Content-Type", "text/xml") -// .withBody(response))); -// assertNotNull(this.monitorMessager.porcessor(null, "", "", "", "")); -// } -// -//} diff --git a/Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/ParamInfoModel_Test.java b/Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/ParamInfoModel_Test.java deleted file mode 100644 index 0e837d45..00000000 --- a/Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/ParamInfoModel_Test.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.bench4q.web.test.masterMessager; - -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; - -@XmlRootElement -public class ParamInfoModel_Test { - private String label; - private String name; - - @XmlElement - public String getLabel() { - return label; - } - - public void setLable(String label) { - this.label = label; - } - - @XmlElement - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - -} diff --git a/Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/PluginMessageTest.java b/Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/PluginMessageTest.java deleted file mode 100644 index a1336a24..00000000 --- a/Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/PluginMessageTest.java +++ /dev/null @@ -1,127 +0,0 @@ -package org.bench4q.web.test.masterMessager; - -import static com.github.tomakehurst.wiremock.client.WireMock.*; - -import static org.junit.Assert.*; - -import org.bench4q.share.helper.MarshalHelper; -import org.bench4q.share.models.master.plugin.PluginResponseModel; -import org.bench4q.web.masterMessager.PluginMessager; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration("file:src/test/resources/bench4qweb-servlet.xml") -public class PluginMessageTest extends MessagerTestBase { - private String pluginName = "pluginName"; - private PluginMessager pluginMessager; - private String baseUrl = "/plugin"; - - public PluginMessager getPluginMessager() { - return pluginMessager; - } - - @Autowired - public void setPluginMessager(PluginMessager pluginMessager) { - this.pluginMessager = pluginMessager; - } - - @BeforeClass - public static void setUp() { - startServer(); - } - - @AfterClass - public static void clear() { - stopServer(); - } - - @Test - public void test_loadPluginUIModels() { - String url = baseUrl + "/loadPluginList"; - this.getWireMock().register( - get(urlEqualTo(url)).willReturn( - aResponse().withStatus(200) - .withHeader("Content-Type", "text/xml") - .withBody(this.createResponse()))); - assertNotNull(this.pluginMessager.loadPluginUIModels(null)); - assertTrue(this.pluginMessager.loadPluginUIModels(null).isSuccess()); - } - - @Test - public void test_loadPluginNameList() { - String url = baseUrl + "/loadPluginNameList"; - this.getWireMock().register( - get(urlEqualTo(url)).willReturn( - aResponse().withStatus(200) - .withHeader("Content-Type", "text/xml") - .withBody(this.createResponse()))); - assertNotNull(this.pluginMessager.loadPluginNameList(null)); - assertTrue(this.pluginMessager.loadPluginNameList(null).isSuccess()); - } - - @Test - public void test_getPluginInfoModel() { - String url = baseUrl + "/getPlugin/" + pluginName; - this.getWireMock().register( - get(urlEqualTo(url)).willReturn( - aResponse().withStatus(200) - .withHeader("Content-Type", "text/xml") - .withBody(this.createResponse()))); - assertNotNull(this.pluginMessager.getPluginInfoModel(null, pluginName)); - assertTrue(this.pluginMessager.getPluginInfoModel(null, pluginName) - .isSuccess()); - } - - @Test - public void test_loadBehaviors() { - String url = baseUrl + "/loadBehaviors/" + pluginName; - this.getWireMock().register( - get(urlEqualTo(url)).willReturn( - aResponse().withStatus(200) - .withHeader("Content-Type", "text/xml") - .withBody(this.createResponse()))); - assertNotNull(this.pluginMessager.loadBehaviors(null, pluginName)); - assertTrue(this.pluginMessager.loadBehaviors(null, pluginName) - .isSuccess()); - } - - @Test - public void test_addPlugin() { - String url = baseUrl + "/addPlugin"; - this.getWireMock().register( - put(urlEqualTo(url)).willReturn( - aResponse().withStatus(200) - .withHeader("Content-Type", "text/xml") - .withBody(this.createResponse()))); - assertNotNull(this.pluginMessager.addPlugin(null, "")); - assertTrue(this.pluginMessager.addPlugin(null, "").isSuccess()); - } - - @Test - public void test_deletePlugin() { - String url = baseUrl + "/deletePlugin/" + pluginName; - this.getWireMock().register( - get(urlEqualTo(url)).willReturn( - aResponse().withStatus(200) - .withHeader("Content-Type", "text/xml") - .withBody(this.createResponse()))); - assertNotNull(this.pluginMessager.deletePlugin(null, pluginName)); - assertTrue(this.pluginMessager.deletePlugin(null, pluginName) - .isSuccess()); - } - - public String createResponse() { - PluginResponseModel pluginResponseModel = new PluginResponseModel(); - pluginResponseModel.setSuccess(true); - return MarshalHelper.tryMarshal(pluginResponseModel); - } - -} diff --git a/Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/PortMessageTest.java b/Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/PortMessageTest.java deleted file mode 100644 index b1b28761..00000000 --- a/Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/PortMessageTest.java +++ /dev/null @@ -1,101 +0,0 @@ -package org.bench4q.web.test.masterMessager; - -import static com.github.tomakehurst.wiremock.client.WireMock.*; - -import static org.junit.Assert.*; - -import java.io.IOException; - -import javax.xml.bind.JAXBException; - -import org.bench4q.share.helper.MarshalHelper; -import org.bench4q.share.models.master.OrganizeRecordPortResponseModel; -import org.bench4q.web.masterMessager.RecordPortMessager; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = { "file:src/test/resources/bench4qweb-servlet.xml" }) -public class PortMessageTest extends MessagerTestBase { - - private RecordPortMessager recordPortMessager; - - public RecordPortMessager getRecordPortMessager() { - return recordPortMessager; - } - - @Autowired - public void setRecordPortMessager(RecordPortMessager recordPortMessager) { - this.recordPortMessager = recordPortMessager; - } - - @BeforeClass - public static void setUp() { - - startServer(); - } - - @AfterClass - public static void shutDowm() { - stopServer(); - } - - @Test - public void test_addPort() throws IOException, JAXBException { - - this.getWireMock().register(post(urlEqualTo("/RecordPort/addPortToPortPool")) - .withRequestBody(containing("port")).willReturn( - aResponse().withStatus(200) - .withHeader("Content-Type", "text/xml") - .withBody(this.createResponse()))); - OrganizeRecordPortResponseModel responseModel = recordPortMessager - .addPort(null, "8090"); - assertNotNull(responseModel); - assertTrue(responseModel.isSuccess()); - } - - @Test - public void test_deletePort() throws JAXBException { - this.getWireMock().register(post(urlEqualTo("/RecordPort/removePortFromPool")) - .withRequestBody(containing("port")).willReturn( - aResponse().withStatus(200) - .withHeader("Content-Type", "text/xml") - .withBody(this.createResponse()))); - OrganizeRecordPortResponseModel responseModel = recordPortMessager - .deletePort(null, "8090"); - assertNotNull(responseModel); - assertTrue(responseModel.isSuccess()); - } - - @Test - public void test_loadPorts() throws JAXBException { - this.getWireMock().register(post(urlEqualTo("/RecordPort/loadPortList")) - .willReturn( - aResponse().withStatus(200) - .withHeader("Content-Type", "text/xml") - .withBody(this.createResponse()))); - OrganizeRecordPortResponseModel responseModel = recordPortMessager - .loadPorts(null); - assertNotNull(responseModel); - assertTrue(responseModel.isSuccess()); - assertNotNull(responseModel.getPortModels()); - } - - private String createResponse() throws JAXBException { - OrganizeRecordPortResponseModel organizeRecordPortResponseModel = new OrganizeRecordPortResponseModel(); - organizeRecordPortResponseModel.setSuccess(true); - - String response = MarshalHelper.marshal( - OrganizeRecordPortResponseModel.class, - organizeRecordPortResponseModel); - return response; - } - -} diff --git a/Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/ScriptMessagerTest.java b/Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/ScriptMessagerTest.java deleted file mode 100644 index 3591ae9f..00000000 --- a/Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/ScriptMessagerTest.java +++ /dev/null @@ -1,197 +0,0 @@ -package org.bench4q.web.test.masterMessager; - -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.containing; -import static com.github.tomakehurst.wiremock.client.WireMock.post; -import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -import org.bench4q.share.helper.MarshalHelper; -import org.bench4q.share.models.master.OperateScriptServerResponseModel; -import org.bench4q.share.models.master.ScriptModel; -import org.bench4q.web.masterMessager.ScriptMessager; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = { "file:src/test/resources/bench4qweb-servlet.xml" }) -public class ScriptMessagerTest extends MessagerTestBase { - private ScriptMessager scriptMessager; - private String port = "8090"; - private String baseUrl = "/script"; - - public ScriptMessager getScriptMessager() { - return scriptMessager; - } - - @Autowired - public void setScriptMessager(ScriptMessager scriptMessager) { - this.scriptMessager = scriptMessager; - } - - @BeforeClass - public static void setUp() { - startServer(); - } - - @AfterClass - public static void clear() { - stopServer(); - } - - @Test - public void test_StartScriptRecordPort() { - - String url = this.baseUrl + "/startScriptRecordServer"; - this.getWireMock().register( - post(urlEqualTo(url)).willReturn( - aResponse().withStatus(200) - .withHeader("Content-Type", "text/xml") - .withBody(this.createResponse()))); - assertNotNull(this.getScriptMessager().startScriptRecordServer(null)); - assertTrue(this.getScriptMessager().startScriptRecordServer(null) - .isSuccess()); - - } - - @Test - public void test_stopScriptRecordServer() { - String url = this.baseUrl + "/stopScriptRecordServer"; - this.getWireMock().register( - post(urlEqualTo(url)) - .withRequestBody(containing("port")) - .withRequestBody(containing("fileNameUUID")) - .willReturn( - aResponse().withStatus(200) - .withHeader("Content-Type", "text/xml") - .withBody(this.createResponse()))); - - assertNotNull(this.getScriptMessager().stopScriptRecordServer(null, - port, "")); - assertTrue(this.getScriptMessager() - .stopScriptRecordServer(null, port, "").isSuccess()); - } - - @Test - public void test_saveScriptRecorded() { - String url = this.baseUrl + "/saveScriptToDB"; - this.getWireMock().register( - post(urlEqualTo(url)) - .withRequestBody(containing("scriptName")) - .withRequestBody(containing("port")) - .withRequestBody(containing("fileNameUUID")) - .willReturn( - aResponse().withStatus(200) - .withHeader("Content-Type", "text/xml") - .withBody(this.createResponse()))); - assertNotNull(this.getScriptMessager().saveScriptRecorded(null, "", - port, "")); - assertTrue(this.getScriptMessager() - .saveScriptRecorded(null, "", port, "").isSuccess()); - } - - @Test - public void test_uploadScript() { - String scriptName = "scriptName"; - String url = this.baseUrl + "/uploadScript/" + scriptName; - this.getWireMock().register( - post(urlEqualTo(url)).willReturn( - aResponse().withStatus(200) - .withHeader("Content-Type", "text/xml") - .withBody(this.createResponse()))); - assertNotNull(this.getScriptMessager().uploadScript(null, scriptName, - "", null)); - assertTrue(this.getScriptMessager() - .uploadScript(null, scriptName, "", null).isSuccess()); - } - - @Test - public void test_deleteScript() { - String url = this.baseUrl + "/deleteScript"; - this.getWireMock().register( - post(urlEqualTo(url)).withRequestBody(containing("scriptId")) - .willReturn( - aResponse().withStatus(200) - .withHeader("Content-Type", "text/xml") - .withBody(this.createResponse()))); - assertNotNull(this.getScriptMessager().deleteScript(null, "")); - assertTrue(this.getScriptMessager().deleteScript(null, "").isSuccess()); - } - - @Test - public void test_updateScript() { - String scriptId = UUID.randomUUID().toString(); - String url = this.baseUrl + "/updateScript/" + scriptId; - this.getWireMock().register( - post(urlEqualTo(url)).withRequestBody(containing("content")) - .willReturn( - aResponse().withStatus(200) - .withHeader("Content-Type", "text/xml") - .withBody(this.createResponse()))); - assertNotNull(this.getScriptMessager().updateScript(null, scriptId, "",null)); - assertTrue(this.getScriptMessager().updateScript(null, scriptId, "",null) - .isSuccess()); - } - - @Test - public void test_loadScript() { - String url = this.baseUrl + "/loadScriptList"; - this.getWireMock().register( - post(urlEqualTo(url)).willReturn( - aResponse().withStatus(200) - .withHeader("Content-Type", "text/xml") - .withBody(this.createResponse()))); - assertNotNull(this.getScriptMessager().loadScripts(null)); - assertTrue(this.getScriptMessager().loadScripts(null).isSuccess()); - } - - @Test - public void test_queryScriptById() { - String url = this.baseUrl + "/queryScriptById"; - this.getWireMock().register( - post(urlEqualTo(url)).withRequestBody(containing("scriptId")) - .willReturn( - aResponse().withStatus(200) - .withHeader("Content-Type", "text/xml") - .withBody(this.createResponse()))); - assertNotNull(this.getScriptMessager().queryScriptById(null, "")); - assertTrue(this.getScriptMessager().queryScriptById(null, "") - .isSuccess()); - } - - @Test - public void test_queryScriptByName() { - String url = this.baseUrl + "/queryScriptByName"; - this.getWireMock().register( - post(urlEqualTo(url)).withRequestBody(containing("name")) - .willReturn( - aResponse().withStatus(200) - .withHeader("Content-Type", "text/xml") - .withBody(this.createResponse()))); - assertNotNull(this.getScriptMessager().queryScriptByName(null, "")); - assertTrue(this.getScriptMessager().queryScriptByName(null, "") - .isSuccess()); - } - - private String createResponse() { - ScriptModel scriptModel=new ScriptModel(); - List list=new ArrayList(); - list.add(scriptModel); - OperateScriptServerResponseModel operateScriptServerResponseModel = new OperateScriptServerResponseModel(); - operateScriptServerResponseModel.setSuccess(true); - operateScriptServerResponseModel.setScriptModels(list); - return MarshalHelper.tryMarshal(operateScriptServerResponseModel); - - } - -} diff --git a/Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/TestPlanMessageTest.java b/Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/TestPlanMessageTest.java deleted file mode 100644 index 8cbda5e9..00000000 --- a/Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/TestPlanMessageTest.java +++ /dev/null @@ -1,176 +0,0 @@ -package org.bench4q.web.test.masterMessager; - -import static com.github.tomakehurst.wiremock.client.WireMock.*; - -import static org.junit.Assert.*; - -import org.bench4q.share.helper.MarshalHelper; -import org.bench4q.share.models.master.TestPlanResponseModel; -import org.bench4q.share.models.master.TestPlanResultModel; -import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel; -import org.bench4q.web.masterMessager.TestPlanMessager; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration("file:src/test/resources/bench4qweb-servlet.xml") -public class TestPlanMessageTest extends MessagerTestBase { - private TestPlanMessager testPlanMessager; - private String baseUrl = "/testPlan"; - private String testPlanId = "testPlanId"; - private String scriptId = "scriptId"; - - public TestPlanMessager getTestPlanMessager() { - return testPlanMessager; - } - - @Autowired - public void setTestPlanMessager(TestPlanMessager testPlanMessager) { - this.testPlanMessager = testPlanMessager; - } - - @BeforeClass - public static void setUp() { - startServer(); - } - - @AfterClass - public static void clear() { - stopServer(); - } - - @Test - public void test_runTestPlan() { - String url = baseUrl + "/run"; - this.getWireMock().register( - post(urlEqualTo(url)).willReturn( - aResponse().withStatus(200) - .withHeader("Content-Type", "text/xml") - .withBody(this.createResponse()))); - assertNotNull(this.testPlanMessager.runTestPlan(null, "")); - } - - @Test - public void test_getRunningTestInfo() { - String url = baseUrl + "/getRunningInfo"; - this.getWireMock().register( - post(urlEqualTo(url)).withRequestBody(containing("testPlanId")) - .willReturn( - aResponse().withStatus(200) - .withHeader("Content-Type", "text/xml") - .withBody(this.createResponse()))); - assertNotNull(this.testPlanMessager.getRunningTestInfo(null, "")); - } - - // @Test - // public void test_getScriptBriefResult() { - // TestPlanScriptBriefResultModel testPlanScriptBriefResultModel = new - // TestPlanScriptBriefResultModel(); - // String response = MarshalHelper - // .tryMarshal(testPlanScriptBriefResultModel); - // String url = baseUrl + '/' + testPlanId + '/' + scriptId + '/' - // + duationBegin; - // System.out.println(url); - // this.getWireMock().register( - // get(urlEqualTo(url)).willReturn( - // aResponse().withStatus(200) - // .withHeader("Content-Type", "text/xml") - // .withBody(response))); - // assertNotNull(this.testPlanMessager.getScriptBriefResult(null, - // testPlanId, scriptId, duationBegin)); - // } - - @Test - public void test_getScriptBehaviorsBriefResult() { - ScriptBehaviorsBriefModel scriptBehaviorsBriefModel = new ScriptBehaviorsBriefModel(); - scriptBehaviorsBriefModel.setFinished(true); - String response = MarshalHelper.tryMarshal(scriptBehaviorsBriefModel); - String url = baseUrl +"/getBehaviorsBrief"+ '/' + testPlanId + '/' + scriptId; - this.getWireMock().register( - get(urlEqualTo(url)).willReturn( - aResponse().withStatus(200) - .withHeader("Content-Type", "text/xml") - .withBody(response))); - assertNotNull(this.testPlanMessager.getScriptBehaviorsBriefResult(null, - testPlanId, scriptId)); - assertTrue(this.testPlanMessager.getScriptBehaviorsBriefResult(null, - testPlanId, scriptId).isFinished()); - } - -// @Test -// public void test_getPageBriefResult() { -// ScriptPagesBriefModel scriptPagesBriefModel = new ScriptPagesBriefModel(); -// String response = MarshalHelper.tryMarshal(scriptPagesBriefModel); -// String url = baseUrl + '/' + testPlanId + '/' + scriptId; -// this.getWireMock().register( -// get(urlEqualTo(url)).willReturn( -// aResponse().withStatus(200) -// .withHeader("Content-Type", "text/xml") -// .withBody(response))); -// assertNotNull(this.testPlanMessager.getPageBriefResult(null, -// testPlanId, scriptId)); -// } - -// @Test -// public void test_queryTestPlanById() { -// String testPlanRunId = "testPlanRunId"; -// String url = baseUrl + "/queryTestPlan/" + testPlanRunId; -// this.getWireMock().register( -// get(urlEqualTo(url)).willReturn( -// aResponse().withStatus(200) -// .withHeader("Content-Type", "text/xml") -// .withBody(this.createResponse()))); -// assertNotNull(this.testPlanMessager.queryTestPlanById(null, -// testPlanRunId)); -// } - - @Test - public void test_deleteTestPlan() { - TestPlanResponseModel testPlanResponseModel = new TestPlanResponseModel(); - testPlanResponseModel.setSuccess(true); - String response = MarshalHelper.tryMarshal(testPlanResponseModel); - String url = baseUrl + "/removeTestPlanFromPool"; - this.getWireMock().register( - post(urlEqualTo(url)).withRequestBody(containing("testPlanId")) - .willReturn( - aResponse().withStatus(200) - .withHeader("Content-Type", "text/xml") - .withBody(response))); - assertNotNull(this.testPlanMessager.deleteTestPlan(null, testPlanId)); - assertTrue(this.testPlanMessager.deleteTestPlan(null, testPlanId) - .isSuccess()); - } - - @Test - public void test_loadTestPlans() { - String url = baseUrl + "/loadTestPlans"; - TestPlanResponseModel testPlanResponseModel = new TestPlanResponseModel(); - testPlanResponseModel.setSuccess(true); - String response = MarshalHelper.tryMarshal(testPlanResponseModel); - this.getWireMock().register( - post(urlEqualTo(url)).willReturn( - aResponse().withStatus(200) - .withHeader("Content-Type", "text/xml") - .withBody(response))); - assertNotNull(this.testPlanMessager.loadTestPlans(null)); - assertTrue(this.testPlanMessager.loadTestPlans(null).isSuccess()); - - } - - @Test - public void test_getTestPlanReport() { - - } - - public String createResponse() { - TestPlanResultModel testPlanResultModel = new TestPlanResultModel(); - return MarshalHelper.tryMarshal(testPlanResultModel); - } -} diff --git a/Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/UserMessageTest.java b/Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/UserMessageTest.java deleted file mode 100644 index 288dafc7..00000000 --- a/Bench4Q-Web/src/test/java/org/bench4q/web/test/masterMessager/UserMessageTest.java +++ /dev/null @@ -1,104 +0,0 @@ -package org.bench4q.web.test.masterMessager; - -import static com.github.tomakehurst.wiremock.client.WireMock.*; - -import static org.junit.Assert.*; - -import org.bench4q.share.helper.MarshalHelper; -import org.bench4q.share.models.master.AuthorizeResponseModel; -import org.bench4q.share.models.master.RegisterResponseModel; - -import org.bench4q.web.masterMessager.UserMessager; -import org.junit.AfterClass; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration("file:src/test/resources/bench4qweb-servlet.xml") -public class UserMessageTest extends MessagerTestBase { - private UserMessager userMessager; - private String baseUrl = "/user"; - - public UserMessager getUserMessager() { - return userMessager; - } - - @Autowired - public void setUserMessager(UserMessager userMessager) { - this.userMessager = userMessager; - } - - @BeforeClass - public static void setUp() { - startServer(); - } - - @AfterClass - public static void clear() { - stopServer(); - } - - @Test - public void test_register() { - String url = baseUrl + "/register?scope=&userName=&password="; - RegisterResponseModel registerResponseModel = new RegisterResponseModel(); - registerResponseModel.setSuccess(true); - String response = MarshalHelper.tryMarshal(registerResponseModel); - this.getWireMock().register( - get(urlEqualTo(url)).willReturn( - aResponse().withStatus(200) - .withHeader("Content-Type", "text/xml") - .withBody(response))); - assertNotNull(this.userMessager.register("", "", "")); - assertTrue(this.userMessager.register("", "", "").isSuccess()); - } - - @Test - public void test_adminLogin() { - String url = baseUrl + "/adminAuthorize?userName=&password="; - this.getWireMock().register( - get(urlEqualTo(url)).willReturn( - aResponse().withStatus(200) - .withHeader("Content-Type", "text/xml") - .withBody(this.createResponse()))); - assertNotNull(this.userMessager.adminLogin("", "")); - assertTrue(this.userMessager.adminLogin("", "").isSuccess()); - } - - @Test - public void test_normalLogin() { - String url = baseUrl + "/normalAuthorize?userName=&password="; - this.getWireMock().register( - get(urlEqualTo(url)).willReturn( - aResponse().withStatus(200) - .withHeader("Content-Type", "text/xml") - .withBody(this.createResponse()))); - assertNotNull(this.userMessager.normalLogin("", "")); - assertTrue(this.userMessager.normalLogin("", "").isSuccess()); - } - - @Test - public void test_deleteUser() { - String userName = "userName"; - String url = baseUrl + "/deleteUser/" + userName; - this.getWireMock().register( - get(urlEqualTo(url)).willReturn( - aResponse().withStatus(200) - .withHeader("Content-Type", "text/xml") - .withBody(this.createResponse()))); - assertNotNull(this.userMessager.deleteUser(userName)); - assertTrue(this.userMessager.deleteUser(userName).isSuccess()); - } - - public String createResponse() { - AuthorizeResponseModel authorizeResponseModel = new AuthorizeResponseModel(); - authorizeResponseModel.setSuccess(true); - return MarshalHelper.tryMarshal(authorizeResponseModel); - } -}