refa and add new tests
This commit is contained in:
parent
1d4b68d93d
commit
5c69fb1e62
|
@ -1,234 +1,243 @@
|
|||
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.entity.Agent;
|
||||
import org.bench4q.master.entity.Port;
|
||||
import org.bench4q.master.entity.Script;
|
||||
import org.bench4q.master.entity.TestPlanDB;
|
||||
import org.bench4q.master.entity.User;
|
||||
import org.bench4q.master.service.infrastructure.ScriptService;
|
||||
import org.bench4q.share.models.master.AgentModel;
|
||||
import org.bench4q.share.models.master.MonitorModel;
|
||||
import org.bench4q.share.models.master.PortModel;
|
||||
import org.bench4q.share.models.master.RunningAgentModel;
|
||||
import org.bench4q.share.models.master.RunningScriptModel;
|
||||
import org.bench4q.share.models.master.ScriptModel;
|
||||
import org.bench4q.share.models.master.TestPlanBusinessModel;
|
||||
import org.bench4q.share.models.master.TestPlanDBModel;
|
||||
import org.bench4q.share.models.master.UserModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class BusinessModelMapFactory {
|
||||
private ScriptService scriptService;
|
||||
|
||||
private ScriptService getScriptService() {
|
||||
return scriptService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setScriptService(ScriptService scriptService) {
|
||||
this.scriptService = scriptService;
|
||||
}
|
||||
|
||||
public static Agent toBusiness(AgentModel agentModel) {
|
||||
Agent agent = new Agent();
|
||||
agent.setCurrentStatus(agentModel.getCurrentStatus());
|
||||
agent.setHostName(agentModel.getHostName());
|
||||
agent.setId(agentModel.getId());
|
||||
agent.setMaxLoad(agentModel.getMaxLoad());
|
||||
agent.setPort(agentModel.getPort());
|
||||
agent.setRemainLoad(agentModel.getRemainLoad());
|
||||
return agent;
|
||||
}
|
||||
|
||||
public static AgentModel toModel(Agent agent) {
|
||||
AgentModel agentModel = new AgentModel();
|
||||
agentModel.setCurrentStatus(agent.getCurrentStatus());
|
||||
agentModel.setHostName(agent.getHostName());
|
||||
agentModel.setId(agent.getId());
|
||||
agentModel.setMaxLoad(agent.getMaxLoad());
|
||||
agentModel.setPort(agent.getPort());
|
||||
agentModel.setRemainLoad(agent.getRemainLoad());
|
||||
return agentModel;
|
||||
}
|
||||
|
||||
public static RunningAgent toBusiness(RunningAgentModel runningAgentModel) {
|
||||
RunningAgent runningAgent = new RunningAgent();
|
||||
runningAgent.setAgent(BusinessModelMapFactory
|
||||
.toBusiness(runningAgentModel.getAgent()));
|
||||
runningAgent.setAgentRunId(runningAgentModel.getAgentRunId());
|
||||
runningAgent.setLoadInUse(runningAgentModel.getLoadInUse());
|
||||
runningAgent.setScriptId(runningAgentModel.getScriptId());
|
||||
return runningAgent;
|
||||
}
|
||||
|
||||
public static RunningAgentModel toModel(RunningAgent runningAgent) {
|
||||
RunningAgentModel ret = new RunningAgentModel();
|
||||
ret.setAgent(BusinessModelMapFactory.toModel(runningAgent.getAgent()));
|
||||
ret.setAgentRunId(runningAgent.getAgentRunId());
|
||||
ret.setLoadInUse(runningAgent.getLoadInUse());
|
||||
ret.setScriptId(runningAgent.getScriptId());
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static RunningScript toBusiness(RunningScriptModel runningScriptModel) {
|
||||
RunningScript result = new RunningScript(
|
||||
runningScriptModel.getConfig(),
|
||||
runningScriptModel.getRequireLoad(),
|
||||
runningScriptModel.getScriptId(),
|
||||
runningScriptModel.getTestPlanID(),
|
||||
toBusiness(runningScriptModel.getRunningAgentModels()));
|
||||
// result.setConfig(runningScriptModel.getConfig());
|
||||
// result.setFinished(runningScriptModel.isFinished());
|
||||
// result.setRequireLoad(runningScriptModel.getRequireLoad());
|
||||
// List<RunningAgent> runningAgents = new ArrayList<RunningAgent>();
|
||||
// for (RunningAgentModel runningAgentModel : runningScriptModel
|
||||
// .getRunningAgentModels()) {
|
||||
// runningAgents.add(BusinessModelMapFactory
|
||||
// .toBusiness(runningAgentModel));
|
||||
// }
|
||||
// result.setRunningAgents(runningAgents);
|
||||
// result.setScriptId(runningScriptModel.getScriptId());
|
||||
// result.setTestPlanID(runningScriptModel.getTestPlanID());
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<RunningAgent> toBusiness(
|
||||
List<RunningAgentModel> runningAgentModels) {
|
||||
List<RunningAgent> runningAgents = new ArrayList<RunningAgent>();
|
||||
for (RunningAgentModel runningAgentModel : runningAgentModels) {
|
||||
runningAgents.add(toBusiness(runningAgentModel));
|
||||
}
|
||||
return runningAgents;
|
||||
}
|
||||
|
||||
public RunningScriptModel toModel(RunningScript runningScript) {
|
||||
RunningScriptModel ret = new RunningScriptModel();
|
||||
ret.setConfig(runningScript.getConfig());
|
||||
ret.setFinished(runningScript.isFinished());
|
||||
ret.setRequireLoad(runningScript.getRequireLoad());
|
||||
List<RunningAgentModel> runningAgentModels = new ArrayList<RunningAgentModel>();
|
||||
for (RunningAgent runningAgent : runningScript
|
||||
.queryRunningAgentsUnModifiable()) {
|
||||
runningAgentModels.add(BusinessModelMapFactory
|
||||
.toModel(runningAgent));
|
||||
}
|
||||
ret.setScenarioModel(runningScript.getScenario());
|
||||
ret.setScriptName(this.getScriptService()
|
||||
.getScript(runningScript.getScriptId()).getName());
|
||||
ret.setRunningAgentModels(runningAgentModels);
|
||||
ret.setScriptId(runningScript.getScriptId());
|
||||
ret.setTestPlanID(runningScript.getTestPlanID());
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static TestPlanInBusiness toBusiness(
|
||||
TestPlanBusinessModel testPlanModel) {
|
||||
TestPlanInBusiness ret = new TestPlanInBusiness();
|
||||
List<MonitorInBusiness> monitors = new ArrayList<MonitorInBusiness>();
|
||||
for (MonitorModel monitorModel : testPlanModel.getMonitorModels()) {
|
||||
monitors.add(toBusiness(monitorModel));
|
||||
}
|
||||
|
||||
ret.setMonitors(monitors);
|
||||
ret.setName(testPlanModel.getName());
|
||||
List<RunningScript> runningScripts = new ArrayList<RunningScript>();
|
||||
for (RunningScriptModel runningScriptModel : testPlanModel
|
||||
.getRunningScriptModels()) {
|
||||
RunningScript runningScript = toBusiness(runningScriptModel);
|
||||
runningScripts.add(runningScript);
|
||||
}
|
||||
ret.setRunningScripts(runningScripts);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public TestPlanBusinessModel toModel(TestPlanInBusiness testPlanInBusiness) {
|
||||
TestPlanBusinessModel ret = new TestPlanBusinessModel();
|
||||
ret.setName(testPlanInBusiness.getName());
|
||||
List<RunningScriptModel> runningScriptModels = new ArrayList<RunningScriptModel>();
|
||||
for (RunningScript runningScript : testPlanInBusiness
|
||||
.getRunningScripts()) {
|
||||
runningScriptModels.add(toModel(runningScript));
|
||||
}
|
||||
ret.setRunningScriptModels(runningScriptModels);
|
||||
List<MonitorModel> monitorModels = new ArrayList<MonitorModel>();
|
||||
for (MonitorInBusiness 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 MonitorModel toModel(MonitorInBusiness monitorInBusiness) {
|
||||
MonitorModel ret = new MonitorModel();
|
||||
ret.setHostName(monitorInBusiness.getHostName());
|
||||
ret.setPort(monitorInBusiness.getPort());
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static TestPlanDBModel toModel(TestPlanDB testPlanDB) {
|
||||
TestPlanDBModel ret = new TestPlanDBModel();
|
||||
ret.setCreateDateTime(testPlanDB.getCreateDateTime());
|
||||
ret.setCurrentStatus(testPlanDB.getCurrentStatus());
|
||||
ret.setFailTimes(testPlanDB.getFailTimes());
|
||||
ret.setId(testPlanDB.getId());
|
||||
ret.setName(testPlanDB.getName());
|
||||
ret.setReportCreated(testPlanDB.isReportCreated());
|
||||
ret.setTestPlanModelContent(testPlanDB.getTestPlanModelContent());
|
||||
ret.setTestPlanRunId(testPlanDB.getTestPlanRunId());
|
||||
ret.setUserModel(toModel(testPlanDB.getUser()));
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static UserModel toModel(User user) {
|
||||
UserModel ret = new UserModel();
|
||||
ret.setId(user.getId());
|
||||
ret.setPassword(user.getPassword());
|
||||
ret.setUserName(user.getUserName());
|
||||
ret.setScope(user.getScope());
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static PortModel toModel(Port port) {
|
||||
PortModel ret = new PortModel();
|
||||
ret.setId(port.getId());
|
||||
ret.setInUse(port.isInUse());
|
||||
ret.setPort(port.getPort());
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Port toBusiness(PortModel portModel) {
|
||||
Port ret = new Port();
|
||||
ret.setId(portModel.getId());
|
||||
ret.setInUse(portModel.isInUse());
|
||||
ret.setPort(portModel.getPort());
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static ScriptModel toModel(Script script) {
|
||||
ScriptModel ret = new ScriptModel();
|
||||
ret.setBehaviorCount(script.getBehaviorCount());
|
||||
ret.setCreateDateTime(script.getCreateDateTime());
|
||||
ret.setId(script.getId());
|
||||
ret.setName(script.getName());
|
||||
ret.setScriptContent(script.getScriptContent());
|
||||
ret.setUserModel(toModel(script.getUser()));
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
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.entity.Agent;
|
||||
import org.bench4q.master.entity.Port;
|
||||
import org.bench4q.master.entity.Script;
|
||||
import org.bench4q.master.entity.TestPlanDB;
|
||||
import org.bench4q.master.entity.User;
|
||||
import org.bench4q.master.service.infrastructure.ScriptService;
|
||||
import org.bench4q.share.models.master.AgentModel;
|
||||
import org.bench4q.share.models.master.MonitorModel;
|
||||
import org.bench4q.share.models.master.PortModel;
|
||||
import org.bench4q.share.models.master.RunningAgentModel;
|
||||
import org.bench4q.share.models.master.RunningScriptModel;
|
||||
import org.bench4q.share.models.master.ScriptModel;
|
||||
import org.bench4q.share.models.master.TestPlanBusinessModel;
|
||||
import org.bench4q.share.models.master.TestPlanDBModel;
|
||||
import org.bench4q.share.models.master.UserModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class BusinessModelMapFactory {
|
||||
private ScriptService scriptService;
|
||||
|
||||
private ScriptService getScriptService() {
|
||||
return scriptService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setScriptService(ScriptService scriptService) {
|
||||
this.scriptService = scriptService;
|
||||
}
|
||||
|
||||
public static Agent toBusiness(AgentModel agentModel) {
|
||||
Agent agent = new Agent();
|
||||
agent.setCurrentStatus(agentModel.getCurrentStatus());
|
||||
agent.setHostName(agentModel.getHostName());
|
||||
agent.setId(agentModel.getId());
|
||||
agent.setMaxLoad(agentModel.getMaxLoad());
|
||||
agent.setPort(agentModel.getPort());
|
||||
agent.setRemainLoad(agentModel.getRemainLoad());
|
||||
return agent;
|
||||
}
|
||||
|
||||
public static AgentModel toModel(Agent agent) {
|
||||
AgentModel agentModel = new AgentModel();
|
||||
agentModel.setCurrentStatus(agent.getCurrentStatus());
|
||||
agentModel.setHostName(agent.getHostName());
|
||||
agentModel.setId(agent.getId());
|
||||
agentModel.setMaxLoad(agent.getMaxLoad());
|
||||
agentModel.setPort(agent.getPort());
|
||||
agentModel.setRemainLoad(agent.getRemainLoad());
|
||||
return agentModel;
|
||||
}
|
||||
|
||||
public static RunningAgent toBusiness(RunningAgentModel runningAgentModel) {
|
||||
RunningAgent runningAgent = new RunningAgent();
|
||||
runningAgent.setAgent(BusinessModelMapFactory
|
||||
.toBusiness(runningAgentModel.getAgent()));
|
||||
runningAgent.setAgentRunId(runningAgentModel.getAgentRunId());
|
||||
runningAgent.setLoadInUse(runningAgentModel.getLoadInUse());
|
||||
runningAgent.setScriptId(runningAgentModel.getScriptId());
|
||||
return runningAgent;
|
||||
}
|
||||
|
||||
public static RunningAgentModel toModel(RunningAgent runningAgent) {
|
||||
RunningAgentModel ret = new RunningAgentModel();
|
||||
ret.setAgent(BusinessModelMapFactory.toModel(runningAgent.getAgent()));
|
||||
ret.setAgentRunId(runningAgent.getAgentRunId());
|
||||
ret.setLoadInUse(runningAgent.getLoadInUse());
|
||||
ret.setScriptId(runningAgent.getScriptId());
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static RunningScript toBusiness(RunningScriptModel runningScriptModel) {
|
||||
RunningScript result = new RunningScript(
|
||||
runningScriptModel.getConfig(),
|
||||
runningScriptModel.getRequireLoad(),
|
||||
runningScriptModel.getScriptId(),
|
||||
runningScriptModel.getTestPlanID(),
|
||||
toBusiness(runningScriptModel.getRunningAgentModels()));
|
||||
// result.setConfig(runningScriptModel.getConfig());
|
||||
// result.setFinished(runningScriptModel.isFinished());
|
||||
// result.setRequireLoad(runningScriptModel.getRequireLoad());
|
||||
// List<RunningAgent> runningAgents = new ArrayList<RunningAgent>();
|
||||
// for (RunningAgentModel runningAgentModel : runningScriptModel
|
||||
// .getRunningAgentModels()) {
|
||||
// runningAgents.add(BusinessModelMapFactory
|
||||
// .toBusiness(runningAgentModel));
|
||||
// }
|
||||
// result.setRunningAgents(runningAgents);
|
||||
// result.setScriptId(runningScriptModel.getScriptId());
|
||||
// result.setTestPlanID(runningScriptModel.getTestPlanID());
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<RunningAgent> toBusiness(
|
||||
List<RunningAgentModel> runningAgentModels) {
|
||||
List<RunningAgent> runningAgents = new ArrayList<RunningAgent>();
|
||||
for (RunningAgentModel runningAgentModel : runningAgentModels) {
|
||||
runningAgents.add(toBusiness(runningAgentModel));
|
||||
}
|
||||
return runningAgents;
|
||||
}
|
||||
|
||||
public RunningScriptModel toModel(RunningScript runningScript) {
|
||||
RunningScriptModel ret = new RunningScriptModel();
|
||||
ret.setConfig(runningScript.getConfig());
|
||||
ret.setFinished(runningScript.isFinished());
|
||||
ret.setRequireLoad(runningScript.getRequireLoad());
|
||||
List<RunningAgentModel> runningAgentModels = new ArrayList<RunningAgentModel>();
|
||||
for (RunningAgent runningAgent : runningScript
|
||||
.queryRunningAgentsUnModifiable()) {
|
||||
runningAgentModels.add(BusinessModelMapFactory
|
||||
.toModel(runningAgent));
|
||||
}
|
||||
ret.setScenarioModel(runningScript.getScenario());
|
||||
ret.setScriptName(this.getScriptService()
|
||||
.getScript(runningScript.getScriptId()).getName());
|
||||
ret.setRunningAgentModels(runningAgentModels);
|
||||
ret.setScriptId(runningScript.getScriptId());
|
||||
ret.setTestPlanID(runningScript.getTestPlanID());
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static TestPlanInBusiness toBusiness(
|
||||
TestPlanBusinessModel testPlanModel) {
|
||||
TestPlanInBusiness ret = new TestPlanInBusiness();
|
||||
List<MonitorInBusiness> monitors = new ArrayList<MonitorInBusiness>();
|
||||
guardMonitorListNotNull(testPlanModel);
|
||||
if (testPlanModel.getMonitorModels() != null) {
|
||||
for (MonitorModel monitorModel : testPlanModel.getMonitorModels()) {
|
||||
monitors.add(toBusiness(monitorModel));
|
||||
}
|
||||
}
|
||||
ret.setMonitors(monitors);
|
||||
ret.setName(testPlanModel.getName());
|
||||
List<RunningScript> runningScripts = new ArrayList<RunningScript>();
|
||||
for (RunningScriptModel runningScriptModel : testPlanModel
|
||||
.getRunningScriptModels()) {
|
||||
RunningScript runningScript = toBusiness(runningScriptModel);
|
||||
runningScripts.add(runningScript);
|
||||
}
|
||||
ret.setRunningScripts(runningScripts);
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static void guardMonitorListNotNull(
|
||||
TestPlanBusinessModel testPlanModel) {
|
||||
if (testPlanModel.getMonitorModels() == null) {
|
||||
testPlanModel.setMonitorModels(new ArrayList<MonitorModel>());
|
||||
}
|
||||
}
|
||||
|
||||
public TestPlanBusinessModel toModel(TestPlanInBusiness testPlanInBusiness) {
|
||||
TestPlanBusinessModel ret = new TestPlanBusinessModel();
|
||||
ret.setName(testPlanInBusiness.getName());
|
||||
List<RunningScriptModel> runningScriptModels = new ArrayList<RunningScriptModel>();
|
||||
for (RunningScript runningScript : testPlanInBusiness
|
||||
.getRunningScripts()) {
|
||||
runningScriptModels.add(toModel(runningScript));
|
||||
}
|
||||
ret.setRunningScriptModels(runningScriptModels);
|
||||
List<MonitorModel> monitorModels = new ArrayList<MonitorModel>();
|
||||
for (MonitorInBusiness 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 MonitorModel toModel(MonitorInBusiness monitorInBusiness) {
|
||||
MonitorModel ret = new MonitorModel();
|
||||
ret.setHostName(monitorInBusiness.getHostName());
|
||||
ret.setPort(monitorInBusiness.getPort());
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static TestPlanDBModel toModel(TestPlanDB testPlanDB) {
|
||||
TestPlanDBModel ret = new TestPlanDBModel();
|
||||
ret.setCreateDateTime(testPlanDB.getCreateDateTime());
|
||||
ret.setCurrentStatus(testPlanDB.getCurrentStatus());
|
||||
ret.setFailTimes(testPlanDB.getFailTimes());
|
||||
ret.setId(testPlanDB.getId());
|
||||
ret.setName(testPlanDB.getName());
|
||||
ret.setReportCreated(testPlanDB.isReportCreated());
|
||||
ret.setTestPlanModelContent(testPlanDB.getTestPlanModelContent());
|
||||
ret.setTestPlanRunId(testPlanDB.getTestPlanRunId());
|
||||
ret.setUserModel(toModel(testPlanDB.getUser()));
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static UserModel toModel(User user) {
|
||||
UserModel ret = new UserModel();
|
||||
ret.setId(user.getId());
|
||||
ret.setPassword(user.getPassword());
|
||||
ret.setUserName(user.getUserName());
|
||||
ret.setScope(user.getScope());
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static PortModel toModel(Port port) {
|
||||
PortModel ret = new PortModel();
|
||||
ret.setId(port.getId());
|
||||
ret.setInUse(port.isInUse());
|
||||
ret.setPort(port.getPort());
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Port toBusiness(PortModel portModel) {
|
||||
Port ret = new Port();
|
||||
ret.setId(portModel.getId());
|
||||
ret.setInUse(portModel.isInUse());
|
||||
ret.setPort(portModel.getPort());
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static ScriptModel toModel(Script script) {
|
||||
ScriptModel ret = new ScriptModel();
|
||||
ret.setBehaviorCount(script.getBehaviorCount());
|
||||
ret.setCreateDateTime(script.getCreateDateTime());
|
||||
ret.setId(script.getId());
|
||||
ret.setName(script.getName());
|
||||
ret.setScriptContent(script.getScriptContent());
|
||||
ret.setUserModel(toModel(script.getUser()));
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,137 +1,135 @@
|
|||
package org.bench4q.master.test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.master.service.infrastructure.ScriptService;
|
||||
import org.bench4q.master.service.infrastructure.TestPlanScriptResultService;
|
||||
import org.bench4q.master.service.infrastructure.TestPlanScriptService;
|
||||
import org.bench4q.master.service.infrastructure.TestPlanService;
|
||||
import org.bench4q.master.service.infrastructure.UserService;
|
||||
import org.bench4q.master.test.controller.TestBase;
|
||||
import org.bench4q.share.models.master.MonitorModel;
|
||||
import org.bench4q.share.models.master.RunningScriptModel;
|
||||
import org.bench4q.share.models.master.TestScriptConfig;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public class TestBase_MakeUpTestPlan extends TestBase {
|
||||
private TestPlanScriptResultService testPlanScriptResultService;
|
||||
private TestPlanScriptService testPlanScriptService;
|
||||
private TestPlanService testPlanService;
|
||||
private UserService userService;
|
||||
private ScriptService scriptService;
|
||||
private UUID testPlanRunIdUuid;
|
||||
private int scriptId;
|
||||
protected static final int USE_SCRIPT = 61;
|
||||
// private static int EACH_SCRIPT_LOAD_LargeSCALE = 12000;
|
||||
private static int EACH_SCRIPT_LOAD_SMALLSCALE = 40;
|
||||
// private static int EACH_SCRIPT_LOAD_MIDDLESCALE = 800;
|
||||
private static String Monitor_Host_Name = "127.0.0.1";
|
||||
private static String monitor_port = "5556";
|
||||
|
||||
public TestPlanScriptResultService getTestPlanScriptResultService() {
|
||||
return testPlanScriptResultService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setTestPlanScriptResultService(
|
||||
TestPlanScriptResultService testPlanScriptResultService) {
|
||||
this.testPlanScriptResultService = testPlanScriptResultService;
|
||||
}
|
||||
|
||||
public TestPlanScriptService getTestPlanScriptService() {
|
||||
return testPlanScriptService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setTestPlanScriptService(
|
||||
TestPlanScriptService testPlanScriptService) {
|
||||
this.testPlanScriptService = testPlanScriptService;
|
||||
}
|
||||
|
||||
public TestPlanService getTestPlanService() {
|
||||
return testPlanService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setTestPlanService(TestPlanService testPlanService) {
|
||||
this.testPlanService = testPlanService;
|
||||
}
|
||||
|
||||
public UserService getUserService() {
|
||||
return userService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setUserService(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
public ScriptService getScriptService() {
|
||||
return scriptService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setScriptService(ScriptService scriptService) {
|
||||
this.scriptService = scriptService;
|
||||
}
|
||||
|
||||
public UUID getTestPlanRunIdUuid() {
|
||||
return testPlanRunIdUuid;
|
||||
}
|
||||
|
||||
public void setTestPlanRunIdUuid(UUID testPlanRunIdUuid) {
|
||||
this.testPlanRunIdUuid = testPlanRunIdUuid;
|
||||
}
|
||||
|
||||
public int getScriptId() {
|
||||
return scriptId;
|
||||
}
|
||||
|
||||
public void setScriptId(int scriptId) {
|
||||
this.scriptId = scriptId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected ScriptBriefResultModel buildScriptBriefResultModel(int i) {
|
||||
ScriptBriefResultModel resultModel = new ScriptBriefResultModel();
|
||||
resultModel.setAverageElapsedTime(100 * i);
|
||||
resultModel.setAverageResponseTime(100 * i);
|
||||
resultModel.setFailRateThisTime(10 * i);
|
||||
return resultModel;
|
||||
}
|
||||
|
||||
public static List<MonitorModel> createOneMonitorList() {
|
||||
List<MonitorModel> monitors = new ArrayList<MonitorModel>();
|
||||
monitors.add(buildMonitorModel());
|
||||
return monitors;
|
||||
}
|
||||
|
||||
public static List<RunningScriptModel> createOneScriptList(int scriptId) {
|
||||
List<RunningScriptModel> list = new ArrayList<RunningScriptModel>();
|
||||
list.add(buildScriptModel(scriptId));
|
||||
return list;
|
||||
}
|
||||
|
||||
public static RunningScriptModel buildScriptModel(int scriptID) {
|
||||
RunningScriptModel model = new RunningScriptModel();
|
||||
model.setScriptId(scriptID);
|
||||
model.setRequireLoad(EACH_SCRIPT_LOAD_SMALLSCALE);
|
||||
TestScriptConfig config = new TestScriptConfig();
|
||||
config.setWarmUp(20);
|
||||
config.setExecuteRange(60);
|
||||
config.setCoolDown(10);
|
||||
model.setConfig(config);
|
||||
return model;
|
||||
}
|
||||
|
||||
private static MonitorModel buildMonitorModel() {
|
||||
MonitorModel monitorModel = new MonitorModel();
|
||||
monitorModel.setHostName(Monitor_Host_Name);
|
||||
monitorModel.setPort(Integer.parseInt(monitor_port));
|
||||
return monitorModel;
|
||||
}
|
||||
}
|
||||
package org.bench4q.master.test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.master.service.infrastructure.ScriptService;
|
||||
import org.bench4q.master.service.infrastructure.TestPlanScriptResultService;
|
||||
import org.bench4q.master.service.infrastructure.TestPlanScriptService;
|
||||
import org.bench4q.master.service.infrastructure.TestPlanService;
|
||||
import org.bench4q.master.service.infrastructure.UserService;
|
||||
import org.bench4q.master.test.controller.TestBase;
|
||||
import org.bench4q.share.models.master.MonitorModel;
|
||||
import org.bench4q.share.models.master.RunningScriptModel;
|
||||
import org.bench4q.share.models.master.TestScriptConfig;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public class TestBase_MakeUpTestPlan extends TestBase {
|
||||
private TestPlanScriptResultService testPlanScriptResultService;
|
||||
private TestPlanScriptService testPlanScriptService;
|
||||
private TestPlanService testPlanService;
|
||||
private UserService userService;
|
||||
private ScriptService scriptService;
|
||||
private UUID testPlanRunIdUuid;
|
||||
private int scriptId;
|
||||
protected static final int USE_SCRIPT = 61;
|
||||
// private static int EACH_SCRIPT_LOAD_LargeSCALE = 12000;
|
||||
private 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";
|
||||
|
||||
public TestPlanScriptResultService getTestPlanScriptResultService() {
|
||||
return testPlanScriptResultService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setTestPlanScriptResultService(
|
||||
TestPlanScriptResultService testPlanScriptResultService) {
|
||||
this.testPlanScriptResultService = testPlanScriptResultService;
|
||||
}
|
||||
|
||||
public TestPlanScriptService getTestPlanScriptService() {
|
||||
return testPlanScriptService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setTestPlanScriptService(
|
||||
TestPlanScriptService testPlanScriptService) {
|
||||
this.testPlanScriptService = testPlanScriptService;
|
||||
}
|
||||
|
||||
public TestPlanService getTestPlanService() {
|
||||
return testPlanService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setTestPlanService(TestPlanService testPlanService) {
|
||||
this.testPlanService = testPlanService;
|
||||
}
|
||||
|
||||
public UserService getUserService() {
|
||||
return userService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setUserService(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
public ScriptService getScriptService() {
|
||||
return scriptService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setScriptService(ScriptService scriptService) {
|
||||
this.scriptService = scriptService;
|
||||
}
|
||||
|
||||
public UUID getTestPlanRunIdUuid() {
|
||||
return testPlanRunIdUuid;
|
||||
}
|
||||
|
||||
public void setTestPlanRunIdUuid(UUID testPlanRunIdUuid) {
|
||||
this.testPlanRunIdUuid = testPlanRunIdUuid;
|
||||
}
|
||||
|
||||
public int getScriptId() {
|
||||
return scriptId;
|
||||
}
|
||||
|
||||
public void setScriptId(int scriptId) {
|
||||
this.scriptId = scriptId;
|
||||
}
|
||||
|
||||
protected ScriptBriefResultModel buildScriptBriefResultModel(int i) {
|
||||
ScriptBriefResultModel resultModel = new ScriptBriefResultModel();
|
||||
resultModel.setAverageElapsedTime(100 * i);
|
||||
resultModel.setAverageResponseTime(100 * i);
|
||||
resultModel.setFailRateThisTime(10 * i);
|
||||
return resultModel;
|
||||
}
|
||||
|
||||
public static List<MonitorModel> createOneMonitorList() {
|
||||
List<MonitorModel> monitors = new ArrayList<MonitorModel>();
|
||||
monitors.add(buildMonitorModel());
|
||||
return monitors;
|
||||
}
|
||||
|
||||
public static List<RunningScriptModel> createOneScriptList(int scriptId) {
|
||||
List<RunningScriptModel> list = new ArrayList<RunningScriptModel>();
|
||||
list.add(buildScriptModel(scriptId));
|
||||
return list;
|
||||
}
|
||||
|
||||
public static RunningScriptModel buildScriptModel(int scriptID) {
|
||||
RunningScriptModel model = new RunningScriptModel();
|
||||
model.setScriptId(scriptID);
|
||||
model.setRequireLoad(EACH_SCRIPT_LOAD_SMALLSCALE);
|
||||
TestScriptConfig config = new TestScriptConfig();
|
||||
config.setWarmUp(20);
|
||||
config.setExecuteRange(60);
|
||||
config.setCoolDown(10);
|
||||
model.setConfig(config);
|
||||
return model;
|
||||
}
|
||||
|
||||
private static MonitorModel buildMonitorModel() {
|
||||
MonitorModel monitorModel = new MonitorModel();
|
||||
monitorModel.setHostName(Monitor_Host_Name);
|
||||
monitorModel.setPort(Integer.parseInt(monitor_port));
|
||||
return monitorModel;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,8 +12,9 @@ public class TestBase {
|
|||
protected HttpRequester httpRequester = new HttpRequester();
|
||||
private final String USERNAME = "admin";
|
||||
private final String PASSWORD = "admin";
|
||||
// public static final String BASE_URL = "http://localhost:8080";
|
||||
public static final String BASE_URL = "http://localhost:7979";
|
||||
// public static final String BASE_URL =
|
||||
// "http://bench4q_master.jd-app.com:80";
|
||||
protected final String AUTH_HEADER_PROPERTY = "Authorization";
|
||||
protected final String ACCES_TOCKEN_STARTER = "Bearer ";
|
||||
protected String accessTocken;
|
||||
|
|
|
@ -1,36 +1,66 @@
|
|||
package org.bench4q.master.test.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.bench4q.master.test.testplan.TestPlanTester;
|
||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.TestPlanBusinessModel;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class TestPlanControllerTest extends TestBase {
|
||||
private String url = BASE_URL + "/testPlan";
|
||||
|
||||
public TestPlanControllerTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runTestPlanWithoutLogOn() throws JAXBException, IOException {
|
||||
HttpResponse httpResponse = this.httpRequester
|
||||
.sendPostXml(
|
||||
this.url + "/runTestPlanWithTestPlanModel",
|
||||
MarshalHelper
|
||||
.marshal(
|
||||
TestPlanBusinessModel.class,
|
||||
TestPlanTester
|
||||
.createATestPlan(TestPlanTester.SCRIPTID1)),
|
||||
null);
|
||||
System.out.println(httpResponse.getContent());
|
||||
assertEquals(400, httpResponse.getCode());
|
||||
}
|
||||
|
||||
}
|
||||
package org.bench4q.master.test.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.bench4q.master.test.TestBase_MakeUpTestPlan;
|
||||
import org.bench4q.master.test.testplan.TestPlanTester;
|
||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.TestPlanBusinessModel;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class TestPlanControllerTest extends TestBase_MakeUpTestPlan {
|
||||
private String url = BASE_URL + "/testPlan";
|
||||
|
||||
public TestPlanControllerTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runTestPlanWithoutLogOn() throws JAXBException, IOException {
|
||||
HttpResponse httpResponse = this.httpRequester
|
||||
.sendPostXml(
|
||||
this.url + "/runTestPlanWithTestPlanModel",
|
||||
MarshalHelper
|
||||
.marshal(
|
||||
TestPlanBusinessModel.class,
|
||||
TestPlanTester
|
||||
.createATestPlan(TestPlanTester.SCRIPTID1)),
|
||||
null);
|
||||
System.out.println(httpResponse.getContent());
|
||||
assertEquals(400, httpResponse.getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runTestPlanWithNullMonitorList() throws IOException,
|
||||
JAXBException {
|
||||
HttpResponse httpResponse = this.httpRequester
|
||||
.sendPostXml(
|
||||
this.url + "/runTestPlanWithTestPlanModel",
|
||||
MarshalHelper
|
||||
.marshal(
|
||||
TestPlanBusinessModel.class,
|
||||
TestPlanTester
|
||||
.createATestPlanWithNullMonitorList(TestPlanTester.SCRIPTID1)),
|
||||
makeAccessTockenMap(accessTocken));
|
||||
System.out.println(httpResponse.getContent());
|
||||
assertEquals(200, httpResponse.getCode());
|
||||
}
|
||||
|
||||
public void runTestPlanWithZeroMonitor() throws IOException, JAXBException {
|
||||
HttpResponse httpResponse = this.httpRequester
|
||||
.sendPostXml(
|
||||
this.url + "/runTestPlanWithTestPlanModel",
|
||||
MarshalHelper
|
||||
.marshal(
|
||||
TestPlanBusinessModel.class,
|
||||
TestPlanTester
|
||||
.createATestPlanWithZeroMonitor(TestPlanTester.SCRIPTID1)),
|
||||
makeAccessTockenMap(accessTocken));
|
||||
System.out.println(httpResponse.getContent());
|
||||
assertEquals(200, httpResponse.getCode());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,310 +1,331 @@
|
|||
package org.bench4q.master.test.testplan;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
|
||||
import org.bench4q.master.test.TestBase_MakeUpTestPlan;
|
||||
import org.bench4q.master.test.controller.TestBase;
|
||||
import org.bench4q.share.communication.HttpRequester;
|
||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.share.enums.master.TestPlanStatus;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.MonitorLogicalDiskResponseModel;
|
||||
import org.bench4q.share.models.master.RunningScriptModel;
|
||||
import org.bench4q.share.models.master.TestPlanBusinessModel;
|
||||
import org.bench4q.share.models.master.TestPlanResultModel;
|
||||
import org.bench4q.share.models.master.TestPlanScriptBriefResultModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptPagesBriefModel;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "classpath:service-test-context.xml" })
|
||||
public class TestPlanTester extends TestBase_MakeUpTestPlan {
|
||||
private TestPlanBusinessModel testPlanBusinessModel = new TestPlanBusinessModel();
|
||||
private String _url = TestBase.BASE_URL + "/testPlan";
|
||||
private int scriptSumNum;
|
||||
public static int SCRIPTID1 = 61;
|
||||
private static int SCRIPTID2 = 2;
|
||||
private static String Monitor_Host_Name = "133.133.12.3";
|
||||
private static String monitor_port = "5556";
|
||||
|
||||
public TestPlanBusinessModel getTestPlanBusinessModel() {
|
||||
return testPlanBusinessModel;
|
||||
}
|
||||
|
||||
public void setTestPlanBusinessModel(
|
||||
TestPlanBusinessModel testPlanBusinessModel) {
|
||||
this.testPlanBusinessModel = testPlanBusinessModel;
|
||||
}
|
||||
|
||||
public int getScriptSumNum() {
|
||||
return scriptSumNum;
|
||||
}
|
||||
|
||||
public void setScriptSumNum(int scriptSumNum) {
|
||||
this.scriptSumNum = scriptSumNum;
|
||||
}
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
public TestPlanTester() {
|
||||
new ClassPathXmlApplicationContext("classpath:service-test-context.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllRight() throws JAXBException, IOException,
|
||||
InterruptedException {
|
||||
this.setScriptSumNum(1);
|
||||
this.setAccessTocken(this.login());
|
||||
this.runAndGetBrief();
|
||||
// tester.loadTestPlans();
|
||||
// tester.runTestWithoutLogin();
|
||||
}
|
||||
|
||||
public void testWithoutBrief() throws JAXBException, IOException,
|
||||
InterruptedException {
|
||||
this.setScriptSumNum(1);
|
||||
this.setAccessTocken(this.login());
|
||||
this.setTestPlanRunIdUuid(testWithTestPlanModel());
|
||||
@SuppressWarnings("unused")
|
||||
TestPlanResultModel resultModel = this.getRunningInfo(this
|
||||
.getTestPlanRunIdUuid());
|
||||
// System.out.println(MarshalHelper.marshal(TestPlanResultModel.class,
|
||||
// resultModel));
|
||||
Thread.sleep(60000);
|
||||
this.getTestPlanReport(this.getTestPlanRunIdUuid());
|
||||
}
|
||||
|
||||
public void behaviorsBrief(UUID testPlanID, int scriptId)
|
||||
throws IOException {
|
||||
HttpResponse httpResponse = this.httpRequester.sendGet(_url
|
||||
+ "/getBehaviorsBrief/" + testPlanID.toString() + "/"
|
||||
+ scriptId, null, makeAccessTockenMap(this.accessTocken));
|
||||
if (HttpRequester.isInvalidResponse(httpResponse)) {
|
||||
System.out.println("Invalid response in behaviorsBrief");
|
||||
return;
|
||||
}
|
||||
System.out.println(httpResponse.getContent());
|
||||
}
|
||||
|
||||
public void runAndGetBrief() throws IOException, JAXBException,
|
||||
InterruptedException {
|
||||
UUID testPlanID = this.testWithTestPlanModel();
|
||||
Thread.sleep(10000);
|
||||
while (this.getRunningInfo(testPlanID).getCurrentStatus() != TestPlanStatus.InRunning) {
|
||||
Thread.sleep(6000);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 20; i++) {
|
||||
Thread.sleep(3000);
|
||||
this.getScriptBrief(testPlanID, SCRIPTID1);
|
||||
this.behaviorsBrief(testPlanID, SCRIPTID1);
|
||||
this.getPagesBriefModel(testPlanID, SCRIPTID1, 0);
|
||||
}
|
||||
|
||||
this.getMonitorBrief(testPlanID, Monitor_Host_Name, monitor_port);
|
||||
this.getTestPlanReport(testPlanID);
|
||||
}
|
||||
|
||||
public void runTestWithoutLogin() {
|
||||
this.setTestPlanBusinessModel(new TestPlanBusinessModel());
|
||||
try {
|
||||
HttpResponse httpResponse = this.httpRequester.sendPostXml(
|
||||
this._url + "/runTestPlanWithTestPlanModel",
|
||||
marshalTestPlanToString(), null);
|
||||
System.out.println(httpResponse.getCode());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (JAXBException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public UUID testWithTestPlanModel() throws JAXBException, IOException {
|
||||
String content;
|
||||
TestPlanResultModel result = new TestPlanResultModel();
|
||||
|
||||
this._createATestPlan();
|
||||
content = marshalTestPlanToString();
|
||||
|
||||
HttpResponse httpResponse = this.httpRequester.sendPostXml(this._url
|
||||
+ "/runTestPlanWithTestPlanModel", content,
|
||||
this.makeAccessTockenMap(this.accessTocken));
|
||||
|
||||
result = (TestPlanResultModel) MarshalHelper.unmarshal(
|
||||
TestPlanResultModel.class, httpResponse.getContent());
|
||||
System.out.println(result.getCurrentStatus());
|
||||
return result.getTestPlanId();
|
||||
}
|
||||
|
||||
private String marshalTestPlanToString() throws JAXBException {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
Marshaller marshaller = JAXBContext.newInstance(
|
||||
this.testPlanBusinessModel.getClass()).createMarshaller();
|
||||
marshaller.marshal(this.testPlanBusinessModel, stringWriter);
|
||||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
public static TestPlanBusinessModel createATestPlan(int scriptId) {
|
||||
TestPlanBusinessModel testPlanBusinessModel = new TestPlanBusinessModel();
|
||||
testPlanBusinessModel.setMonitorModels(createOneMonitorList());
|
||||
testPlanBusinessModel
|
||||
.setRunningScriptModels(createOneScriptList(SCRIPTID1));
|
||||
return testPlanBusinessModel;
|
||||
}
|
||||
|
||||
public TestPlanBusinessModel _createATestPlan() {
|
||||
if (this.getScriptSumNum() == 1) {
|
||||
this.testPlanBusinessModel
|
||||
.setRunningScriptModels(createOneScriptList(SCRIPTID1));
|
||||
} else if (getScriptSumNum() == 2) {
|
||||
this.testPlanBusinessModel
|
||||
.setRunningScriptModels(createTowScriptList());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
this.testPlanBusinessModel.setMonitorModels(createOneMonitorList());
|
||||
return this.testPlanBusinessModel;
|
||||
}
|
||||
|
||||
private List<RunningScriptModel> createTowScriptList() {
|
||||
List<RunningScriptModel> list = new ArrayList<RunningScriptModel>();
|
||||
list.add(buildScriptModel(SCRIPTID1));
|
||||
list.add(buildScriptModel(SCRIPTID2));
|
||||
return list;
|
||||
}
|
||||
|
||||
public TestPlanResultModel getRunningInfo(UUID testPlanId)
|
||||
throws IOException, JAXBException {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("testPlanId", testPlanId.toString());
|
||||
|
||||
HttpResponse httpResponse = this.httpRequester.sendGet(this._url
|
||||
+ "/getRunningInfo", params,
|
||||
this.makeAccessTockenMap(this.getAccessTocken()));
|
||||
TestPlanResultModel ret = (TestPlanResultModel) MarshalHelper
|
||||
.unmarshal(TestPlanResultModel.class, httpResponse.getContent());
|
||||
System.out.println(ret.getCurrentStatus());
|
||||
return ret;
|
||||
}
|
||||
|
||||
public TestPlanScriptBriefResultModel getScriptBrief(UUID testPlanId,
|
||||
int scriptId) throws IOException, JAXBException {
|
||||
HttpResponse httpResponse = this.httpRequester.sendGet(this._url
|
||||
+ "/scriptBrief/" + testPlanId.toString() + "/" + scriptId
|
||||
+ "/" + 0, null, createAccessTokenMap());
|
||||
System.out.println(httpResponse.getContent());
|
||||
TestPlanScriptBriefResultModel ret = (TestPlanScriptBriefResultModel) MarshalHelper
|
||||
.unmarshal(TestPlanScriptBriefResultModel.class,
|
||||
httpResponse.getContent());
|
||||
for (ScriptBriefResultModel scriptBriefResultModel : ret
|
||||
.getScriptBriefResultModels()) {
|
||||
System.out.println(scriptBriefResultModel.getAverageResponseTime());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public ScriptPagesBriefModel getPagesBriefModel(UUID testPlanId,
|
||||
int scriptId, int pageId) throws IOException, JAXBException {
|
||||
HttpResponse httpResponse = this.httpRequester.sendGet(this._url
|
||||
+ "/pagesBrief/" + testPlanId.toString() + "/" + scriptId,
|
||||
null, createAccessTokenMap());
|
||||
System.out.println(httpResponse.getContent());
|
||||
ScriptPagesBriefModel ret = (ScriptPagesBriefModel) MarshalHelper
|
||||
.unmarshal(ScriptPagesBriefModel.class,
|
||||
httpResponse.getContent());
|
||||
return ret;
|
||||
}
|
||||
|
||||
private Map<String, String> createAccessTokenMap() {
|
||||
Map<String, String> properties = new HashMap<String, String>();
|
||||
properties.put(this.AUTH_HEADER_PROPERTY, this.ACCES_TOCKEN_STARTER
|
||||
+ this.accessTocken);
|
||||
return properties;
|
||||
}
|
||||
|
||||
public void getMonitorBrief(UUID testPlanID, String hostName, String port)
|
||||
throws IOException, InterruptedException, JAXBException {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
getMonitorMemoryResult(testPlanID, hostName, port);
|
||||
getProcessorResult(testPlanID, hostName, port);
|
||||
getLogicalDiskResult(testPlanID, hostName, port);
|
||||
getNetworkInterfaceResult(testPlanID, hostName, port);
|
||||
}
|
||||
}
|
||||
|
||||
private void getMonitorMemoryResult(UUID testPlanId, String hostName,
|
||||
String port) throws IOException {
|
||||
getMonitorResult(testPlanId, hostName, port,
|
||||
"/monitorController/memorySUTInfo");
|
||||
|
||||
}
|
||||
|
||||
private void getProcessorResult(UUID testPlanId, String hostName,
|
||||
String port) throws IOException {
|
||||
getMonitorResult(testPlanId, hostName, port,
|
||||
"/monitorController/processorSUTInfo");
|
||||
}
|
||||
|
||||
private void getLogicalDiskResult(UUID testPlanID, String hostName,
|
||||
String port) throws IOException, JAXBException {
|
||||
HttpResponse httpResponse = this.httpRequester.sendGet(
|
||||
TestBase.BASE_URL
|
||||
+ "/monitorController/logicDiskMonitorSUTInfo/"
|
||||
+ testPlanID.toString() + "/" + hostName + "/6565/0",
|
||||
null, this.createAccessTokenMap());
|
||||
System.out.println(httpResponse.getContent());
|
||||
MonitorLogicalDiskResponseModel logicalDiskResponseModel = (MonitorLogicalDiskResponseModel) MarshalHelper
|
||||
.unmarshal(MonitorLogicalDiskResponseModel.class,
|
||||
httpResponse.getContent());
|
||||
assertNotNull(logicalDiskResponseModel);
|
||||
}
|
||||
|
||||
private void getNetworkInterfaceResult(UUID testPlanID, String hostName,
|
||||
String port) throws IOException {
|
||||
getMonitorResult(testPlanID, hostName, port,
|
||||
"/monitorController/networkInfo");
|
||||
}
|
||||
|
||||
private void getMonitorResult(UUID testPlanId, String hostName,
|
||||
String port, String relativePath) throws IOException {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("testPlanRunId", testPlanId.toString());
|
||||
params.put("hostName", hostName);
|
||||
params.put("port", port);
|
||||
params.put("duationBegin", 0 + "");
|
||||
HttpResponse httpResponse = this.httpRequester.sendGet(
|
||||
TestBase.BASE_URL + relativePath, params,
|
||||
this.createAccessTokenMap());
|
||||
System.out.println(httpResponse.getContent());
|
||||
}
|
||||
|
||||
public void loadTestPlans() throws IOException {
|
||||
HttpResponse httpResponse = this.httpRequester.sendGet(this._url
|
||||
+ "/loadTestPlans", null,
|
||||
this.makeAccessTockenMap(this.getAccessTocken()));
|
||||
System.out.println(httpResponse.getContent());
|
||||
}
|
||||
|
||||
public void getTestPlanReport(UUID testPlanID) throws IOException {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("testPlanRunID", testPlanID.toString());
|
||||
this.httpRequester.sendGet(this._url + "/getTestPlanReport", params,
|
||||
this.makeAccessTockenMap(this.getAccessTocken()));
|
||||
}
|
||||
|
||||
}
|
||||
package org.bench4q.master.test.testplan;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
|
||||
import org.bench4q.master.test.TestBase_MakeUpTestPlan;
|
||||
import org.bench4q.master.test.controller.TestBase;
|
||||
import org.bench4q.share.communication.HttpRequester;
|
||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.share.enums.master.TestPlanStatus;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.MonitorLogicalDiskResponseModel;
|
||||
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.TestPlanResultModel;
|
||||
import org.bench4q.share.models.master.TestPlanScriptBriefResultModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptPagesBriefModel;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "classpath:service-test-context.xml" })
|
||||
public class TestPlanTester extends TestBase_MakeUpTestPlan {
|
||||
private TestPlanBusinessModel testPlanBusinessModel = new TestPlanBusinessModel();
|
||||
private String _url = TestBase.BASE_URL + "/testPlan";
|
||||
private int scriptSumNum;
|
||||
public static int SCRIPTID1 = 61;
|
||||
// public static int SCRIPTID1 = 1;
|
||||
private static int SCRIPTID2 = 2;
|
||||
private static String Monitor_Host_Name = "133.133.12.3";
|
||||
private static String monitor_port = "5556";
|
||||
|
||||
public TestPlanBusinessModel getTestPlanBusinessModel() {
|
||||
return testPlanBusinessModel;
|
||||
}
|
||||
|
||||
public void setTestPlanBusinessModel(
|
||||
TestPlanBusinessModel testPlanBusinessModel) {
|
||||
this.testPlanBusinessModel = testPlanBusinessModel;
|
||||
}
|
||||
|
||||
public int getScriptSumNum() {
|
||||
return scriptSumNum;
|
||||
}
|
||||
|
||||
public void setScriptSumNum(int scriptSumNum) {
|
||||
this.scriptSumNum = scriptSumNum;
|
||||
}
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
public TestPlanTester() {
|
||||
new ClassPathXmlApplicationContext("classpath:service-test-context.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllRight() throws JAXBException, IOException,
|
||||
InterruptedException {
|
||||
this.setScriptSumNum(1);
|
||||
this.setAccessTocken(this.login());
|
||||
this.runAndGetBrief();
|
||||
// tester.loadTestPlans();
|
||||
// tester.runTestWithoutLogin();
|
||||
}
|
||||
|
||||
public void testWithoutBrief() throws JAXBException, IOException,
|
||||
InterruptedException {
|
||||
this.setScriptSumNum(1);
|
||||
this.setAccessTocken(this.login());
|
||||
this.setTestPlanRunIdUuid(testWithTestPlanModel());
|
||||
@SuppressWarnings("unused")
|
||||
TestPlanResultModel resultModel = this.getRunningInfo(this
|
||||
.getTestPlanRunIdUuid());
|
||||
// System.out.println(MarshalHelper.marshal(TestPlanResultModel.class,
|
||||
// resultModel));
|
||||
Thread.sleep(60000);
|
||||
this.getTestPlanReport(this.getTestPlanRunIdUuid());
|
||||
}
|
||||
|
||||
public void behaviorsBrief(UUID testPlanID, int scriptId)
|
||||
throws IOException {
|
||||
HttpResponse httpResponse = this.httpRequester.sendGet(_url
|
||||
+ "/getBehaviorsBrief/" + testPlanID.toString() + "/"
|
||||
+ scriptId, null, makeAccessTockenMap(this.accessTocken));
|
||||
if (HttpRequester.isInvalidResponse(httpResponse)) {
|
||||
System.out.println("Invalid response in behaviorsBrief");
|
||||
return;
|
||||
}
|
||||
System.out.println(httpResponse.getContent());
|
||||
}
|
||||
|
||||
public void runAndGetBrief() throws IOException, JAXBException,
|
||||
InterruptedException {
|
||||
UUID testPlanID = this.testWithTestPlanModel();
|
||||
Thread.sleep(10000);
|
||||
while (this.getRunningInfo(testPlanID).getCurrentStatus() != TestPlanStatus.InRunning) {
|
||||
Thread.sleep(6000);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 20; i++) {
|
||||
Thread.sleep(3000);
|
||||
this.getScriptBrief(testPlanID, SCRIPTID1);
|
||||
this.behaviorsBrief(testPlanID, SCRIPTID1);
|
||||
this.getPagesBriefModel(testPlanID, SCRIPTID1, 0);
|
||||
}
|
||||
|
||||
this.getMonitorBrief(testPlanID, Monitor_Host_Name, monitor_port);
|
||||
this.getTestPlanReport(testPlanID);
|
||||
}
|
||||
|
||||
public void runTestWithoutLogin() {
|
||||
this.setTestPlanBusinessModel(new TestPlanBusinessModel());
|
||||
try {
|
||||
HttpResponse httpResponse = this.httpRequester.sendPostXml(
|
||||
this._url + "/runTestPlanWithTestPlanModel",
|
||||
marshalTestPlanToString(), null);
|
||||
System.out.println(httpResponse.getCode());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (JAXBException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public UUID testWithTestPlanModel() throws JAXBException, IOException {
|
||||
String content;
|
||||
TestPlanResultModel result = new TestPlanResultModel();
|
||||
|
||||
this._createATestPlan();
|
||||
content = marshalTestPlanToString();
|
||||
|
||||
HttpResponse httpResponse = this.httpRequester.sendPostXml(this._url
|
||||
+ "/runTestPlanWithTestPlanModel", content,
|
||||
this.makeAccessTockenMap(this.accessTocken));
|
||||
|
||||
result = (TestPlanResultModel) MarshalHelper.unmarshal(
|
||||
TestPlanResultModel.class, httpResponse.getContent());
|
||||
System.out.println(result.getCurrentStatus());
|
||||
return result.getTestPlanId();
|
||||
}
|
||||
|
||||
private String marshalTestPlanToString() throws JAXBException {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
Marshaller marshaller = JAXBContext.newInstance(
|
||||
this.testPlanBusinessModel.getClass()).createMarshaller();
|
||||
marshaller.marshal(this.testPlanBusinessModel, stringWriter);
|
||||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
public static TestPlanBusinessModel createATestPlan(int scriptId) {
|
||||
TestPlanBusinessModel testPlanBusinessModel = new TestPlanBusinessModel();
|
||||
testPlanBusinessModel.setMonitorModels(createOneMonitorList());
|
||||
testPlanBusinessModel
|
||||
.setRunningScriptModels(createOneScriptList(SCRIPTID1));
|
||||
return testPlanBusinessModel;
|
||||
}
|
||||
|
||||
public static TestPlanBusinessModel createATestPlanWithZeroMonitor(
|
||||
int scriptId) {
|
||||
TestPlanBusinessModel testPlanBusinessModel = new TestPlanBusinessModel();
|
||||
testPlanBusinessModel.setMonitorModels(new ArrayList<MonitorModel>());
|
||||
testPlanBusinessModel
|
||||
.setRunningScriptModels(createOneScriptList(SCRIPTID1));
|
||||
return testPlanBusinessModel;
|
||||
}
|
||||
|
||||
public static TestPlanBusinessModel createATestPlanWithNullMonitorList(
|
||||
int scriptId) {
|
||||
TestPlanBusinessModel testPlanBusinessModel = new TestPlanBusinessModel();
|
||||
testPlanBusinessModel.setMonitorModels(null);
|
||||
testPlanBusinessModel
|
||||
.setRunningScriptModels(createOneScriptList(scriptId));
|
||||
return testPlanBusinessModel;
|
||||
}
|
||||
|
||||
public TestPlanBusinessModel _createATestPlan() {
|
||||
if (this.getScriptSumNum() == 1) {
|
||||
this.testPlanBusinessModel
|
||||
.setRunningScriptModels(createOneScriptList(SCRIPTID1));
|
||||
} else if (getScriptSumNum() == 2) {
|
||||
this.testPlanBusinessModel
|
||||
.setRunningScriptModels(createTowScriptList());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
this.testPlanBusinessModel.setMonitorModels(createOneMonitorList());
|
||||
return this.testPlanBusinessModel;
|
||||
}
|
||||
|
||||
private List<RunningScriptModel> createTowScriptList() {
|
||||
List<RunningScriptModel> list = new ArrayList<RunningScriptModel>();
|
||||
list.add(buildScriptModel(SCRIPTID1));
|
||||
list.add(buildScriptModel(SCRIPTID2));
|
||||
return list;
|
||||
}
|
||||
|
||||
public TestPlanResultModel getRunningInfo(UUID testPlanId)
|
||||
throws IOException, JAXBException {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("testPlanId", testPlanId.toString());
|
||||
|
||||
HttpResponse httpResponse = this.httpRequester.sendGet(this._url
|
||||
+ "/getRunningInfo", params,
|
||||
this.makeAccessTockenMap(this.getAccessTocken()));
|
||||
TestPlanResultModel ret = (TestPlanResultModel) MarshalHelper
|
||||
.unmarshal(TestPlanResultModel.class, httpResponse.getContent());
|
||||
System.out.println(ret.getCurrentStatus());
|
||||
return ret;
|
||||
}
|
||||
|
||||
public TestPlanScriptBriefResultModel getScriptBrief(UUID testPlanId,
|
||||
int scriptId) throws IOException, JAXBException {
|
||||
HttpResponse httpResponse = this.httpRequester.sendGet(this._url
|
||||
+ "/scriptBrief/" + testPlanId.toString() + "/" + scriptId
|
||||
+ "/" + 0, null, createAccessTokenMap());
|
||||
System.out.println(httpResponse.getContent());
|
||||
TestPlanScriptBriefResultModel ret = (TestPlanScriptBriefResultModel) MarshalHelper
|
||||
.unmarshal(TestPlanScriptBriefResultModel.class,
|
||||
httpResponse.getContent());
|
||||
for (ScriptBriefResultModel scriptBriefResultModel : ret
|
||||
.getScriptBriefResultModels()) {
|
||||
System.out.println(scriptBriefResultModel.getAverageResponseTime());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public ScriptPagesBriefModel getPagesBriefModel(UUID testPlanId,
|
||||
int scriptId, int pageId) throws IOException, JAXBException {
|
||||
HttpResponse httpResponse = this.httpRequester.sendGet(this._url
|
||||
+ "/pagesBrief/" + testPlanId.toString() + "/" + scriptId,
|
||||
null, createAccessTokenMap());
|
||||
System.out.println(httpResponse.getContent());
|
||||
ScriptPagesBriefModel ret = (ScriptPagesBriefModel) MarshalHelper
|
||||
.unmarshal(ScriptPagesBriefModel.class,
|
||||
httpResponse.getContent());
|
||||
return ret;
|
||||
}
|
||||
|
||||
private Map<String, String> createAccessTokenMap() {
|
||||
Map<String, String> properties = new HashMap<String, String>();
|
||||
properties.put(this.AUTH_HEADER_PROPERTY, this.ACCES_TOCKEN_STARTER
|
||||
+ this.accessTocken);
|
||||
return properties;
|
||||
}
|
||||
|
||||
public void getMonitorBrief(UUID testPlanID, String hostName, String port)
|
||||
throws IOException, InterruptedException, JAXBException {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
getMonitorMemoryResult(testPlanID, hostName, port);
|
||||
getProcessorResult(testPlanID, hostName, port);
|
||||
getLogicalDiskResult(testPlanID, hostName, port);
|
||||
getNetworkInterfaceResult(testPlanID, hostName, port);
|
||||
}
|
||||
}
|
||||
|
||||
private void getMonitorMemoryResult(UUID testPlanId, String hostName,
|
||||
String port) throws IOException {
|
||||
getMonitorResult(testPlanId, hostName, port,
|
||||
"/monitorController/memorySUTInfo");
|
||||
|
||||
}
|
||||
|
||||
private void getProcessorResult(UUID testPlanId, String hostName,
|
||||
String port) throws IOException {
|
||||
getMonitorResult(testPlanId, hostName, port,
|
||||
"/monitorController/processorSUTInfo");
|
||||
}
|
||||
|
||||
private void getLogicalDiskResult(UUID testPlanID, String hostName,
|
||||
String port) throws IOException, JAXBException {
|
||||
HttpResponse httpResponse = this.httpRequester.sendGet(
|
||||
TestBase.BASE_URL
|
||||
+ "/monitorController/logicDiskMonitorSUTInfo/"
|
||||
+ testPlanID.toString() + "/" + hostName + "/6565/0",
|
||||
null, this.createAccessTokenMap());
|
||||
System.out.println(httpResponse.getContent());
|
||||
MonitorLogicalDiskResponseModel logicalDiskResponseModel = (MonitorLogicalDiskResponseModel) MarshalHelper
|
||||
.unmarshal(MonitorLogicalDiskResponseModel.class,
|
||||
httpResponse.getContent());
|
||||
assertNotNull(logicalDiskResponseModel);
|
||||
}
|
||||
|
||||
private void getNetworkInterfaceResult(UUID testPlanID, String hostName,
|
||||
String port) throws IOException {
|
||||
getMonitorResult(testPlanID, hostName, port,
|
||||
"/monitorController/networkInfo");
|
||||
}
|
||||
|
||||
private void getMonitorResult(UUID testPlanId, String hostName,
|
||||
String port, String relativePath) throws IOException {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("testPlanRunId", testPlanId.toString());
|
||||
params.put("hostName", hostName);
|
||||
params.put("port", port);
|
||||
params.put("duationBegin", 0 + "");
|
||||
HttpResponse httpResponse = this.httpRequester.sendGet(
|
||||
TestBase.BASE_URL + relativePath, params,
|
||||
this.createAccessTokenMap());
|
||||
System.out.println(httpResponse.getContent());
|
||||
}
|
||||
|
||||
public void loadTestPlans() throws IOException {
|
||||
HttpResponse httpResponse = this.httpRequester.sendGet(this._url
|
||||
+ "/loadTestPlans", null,
|
||||
this.makeAccessTockenMap(this.getAccessTocken()));
|
||||
System.out.println(httpResponse.getContent());
|
||||
}
|
||||
|
||||
public void getTestPlanReport(UUID testPlanID) throws IOException {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("testPlanRunID", testPlanID.toString());
|
||||
this.httpRequester.sendGet(this._url + "/getTestPlanReport", params,
|
||||
this.makeAccessTockenMap(this.getAccessTocken()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue