This commit is contained in:
fanfuxiaoran 2013-11-29 08:59:59 +08:00
parent a899f7efc2
commit b400007203
4 changed files with 168 additions and 0 deletions

View File

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

View File

@ -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<ScriptIndexModel> scriptIndexModels){
Iterator<ScriptIndexModel> 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<MonitorModel> list){
if(list==null)
return ;
/*Iterator<MonitorModel> 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

View File

@ -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<ScriptModel> 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<TestPlanTaskModel> list = (List<TestPlanTaskModel>) this.model
.get("testPlanTaskList");
Iterator<TestPlanTaskModel> iterator = list.iterator();
UUID = iterator.next().getId();
}
}

View File

@ -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<TestPlanTaskModel> list = (List<TestPlanTaskModel>) this.model.get("testPlanTaskList");
Assert.isTrue(list.size()==1);
// Iterator< TestPlanTaskModel> iterator=list.iterator();
}
}