add test to get test result
This commit is contained in:
parent
5cbb9f7f2d
commit
80d8e47a9c
|
@ -97,7 +97,7 @@ public class ScriptActionController {
|
|||
|
||||
@RequestMapping("deleteScript")
|
||||
public @ResponseBody
|
||||
BaseResponseModel deletescript(HttpServletRequest request,
|
||||
BaseResponseModel deletescript(
|
||||
@ModelAttribute("accessToken") String accessToken,
|
||||
@RequestParam String scriptId) throws CustomGenericException {
|
||||
String caller = new String("ScriptActionComntroller:deleteScript");
|
||||
|
|
|
@ -237,9 +237,8 @@ public class TestPlanActionController {
|
|||
@ModelAttribute("accessToken") String accessToken,
|
||||
@PathVariable String testPlanId) throws CustomGenericException,
|
||||
JAXBException {
|
||||
String caller = this.BASECALLER + "getSutInfo";
|
||||
WebTestPlanResultModel testPlanResultModel = this.getTestPlanInfo()
|
||||
.getTestPlanInfo(accessToken, testPlanId, caller);
|
||||
.getTestPlanInfo(accessToken, testPlanId, "");
|
||||
List<MonitorModel> monitorModels = testPlanResultModel
|
||||
.getMonitorModels();
|
||||
if (monitorModels != null) {
|
||||
|
@ -253,7 +252,7 @@ public class TestPlanActionController {
|
|||
}
|
||||
return new BaseResponseModel(true, sutInfos);
|
||||
} else
|
||||
return new BaseResponseModel(false, caller
|
||||
return new BaseResponseModel(false, ""
|
||||
+ ":monitor info in testPlan is empty:" + testPlanId);
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package org.bench4q.web.model;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
@XmlRootElement
|
||||
public class ResultInfoModel {
|
||||
|
||||
private String result;
|
||||
|
|
|
@ -2,17 +2,13 @@ package org.bench4q.web.model;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class SutInfo {
|
||||
|
||||
private String ip;
|
||||
private String port;
|
||||
|
||||
private List<ResultInfoModel> childResults;
|
||||
/*private List<String> cpu;
|
||||
private List<String> network;
|
||||
private final String mem=new String ("Memory");
|
||||
*/
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
@ -20,7 +16,6 @@ public class SutInfo {
|
|||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
public String getPort() {
|
||||
return port;
|
||||
}
|
||||
|
@ -28,7 +23,6 @@ public class SutInfo {
|
|||
public void setPort(String port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public List<ResultInfoModel> getChildResults() {
|
||||
return childResults;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package org.bench4q.web.service;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bench4q.share.models.monitor.NetworkInterfaceModel;
|
||||
import org.bench4q.web.exception.CustomGenericException;
|
||||
import org.bench4q.web.model.ResultInfoModel;
|
||||
import org.bench4q.web.model.SutInfo;
|
||||
|
@ -13,9 +16,9 @@ import org.springframework.stereotype.Component;
|
|||
public class MonitorDescriptionInfoService extends BaseService {
|
||||
private MonitorService monitorService;
|
||||
|
||||
// private MonitorService getMonitorService() {
|
||||
// return monitorService;
|
||||
// }
|
||||
// private MonitorService getMonitorService() {
|
||||
// return monitorService;
|
||||
// }
|
||||
|
||||
@Autowired
|
||||
private void setMonitorService(MonitorService monitorService) {
|
||||
|
@ -33,31 +36,13 @@ public class MonitorDescriptionInfoService extends BaseService {
|
|||
port));
|
||||
if (cpuInfoModel != null)
|
||||
resultInfoModels.add(cpuInfoModel);
|
||||
System.out.println("ok");
|
||||
// ResultInfoModel networkInfoModel = createNetworkResultInfoModel(
|
||||
// "network",
|
||||
// this.getMonitorService().getNetworkList(accessToken,
|
||||
// testPlanId, ip, port));
|
||||
// if (networkInfoModel != null)
|
||||
// resultInfoModels.add(networkInfoModel);
|
||||
resultInfoModels.add(createMemoryResultInfoModel("Memory"));
|
||||
|
||||
resultInfoModels.add(createNetworkResultInfoModel("Network"));
|
||||
sutInfo.setChildResults(resultInfoModels);
|
||||
return sutInfo;
|
||||
|
||||
}
|
||||
|
||||
// private ResultInfoModel createNetworkResultInfoModel(String resultName,
|
||||
// List<String> results) {
|
||||
// if (results.size() <= 0)
|
||||
// return null;
|
||||
// ResultInfoModel resultInfoModel = new ResultInfoModel(resultName,
|
||||
// new ArrayList<ResultInfoModel>());
|
||||
// for (String result : results) {
|
||||
// resultInfoModel.getChildResults().add(getNetworkResultInfo(result));
|
||||
// }
|
||||
// return resultInfoModel;
|
||||
// }
|
||||
|
||||
private ResultInfoModel createMemoryResultInfoModel(String resultName) {
|
||||
|
||||
|
@ -69,6 +54,16 @@ public class MonitorDescriptionInfoService extends BaseService {
|
|||
return resultInfoModel;
|
||||
}
|
||||
|
||||
private ResultInfoModel createNetworkResultInfoModel(String resultName) {
|
||||
|
||||
ResultInfoModel resultInfoModel = new ResultInfoModel(resultName,
|
||||
new ArrayList<ResultInfoModel>());
|
||||
|
||||
resultInfoModel.getChildResults().add(getNetworkResultInfo());
|
||||
|
||||
return resultInfoModel;
|
||||
}
|
||||
|
||||
private ResultInfoModel createCpuResultInfoModel(String resultName,
|
||||
List<String> results) {
|
||||
if (results.size() <= 0)
|
||||
|
@ -87,12 +82,6 @@ public class MonitorDescriptionInfoService extends BaseService {
|
|||
return getResultInfoModel(result, fields);
|
||||
}
|
||||
|
||||
// private ResultInfoModel getNetworkResultInfo(String result) {
|
||||
// String[] fields = new String[] { "bytesTotalPerSecond",
|
||||
// "bytesReceivedPerSecond", "bytesReceivedPerSecond" };
|
||||
// return getResultInfoModel(result, fields);
|
||||
// }
|
||||
|
||||
private ResultInfoModel getMemoryResultInfo() {
|
||||
String result = "Result";
|
||||
String[] fields = new String[] { "pagesPerSecond",
|
||||
|
@ -100,4 +89,15 @@ public class MonitorDescriptionInfoService extends BaseService {
|
|||
"committedBytes", "availableKiloBytes" };
|
||||
return getResultInfoModel(result, fields);
|
||||
}
|
||||
|
||||
private ResultInfoModel getNetworkResultInfo() {
|
||||
String result = "Result";
|
||||
List<String> fiels = new LinkedList<String>();
|
||||
for (Field field : NetworkInterfaceModel.class.getFields()) {
|
||||
fiels.add(field.getName());
|
||||
|
||||
}
|
||||
String[] toBeStored = new String[fiels.size()];
|
||||
return getResultInfoModel(result, fiels.toArray(toBeStored));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||
public class MonitorService extends BaseService {
|
||||
private String baseUrl = "monitorController";
|
||||
private Logger logger = Logger.getLogger(MonitorService.class);
|
||||
|
||||
public String getBaseUrl() {
|
||||
return baseUrl;
|
||||
}
|
||||
|
@ -32,12 +33,17 @@ public class MonitorService extends BaseService {
|
|||
@ModelAttribute("accessToken") String accessToken,
|
||||
@RequestParam("testPlanId") String testPlanId,
|
||||
@RequestParam String ip, String port) throws CustomGenericException {
|
||||
String scource = "MonitorService:getCpuList";
|
||||
try {
|
||||
MonitorProcessorResponseModel monitorProcessorResponseModel = getCpus(
|
||||
accessToken, testPlanId, ip, port, "0");
|
||||
ProcessorModel processorModel = monitorProcessorResponseModel
|
||||
.getProcessorModels().get(0);
|
||||
|
||||
ProcessorModel processorModel = null;
|
||||
List<ProcessorModel> processorModels = monitorProcessorResponseModel
|
||||
.getProcessorModels();
|
||||
if (processorModels.size() > 0)
|
||||
processorModel = processorModels.get(0);
|
||||
else
|
||||
return new ArrayList<String>();
|
||||
List<String> cpuList = new ArrayList<String>();
|
||||
for (ProcessorModelChild processorModelChild : processorModel
|
||||
.getProcessorModelList()) {
|
||||
|
@ -47,7 +53,7 @@ public class MonitorService extends BaseService {
|
|||
} catch (NullPointerException e) {
|
||||
logger.info(e.getStackTrace());
|
||||
throw new CustomGenericException("1", "error cpu list info"
|
||||
+ e.getCause(), scource);
|
||||
+ e.getCause(), "");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,7 +66,7 @@ public class MonitorService extends BaseService {
|
|||
Map<String, String> params = makeParamsMap(ip, port, testPlanId,
|
||||
startTime);
|
||||
|
||||
return (MonitorMemoryResponseModel)this.getCommunicateWithMaster()
|
||||
return (MonitorMemoryResponseModel) this.getCommunicateWithMaster()
|
||||
.getResponseModel(accessToken, url,
|
||||
MonitorMemoryResponseModel.class, params, caller);
|
||||
}
|
||||
|
@ -80,26 +86,27 @@ public class MonitorService extends BaseService {
|
|||
|
||||
}
|
||||
|
||||
// public List<String> getNetworkList(String accessToken, String testplanId,
|
||||
// String ip, String port) throws CustomGenericException {
|
||||
// String scource = "MonitorService:getNetworkList";
|
||||
// try {
|
||||
// MonitorNetworkReponseModel monitorNetworkReponseModel = getNetworks(
|
||||
// accessToken, testplanId, ip, port, "0");
|
||||
// NetworkInterfaceModel networkInterfaceModel = monitorNetworkReponseModel
|
||||
// .getModels().get(0);
|
||||
// List<String> networkList = new ArrayList<String>();
|
||||
// for (NetworkInterfaceModelChild networkInterfaceModelChild : networkInterfaceModel
|
||||
// .getNetworkList()) {
|
||||
// networkList.add(networkInterfaceModelChild.getInstance());
|
||||
// }
|
||||
// return networkList;
|
||||
// } catch (NullPointerException e) {
|
||||
// logger.info(e.getStackTrace());
|
||||
// throw new CustomGenericException("1", "error network list info"
|
||||
// + e.getCause(), scource);
|
||||
// }
|
||||
// }
|
||||
// public List<String> getNetworkList(String accessToken, String testplanId,
|
||||
// String ip, String port) throws CustomGenericException {
|
||||
// String scource = "MonitorService:getNetworkList";
|
||||
// try {
|
||||
// MonitorNetworkReponseModel monitorNetworkReponseModel = getNetworks(
|
||||
// accessToken, testplanId, ip, port, "0");
|
||||
// NetworkInterfaceModel networkInterfaceModel = monitorNetworkReponseModel
|
||||
// .getModels().get(0);
|
||||
// List<String> networkList = new ArrayList<String>();
|
||||
// for (NetworkInterfaceModelChild networkInterfaceModelChild :
|
||||
// networkInterfaceModel
|
||||
// .getNetworkList()) {
|
||||
// networkList.add(networkInterfaceModelChild.getInstance());
|
||||
// }
|
||||
// return networkList;
|
||||
// } catch (NullPointerException e) {
|
||||
// logger.info(e.getStackTrace());
|
||||
// throw new CustomGenericException("1", "error network list info"
|
||||
// + e.getCause(), scource);
|
||||
// }
|
||||
// }
|
||||
|
||||
public MonitorNetworkReponseModel getNetworks(String accessToken,
|
||||
String testplanId, String ip, String port, String startTime)
|
||||
|
|
|
@ -1 +1 @@
|
|||
masterAddress=133.133.12.1:7979/
|
||||
masterAddress=127.0.0.1:7979/
|
|
@ -2,6 +2,7 @@ package org.bench4q.web.api.test;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bench4q.share.models.master.ScriptModel;
|
||||
import org.bench4q.web.TestPlan.RunTestPlan;
|
||||
import org.bench4q.web.api.ScriptActionController;
|
||||
|
@ -15,6 +16,7 @@ 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" })
|
||||
|
@ -23,14 +25,8 @@ public class RunTestPlanTest {
|
|||
private ScriptActionController scriptActionController;
|
||||
private RunTestPlan runTestPlan;
|
||||
private LoginHelper loginHelper;
|
||||
public LoginHelper getLoginHelper() {
|
||||
return loginHelper;
|
||||
}
|
||||
@Autowired
|
||||
public void setLoginHelper(LoginHelper loginHelper) {
|
||||
this.loginHelper = loginHelper;
|
||||
}
|
||||
private String accessToken;
|
||||
|
||||
private ScriptActionController getScriptActionController() {
|
||||
return scriptActionController;
|
||||
}
|
||||
|
@ -50,9 +46,18 @@ public class RunTestPlanTest {
|
|||
this.runTestPlan = runTestPlan;
|
||||
}
|
||||
|
||||
public LoginHelper getLoginHelper() {
|
||||
return loginHelper;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setLoginHelper(LoginHelper loginHelper) {
|
||||
this.loginHelper = loginHelper;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.accessToken = loginHelper.Login();
|
||||
this.accessToken = this.getLoginHelper().login();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -73,10 +78,10 @@ public class RunTestPlanTest {
|
|||
webScriptModels.add(webScriptModel);
|
||||
testPlanRequestModel.setScriptList(webScriptModels);
|
||||
this.getRunTestPlan().runTestPlan(accessToken, testPlanRequestModel,
|
||||
this.getLoginHelper().modelMap);
|
||||
new ModelMap());
|
||||
testPlanRequestModel.setTestPlanName("test");
|
||||
testPlanRequestModel.setIpList(new ArrayList<String>());
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,17 +26,8 @@ import com.google.gson.Gson;
|
|||
@ContextConfiguration(locations = { "file:src/main/resources/bench4qweb-servlet.xml" })
|
||||
public class ScriptActionControllerTest {
|
||||
private ScriptActionController scriptActionController;
|
||||
private LoginHelper loginHelper;
|
||||
private String accessToken;
|
||||
|
||||
public LoginHelper getLoginHelper() {
|
||||
return loginHelper;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setLoginHelper(LoginHelper loginHelper) {
|
||||
this.loginHelper = loginHelper;
|
||||
}
|
||||
private LoginHelper loginHelper;
|
||||
|
||||
public ScriptActionController getScriptActionController() {
|
||||
return scriptActionController;
|
||||
|
@ -48,9 +39,17 @@ public class ScriptActionControllerTest {
|
|||
this.scriptActionController = scriptActionController;
|
||||
}
|
||||
|
||||
public LoginHelper getLoginHelper() {
|
||||
return loginHelper;
|
||||
}
|
||||
|
||||
public void setLoginHelper(LoginHelper loginHelper) {
|
||||
this.loginHelper = loginHelper;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.accessToken = this.getLoginHelper().Login();
|
||||
this.accessToken = this.getLoginHelper().login();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -65,7 +64,7 @@ public class ScriptActionControllerTest {
|
|||
public void uploadPluginEditedScript() throws CustomGenericException {
|
||||
@SuppressWarnings("unchecked")
|
||||
int insertCountBefore = ((List<ScriptModel>) scriptActionController
|
||||
.loadScript(loginHelper.Login()).getData()).size();
|
||||
.loadScript(accessToken).getData()).size();
|
||||
PluginEditScriptRequestModel pluginEditScriptRequestModel = new PluginEditScriptRequestModel();
|
||||
pluginEditScriptRequestModel
|
||||
.setBehaviorModels(createBheBehaviorModels());
|
||||
|
@ -74,12 +73,12 @@ public class ScriptActionControllerTest {
|
|||
pluginEditScriptRequestModel.setScriptName("testScriptName");
|
||||
Gson gson = new Gson();
|
||||
BaseResponseModel baseResponseModel = scriptActionController
|
||||
.uploadPluginEditedScript(loginHelper.Login(),
|
||||
.uploadPluginEditedScript(accessToken,
|
||||
gson.toJson(pluginEditScriptRequestModel));
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
int insertCountAfter = ((List<ScriptModel>) scriptActionController
|
||||
.loadScript(loginHelper.Login()).getData()).size();
|
||||
.loadScript(accessToken).getData()).size();
|
||||
Assert.assertTrue(baseResponseModel.isSuccess());
|
||||
Assert.assertEquals(insertCountBefore + 1, insertCountAfter);
|
||||
}
|
||||
|
|
|
@ -1,20 +1,26 @@
|
|||
package org.bench4q.web.api.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
import junit.framework.Assert;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.share.enums.master.TestPlanStatus;
|
||||
import org.bench4q.share.helper.ExceptionLog;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptPagesBriefModel;
|
||||
import org.bench4q.web.api.TestPlanActionController;
|
||||
import org.bench4q.web.exception.CustomGenericException;
|
||||
import org.bench4q.web.model.BaseResponseModel;
|
||||
import org.bench4q.web.model.ResultModel;
|
||||
import org.bench4q.web.model.SutInfo;
|
||||
import org.bench4q.web.model.WebTestPlanResultModel;
|
||||
import org.bench4q.web.service.TestPlanService;
|
||||
import org.bench4q.web.tool.test.GsonHelper;
|
||||
import org.bench4q.web.tool.test.LoginHelper;
|
||||
import org.bench4q.web.tool.test.StartTestPlan;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -22,33 +28,18 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "file:src/test/resources/bench4qweb-servlet.xml" })
|
||||
public class TestResultTest {
|
||||
private LoginHelper loginHelper;
|
||||
private Logger logger = Logger.getLogger(TestResultTest.class);
|
||||
public class TestResultTest extends LoginHelper {
|
||||
private TestPlanActionController testPlanActionController;
|
||||
private StartTestPlan startTestPlan;
|
||||
|
||||
private String testPlanId;
|
||||
private String accessToken;
|
||||
|
||||
public StartTestPlan getStartTestPlan() {
|
||||
return startTestPlan;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setStartTestPlan(StartTestPlan startTestPlan) {
|
||||
this.startTestPlan = startTestPlan;
|
||||
}
|
||||
|
||||
public LoginHelper getLoginHelper() {
|
||||
return loginHelper;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setLoginHelper(LoginHelper loginHelper) {
|
||||
this.loginHelper = loginHelper;
|
||||
}
|
||||
private Logger logger = Logger.getLogger(TestResultTest.class);
|
||||
private TestPlanService testPlanService;
|
||||
private String scriptId;
|
||||
|
||||
public TestPlanActionController getTestPlanActionController() {
|
||||
return testPlanActionController;
|
||||
|
@ -60,20 +51,44 @@ public class TestResultTest {
|
|||
this.testPlanActionController = testPlanActionController;
|
||||
}
|
||||
|
||||
public StartTestPlan getStartTestPlan() {
|
||||
return startTestPlan;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setStartTestPlan(StartTestPlan startTestPlan) {
|
||||
this.startTestPlan = startTestPlan;
|
||||
}
|
||||
|
||||
public TestPlanService getTestPlanService() {
|
||||
return testPlanService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setTestPlanService(TestPlanService testPlanService) {
|
||||
this.testPlanService = testPlanService;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.accessToken = loginHelper.Login();
|
||||
this.startTestPlan.startTest();
|
||||
this.accessToken = this.login();
|
||||
this.startTestPlan.startTest(accessToken);
|
||||
this.testPlanId = this.startTestPlan.getTestPlanRunId();
|
||||
this.scriptId = this.getOneScriptId(testPlanId);
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void clean() throws CustomGenericException {
|
||||
this.getStartTestPlan().cleanUpTest(this.accessToken);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getReplaceList() throws CustomGenericException,
|
||||
JAXBException {
|
||||
Assert.assertNotNull(this.getStartTestPlan().getTestPlanRunId());
|
||||
BaseResponseModel baseResponseModel = this
|
||||
.getTestPlanActionController().getReplaceList(
|
||||
loginHelper.Login(),
|
||||
.getTestPlanActionController().getReplaceList(this.accessToken,
|
||||
this.startTestPlan.getTestPlanRunId());
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Integer> scriptIdMap = (Map<String, Integer>) baseResponseModel
|
||||
|
@ -90,24 +105,77 @@ public class TestResultTest {
|
|||
.getSutInfo(accessToken,
|
||||
this.getStartTestPlan().getTestPlanRunId()).getData();
|
||||
for (SutInfo sutInfo : sutInfos) {
|
||||
Assert.assertEquals("5556", sutInfo.getPort());
|
||||
Assert.assertEquals("133.133.12.3", sutInfo.getIp());
|
||||
assertEquals("5556", sutInfo.getPort());
|
||||
assertEquals("133.133.12.3", sutInfo.getIp());
|
||||
Gson gson = new Gson();
|
||||
logger.info(gson.toJson(sutInfo));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getScriptBehaviorBriefModel()
|
||||
throws CustomGenericException, JAXBException {
|
||||
Assert.assertNotNull(this.getStartTestPlan().getTestPlanRunId());
|
||||
public void test_getTestPageBriefModel() throws InterruptedException,
|
||||
CustomGenericException, JAXBException {
|
||||
assertNotNull(this.testPlanId);
|
||||
assertNotNull(this.scriptId);
|
||||
Thread.sleep(3000);
|
||||
WebTestPlanResultModel webTestPlanResultModel = this
|
||||
.queryTestPlanResultModel(testPlanId);
|
||||
assertEquals(TestPlanStatus.InRunning,
|
||||
webTestPlanResultModel.getCurrentStatus());
|
||||
BaseResponseModel baseResponseModel = this
|
||||
.getTestPlanActionController().getScriptPageBriefModel(
|
||||
accessToken, testPlanId, scriptId);
|
||||
ScriptPagesBriefModel scriptPagesBriefModel = (ScriptPagesBriefModel) baseResponseModel
|
||||
.getData();
|
||||
logger.info(GsonHelper.getGson().toJson(scriptPagesBriefModel));
|
||||
assertTrue(scriptPagesBriefModel.getScriptPageBriefModels().size() > 0);
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void test_getScriptBriefStatus() throws NoSuchFieldException,
|
||||
CustomGenericException, JAXBException, InterruptedException {
|
||||
Assert.assertNotNull(testPlanId);
|
||||
String scriptId = getOneScriptId(this.getStartTestPlan()
|
||||
.getTestPlanRunId());
|
||||
Assert.assertNotNull(scriptId);
|
||||
Thread.sleep(3000);
|
||||
BaseResponseModel baseResponseModelForTestPlan = this
|
||||
.getTestPlanActionController().queryTestPlan(accessToken,
|
||||
this.testPlanId);
|
||||
assertTrue(baseResponseModelForTestPlan.isSuccess());
|
||||
WebTestPlanResultModel webTestPlanResultModel = (WebTestPlanResultModel) baseResponseModelForTestPlan
|
||||
.getData();
|
||||
assertEquals(TestPlanStatus.InRunning,
|
||||
webTestPlanResultModel.getCurrentStatus());
|
||||
BaseResponseModel baseResponseModel = this
|
||||
.getTestPlanActionController().getScriptBriefStatus(
|
||||
accessToken, this.testPlanId,
|
||||
this.getOneScriptId(this.testPlanId),
|
||||
"averageResponseTime", "0");
|
||||
assertTrue(baseResponseModel.isSuccess());
|
||||
List<ResultModel> resultModels = (List<ResultModel>) baseResponseModel
|
||||
.getData();
|
||||
Logger.getLogger("get result model");
|
||||
Logger.getLogger(TestResultTest.class).info(
|
||||
"resultModel:" + GsonHelper.getGson().toJson(resultModels));
|
||||
assertTrue(resultModels.size() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getScriptBehaviorBriefModel()
|
||||
throws CustomGenericException, JAXBException, InterruptedException {
|
||||
assertNotNull(this.testPlanId);
|
||||
String scriptId = getOneScriptId(this.getStartTestPlan()
|
||||
.getTestPlanRunId());
|
||||
Thread.sleep(3000);
|
||||
BaseResponseModel baseResponseModel = this
|
||||
.getTestPlanActionController().getScriptBehaviorBriefModel(
|
||||
accessToken,
|
||||
this.getStartTestPlan().getTestPlanRunId(), scriptId);
|
||||
accessToken, this.testPlanId, scriptId);
|
||||
ScriptBehaviorsBriefModel scriptBehaviorsBriefModel = (ScriptBehaviorsBriefModel) baseResponseModel
|
||||
.getData();
|
||||
logger.info(GsonHelper.getGson().toJson(scriptBehaviorsBriefModel));
|
||||
Assert.assertNotNull(scriptBehaviorsBriefModel);
|
||||
Assert.assertNotNull(scriptBehaviorsBriefModel
|
||||
.getTestBehaviorsBriefModel());
|
||||
|
@ -117,6 +185,7 @@ public class TestResultTest {
|
|||
|
||||
private String getOneScriptId(String testPlanRunId) {
|
||||
try {
|
||||
|
||||
return queryTestPlanResultModel(testPlanRunId).getScriptIds()
|
||||
.get(0).toString();
|
||||
} catch (CustomGenericException e) {
|
||||
|
@ -133,9 +202,10 @@ public class TestResultTest {
|
|||
|
||||
private WebTestPlanResultModel queryTestPlanResultModel(String testPlanRunId)
|
||||
throws CustomGenericException, JAXBException {
|
||||
return (WebTestPlanResultModel) this
|
||||
WebTestPlanResultModel webTestPlanResultModel = (WebTestPlanResultModel) this
|
||||
.getTestPlanActionController()
|
||||
.queryTestPlan(accessToken,
|
||||
this.getStartTestPlan().getTestPlanRunId()).getData();
|
||||
return webTestPlanResultModel;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package org.bench4q.web.tool.test;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public class GsonHelper {
|
||||
|
||||
public static Gson getGson() {
|
||||
return new Gson();
|
||||
}
|
||||
}
|
|
@ -1,19 +1,19 @@
|
|||
package org.bench4q.web.tool.test;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.share.helper.ExceptionLog;
|
||||
import org.bench4q.share.models.master.UserModel;
|
||||
import org.bench4q.web.api.AuthorizeActionController;
|
||||
import org.bench4q.web.exception.CustomGenericException;
|
||||
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;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.ui.ModelMap;
|
||||
|
||||
@Component
|
||||
public class LoginHelper {
|
||||
private AuthorizeActionController authorizeActionController;
|
||||
public ModelMap modelMap = new ModelMap();
|
||||
|
||||
private Logger logger = Logger.getLogger(LoginHelper.class);
|
||||
|
||||
public AuthorizeActionController getAuthorizeActionController() {
|
||||
return authorizeActionController;
|
||||
|
@ -25,22 +25,22 @@ public class LoginHelper {
|
|||
this.authorizeActionController = authorizeActionController;
|
||||
}
|
||||
|
||||
public String Login() {
|
||||
public String login() {
|
||||
|
||||
UserModel userModel = new UserModel();
|
||||
userModel.setUserName("www");
|
||||
userModel.setPassword("www");
|
||||
userModel.setUserName("admin");
|
||||
userModel.setPassword("admin");
|
||||
try {
|
||||
if (this.getAuthorizeActionController() == null) {
|
||||
System.out.println("null");
|
||||
if (this.authorizeActionController == null) {
|
||||
System.out.println(" null");
|
||||
}
|
||||
this.getAuthorizeActionController().login(userModel, modelMap);
|
||||
ModelMap modelMap = new ModelMap();
|
||||
authorizeActionController.login(userModel, modelMap);
|
||||
String accessToken = (String) modelMap.get("accessToken");
|
||||
return accessToken;
|
||||
} catch (CustomGenericException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
logger.info(ExceptionLog.getStackTrace(e));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,28 +2,36 @@ package org.bench4q.web.tool.test;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||
import org.bench4q.share.models.master.OperateScriptServerResponseModel;
|
||||
import org.bench4q.share.models.master.ScriptModel;
|
||||
import org.bench4q.web.api.ScriptActionController;
|
||||
import org.bench4q.web.exception.CustomGenericException;
|
||||
import org.bench4q.web.extractObjectFromXml.ObjectXmlExchange;
|
||||
import org.bench4q.web.model.BaseResponseModel;
|
||||
import org.bench4q.web.service.ScriptService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
@Component
|
||||
public class ScriptHelper {
|
||||
|
||||
private String filePath = "src/test/resources/script.xml";
|
||||
|
||||
private ScriptService scriptService;
|
||||
private ScriptModel scriptModel;
|
||||
|
||||
private ScriptActionController scriptActionController;
|
||||
|
||||
public ScriptService getScriptService() {
|
||||
return scriptService;
|
||||
|
@ -34,6 +42,16 @@ public class ScriptHelper {
|
|||
this.scriptService = scriptService;
|
||||
}
|
||||
|
||||
public ScriptActionController getScriptActionController() {
|
||||
return scriptActionController;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setScriptActionController(
|
||||
ScriptActionController scriptActionController) {
|
||||
this.scriptActionController = scriptActionController;
|
||||
}
|
||||
|
||||
public RunScenarioModel getRunScenarioModelFormFile() throws JAXBException,
|
||||
IOException {
|
||||
String scriptContent = FileUtils.readFileToString(new File(filePath));
|
||||
|
@ -41,20 +59,32 @@ public class ScriptHelper {
|
|||
RunScenarioModel.class, scriptContent);
|
||||
}
|
||||
|
||||
public int upLoadScriptAndGetId() throws JAXBException, IOException,
|
||||
CustomGenericException {
|
||||
LoginHelper loginHelper = new LoginHelper();
|
||||
public void deleteScript(String accessToken) throws CustomGenericException {
|
||||
|
||||
String scriptName = "testScript";
|
||||
BaseResponseModel baseResponseModel = this.getScriptActionController()
|
||||
.deletescript(accessToken,
|
||||
(new Integer(this.scriptModel.getId())).toString());
|
||||
Gson goGson = new Gson();
|
||||
Logger.getLogger(ScriptHelper.class).info(
|
||||
goGson.toJson(baseResponseModel));
|
||||
if (baseResponseModel.isSuccess())
|
||||
Logger.getLogger(ScriptHelper.class).info("delete script");
|
||||
}
|
||||
|
||||
public ScriptModel upLoadScriptAndGetId(String accessToken)
|
||||
throws JAXBException, IOException, CustomGenericException {
|
||||
|
||||
String scriptName = "testScript" + UUID.randomUUID();
|
||||
String scriptContent = MarshalHelper.marshal(RunScenarioModel.class,
|
||||
getRunScenarioModelFormFile());
|
||||
OperateScriptServerResponseModel operateScriptServerResponseModel = this
|
||||
.getScriptService().uploadScript(loginHelper.Login(),
|
||||
scriptContent, scriptName);
|
||||
.getScriptService().uploadScript(accessToken, scriptContent,
|
||||
scriptName);
|
||||
Assert.assertTrue(operateScriptServerResponseModel.isSuccess());
|
||||
ScriptModel scriptModel = this.getScriptService().queryScriptByName(
|
||||
scriptName, loginHelper.Login());
|
||||
return scriptModel.getId();
|
||||
scriptName, accessToken);
|
||||
this.scriptModel = scriptModel;
|
||||
return scriptModel;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,15 +21,14 @@ import org.springframework.ui.ModelMap;
|
|||
public class StartTestPlan {
|
||||
private final String MONITOR_IP = "133.133.12.3";
|
||||
private ScriptHelper scriptHelper;
|
||||
private LoginHelper loginHelper;
|
||||
private TestPlanActionController testPlanActionController;
|
||||
private String testPlanRunId;
|
||||
|
||||
|
||||
public TestPlanActionController getTestPlanActionController() {
|
||||
return testPlanActionController;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@Autowired
|
||||
public void setTestPlanActionController(
|
||||
TestPlanActionController testPlanActionController) {
|
||||
this.testPlanActionController = testPlanActionController;
|
||||
|
@ -44,15 +43,6 @@ public class StartTestPlan {
|
|||
this.scriptHelper = scriptHelper;
|
||||
}
|
||||
|
||||
public LoginHelper getLoginHelper() {
|
||||
return loginHelper;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setLoginHelper(LoginHelper loginHelper) {
|
||||
this.loginHelper = loginHelper;
|
||||
}
|
||||
|
||||
public String getTestPlanRunId() {
|
||||
return testPlanRunId;
|
||||
}
|
||||
|
@ -61,13 +51,13 @@ public class StartTestPlan {
|
|||
this.testPlanRunId = testPlanRunId;
|
||||
}
|
||||
|
||||
public void startTest() {
|
||||
|
||||
public void startTest(String accessToken) {
|
||||
try {
|
||||
TestPlanResultModel testPlanResultModel = (TestPlanResultModel) this
|
||||
.getTestPlanActionController()
|
||||
.runTestPlan(this.getLoginHelper().Login(), new ModelMap(),
|
||||
createTestPlanWithMonitor()).getData();
|
||||
.runTestPlan(accessToken, new ModelMap(),
|
||||
createTestPlanWithMonitor(accessToken)).getData();
|
||||
|
||||
this.setTestPlanRunId(testPlanResultModel.getTestPlanId()
|
||||
.toString());
|
||||
} catch (Exception e) {
|
||||
|
@ -76,28 +66,36 @@ public class StartTestPlan {
|
|||
}
|
||||
}
|
||||
|
||||
public TestPlanRequestModel createTestPlanWithMonitor()
|
||||
public TestPlanRequestModel createTestPlanWithMonitor(String accessToken)
|
||||
throws JAXBException, IOException, CustomGenericException {
|
||||
List<String> ipList = new ArrayList<>();
|
||||
ipList.add(MONITOR_IP);
|
||||
TestPlanRequestModel testPlanRequestModel = new TestPlanRequestModel();
|
||||
testPlanRequestModel.setIpList(ipList);
|
||||
testPlanRequestModel.setTestPlanName("forTest");
|
||||
testPlanRequestModel.setScriptList(generateWebScriptModels());
|
||||
testPlanRequestModel
|
||||
.setScriptList(generateWebScriptModels(accessToken));
|
||||
return testPlanRequestModel;
|
||||
}
|
||||
// private void deleteTestPlan(String accessToken){
|
||||
//
|
||||
// }
|
||||
|
||||
private List<WebScriptModel> generateWebScriptModels()
|
||||
private List<WebScriptModel> generateWebScriptModels(String accessToken)
|
||||
throws JAXBException, IOException, CustomGenericException {
|
||||
List<WebScriptModel> scriptList = new ArrayList<WebScriptModel>();
|
||||
WebScriptModel webScriptModel = new WebScriptModel();
|
||||
webScriptModel.setCooldown(1);
|
||||
webScriptModel.setExecuteRange(50);
|
||||
webScriptModel.setId(this.getScriptHelper().upLoadScriptAndGetId());
|
||||
webScriptModel.setId(this.getScriptHelper().upLoadScriptAndGetId(
|
||||
accessToken).getId());
|
||||
webScriptModel.setLoad(30);
|
||||
webScriptModel.setWarmup(1);
|
||||
scriptList.add(webScriptModel);
|
||||
return scriptList;
|
||||
|
||||
}
|
||||
public void cleanUpTest(String accessToken) throws CustomGenericException{
|
||||
this.getScriptHelper().deleteScript(accessToken);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
package org.bench4q.web.tool.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bench4q.share.models.master.ScriptModel;
|
||||
import org.bench4q.web.api.ScriptActionController;
|
||||
import org.bench4q.web.exception.CustomGenericException;
|
||||
import org.bench4q.web.model.BaseResponseModel;
|
||||
import org.bench4q.web.tool.test.LoginHelper;
|
||||
import org.bench4q.web.tool.test.StartTestPlan;
|
||||
import org.junit.After;
|
||||
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 TestLoginHelper {
|
||||
private LoginHelper loginHelper;
|
||||
|
||||
private ScriptActionController scriptActionController;
|
||||
private StartTestPlan startTestPlan;
|
||||
|
||||
public LoginHelper getLoginHelper() {
|
||||
return loginHelper;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setLoginHelper(LoginHelper loginHelper) {
|
||||
this.loginHelper = loginHelper;
|
||||
}
|
||||
|
||||
public StartTestPlan getStartTestPlan() {
|
||||
return startTestPlan;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setStartTestPlan(StartTestPlan startTestPlan) {
|
||||
this.startTestPlan = startTestPlan;
|
||||
}
|
||||
|
||||
public ScriptActionController getScriptActionController() {
|
||||
return scriptActionController;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setScriptActionController(
|
||||
ScriptActionController scriptActionController) {
|
||||
this.scriptActionController = scriptActionController;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoginHelper() {
|
||||
String accessToken = this.getLoginHelper().login();
|
||||
|
||||
assertNotNull(accessToken);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testLoginHelperRight() throws CustomGenericException {
|
||||
String accessToken = this.getLoginHelper().login();
|
||||
BaseResponseModel baseResponseModel = this
|
||||
.getScriptActionController().loadScript(accessToken);
|
||||
List<ScriptModel> scriptModels=(List<ScriptModel>)
|
||||
baseResponseModel.getData();
|
||||
assertTrue(baseResponseModel.isSuccess());
|
||||
assertTrue(scriptModels.size()>0);
|
||||
|
||||
}
|
||||
@Test
|
||||
public void testLoginInStartTest() throws CustomGenericException{
|
||||
String accessToken = this.getLoginHelper().login();
|
||||
this.getStartTestPlan().startTest(accessToken);
|
||||
assertNotNull(this.getStartTestPlan().getTestPlanRunId());
|
||||
|
||||
}
|
||||
@After
|
||||
public void clean() throws CustomGenericException{
|
||||
String accessToken = this.getLoginHelper().login();
|
||||
this.getStartTestPlan().cleanUpTest(accessToken);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue