diff --git a/src/main/java/org/bench4q/web/model/Bench4qWebException.java b/src/main/java/org/bench4q/web/model/Bench4qWebException.java new file mode 100644 index 00000000..c5ec1c4c --- /dev/null +++ b/src/main/java/org/bench4q/web/model/Bench4qWebException.java @@ -0,0 +1,44 @@ +package org.bench4q.web.model; + +import org.bench4q.web.model.master.ErrorResponseModel; + +public class Bench4qWebException extends Exception{ + + /** + * + */ + private static final long serialVersionUID = 1L; + private String code; + private String message; + private String resource; + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getResource() { + return resource; + } + + public void setResource(String resource) { + this.resource = resource; + } + + public Bench4qWebException(ErrorResponseModel errorReponseModel){ + this.code=errorReponseModel.getCode(); + this.message=errorReponseModel.getMessage(); + this.resource=errorReponseModel.getResource(); + } +} diff --git a/src/test/java/org/bench4q/web/api/test/GetRuningInfoTest.java b/src/test/java/org/bench4q/web/api/test/GetRuningInfoTest.java new file mode 100644 index 00000000..c5173ee5 --- /dev/null +++ b/src/test/java/org/bench4q/web/api/test/GetRuningInfoTest.java @@ -0,0 +1,45 @@ +package org.bench4q.web.api.test; + +import java.util.Iterator; +import java.util.List; + +import org.bench4q.web.model.RunningIndexModel; +import org.bench4q.web.model.ScriptIndexModel; +import org.bench4q.web.model.master.MonitorModel; +import org.junit.Assert; +import org.junit.Test; + + +public class GetRuningInfoTest extends RunPlan { + @Test + public void getRunningInfo() { + RunningIndexModel runningIndexModel = this.testPlanActionController + .getRunningInfo(this.accessToken, this.UUID); + + testScriptModel(runningIndexModel.getScriptIndexModels()); + testMonitorModel(runningIndexModel.getMonitorModels()); + Assert.assertEquals(runningIndexModel.getName(),this.testPlanRequestModel.getTestPlanName()); + System.out.println(runningIndexModel.getStatus()); + Assert.assertEquals(runningIndexModel.getTestPlanId(), this.UUID.toString()); + } + public void testScriptModel(List scriptIndexModels){ + Iterator iterator=scriptIndexModels.iterator(); + ScriptIndexModel scriptIndexModel=iterator.next(); + Assert.assertEquals(scriptIndexModel.getConfig().getWarmUp(), this.scriptRight.getWarmup()); + Assert.assertEquals(scriptIndexModel.getConfig().getCoolDown(),this.scriptRight.getCooldown()); + Assert.assertEquals(scriptIndexModel.getConfig().getExecuteRange(), this.scriptRight.getExecuteRange()); + Assert.assertEquals(scriptIndexModel.getScriptId(),this.scriptRight.getId()); + Assert.assertEquals(scriptIndexModel.getRequireLoad(), this.scriptRight.getLoad()); + } + public void testMonitorModel(List list){ + if(list==null) + return ; + /*Iterator iterator=monitorModels.iterator(); + MonitorModel monitorModel=iterator.next(); + Assert.assertEquals(monitorModel.getHostName(),);*/ + + + } +} + +//if the script result is error ,can i get the running info in the taskList?I think that should not \ No newline at end of file diff --git a/src/test/java/org/bench4q/web/api/test/RunPlan.java b/src/test/java/org/bench4q/web/api/test/RunPlan.java new file mode 100644 index 00000000..6a6125ad --- /dev/null +++ b/src/test/java/org/bench4q/web/api/test/RunPlan.java @@ -0,0 +1,54 @@ +package org.bench4q.web.api.test; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.bench4q.web.api.AuthorizeActionController; +import org.bench4q.web.api.TestPlanActionController; +import org.bench4q.web.model.ScriptModel; +import org.bench4q.web.model.TestPlanRequestModel; +import org.bench4q.web.model.TestPlanTaskModel; +import org.bench4q.web.model.UserModel; +import org.junit.Before; +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; +import org.springframework.ui.ModelMap; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = { "file:src/main/resources/bench4qweb-servlet.xml" }) +public class RunPlan { + @Autowired + protected AuthorizeActionController authorizeActionController; + @Autowired + protected TestPlanActionController testPlanActionController; + protected String accessToken; + protected String UUID; + protected TestPlanRequestModel testPlanRequestModel; + protected ScriptModel scriptRight; + protected ModelMap model = new ModelMap(); + + @Before + public void loginAndRunTest() { + UserModel userModel = new UserModel("www", "www"); + + authorizeActionController.login(userModel, model); + accessToken = (String) model.get("accessToken"); + List scriptModels = new ArrayList<>(); + testPlanRequestModel = new TestPlanRequestModel(); + scriptRight = new ScriptModel(15, 100, 20, 100, 30); + scriptModels.add(scriptRight); + testPlanRequestModel.setScriptList(scriptModels); + testPlanActionController.runTestPlan(accessToken, model, + testPlanRequestModel); + + @SuppressWarnings("unchecked") + List list = (List) this.model + .get("testPlanTaskList"); + Iterator iterator = list.iterator(); + UUID = iterator.next().getId(); + + } +} diff --git a/src/test/java/org/bench4q/web/api/test/TestPlanTaskListTest.java b/src/test/java/org/bench4q/web/api/test/TestPlanTaskListTest.java new file mode 100644 index 00000000..dbb17d27 --- /dev/null +++ b/src/test/java/org/bench4q/web/api/test/TestPlanTaskListTest.java @@ -0,0 +1,25 @@ +package org.bench4q.web.api.test; + +import java.util.List; + +import org.bench4q.web.model.TestPlanTaskModel; +import org.junit.Test; +import org.springframework.util.Assert; + +public class TestPlanTaskListTest extends RunPlan{ + + @Test + public void testPlanTaskList() throws InterruptedException{ + + Assert.notNull(this.model.get("testPlanTaskList")); + @SuppressWarnings("unchecked") + List list = (List) this.model.get("testPlanTaskList"); + Assert.isTrue(list.size()==1); + +// Iterator< TestPlanTaskModel> iterator=list.iterator(); + + + } + + +}