refactor the testplanControler's api to pure restful
refactor the testplanControler's api to pure restful
This commit is contained in:
parent
dcf91a19b1
commit
7d7d8c7837
|
@ -21,14 +21,17 @@ import org.bench4q.master.exception.Bench4QException;
|
|||
import org.bench4q.master.exception.ExceptionLog;
|
||||
import org.bench4q.recorder.ScriptCapturer;
|
||||
import org.bench4q.share.models.master.OperateScriptServerResponseModel;
|
||||
import org.bench4q.share.models.master.ScriptFilterModel;
|
||||
import org.bench4q.share.models.master.ScriptModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Controller
|
||||
|
@ -116,8 +119,7 @@ public class ScriptController extends BaseController {
|
|||
this.getScriptCapturer().startRecordServer(port.getPort());
|
||||
|
||||
return buildReponseModel(true, "", this.getScriptCapturer()
|
||||
.getIpHttpCaptureServerAdress(), port.getPort(), null, null,
|
||||
"");
|
||||
.getIpHttpCaptureServerAdress(), port.getPort(), null, null, "");
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/startScriptRecording", method = {
|
||||
|
@ -131,8 +133,8 @@ public class ScriptController extends BaseController {
|
|||
null, null);
|
||||
}
|
||||
UUID uuid = UUID.randomUUID();
|
||||
this.getScriptCapturer().startRecording(port,
|
||||
buildScriptSavePath(), uuid.toString());
|
||||
this.getScriptCapturer().startRecording(port, buildScriptSavePath(),
|
||||
uuid.toString());
|
||||
|
||||
return buildReponseModel(true, "RecordServer stop", "", port, null,
|
||||
null, uuid.toString());
|
||||
|
@ -325,15 +327,16 @@ public class ScriptController extends BaseController {
|
|||
RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT })
|
||||
@ResponseBody
|
||||
public OperateScriptServerResponseModel updateScript(
|
||||
@PathVariable int scriptId, @RequestParam String content, @RequestParam String scriptName) {
|
||||
@PathVariable int scriptId, @RequestParam String content,
|
||||
@RequestParam String scriptName) {
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
Logger.getLogger(ScriptController.class).info("no power");
|
||||
return null;
|
||||
}
|
||||
return this.buildReponseModel(
|
||||
this.getScriptService().alterScriptContent(scriptId,
|
||||
this.getPrincipal().getId(),content,scriptName), "", "", 0, null,
|
||||
null, null);
|
||||
this.getPrincipal().getId(), content, scriptName), "",
|
||||
"", 0, null, null, null);
|
||||
}
|
||||
|
||||
// @RequestMapping(value = "updateScript/{scriptId}", method = {
|
||||
|
@ -341,8 +344,10 @@ public class ScriptController extends BaseController {
|
|||
// @ResponseBody
|
||||
// public OperateScriptServerResponseModel updateScript(
|
||||
// @PathVariable int scriptId,
|
||||
// @RequestParam(value = "paramContents[]", required = true) List<String> paramContents,
|
||||
// @RequestParam(value = "paramFiles[]", required = false) List<MultipartFile> paramFiles)
|
||||
// @RequestParam(value = "paramContents[]", required = true) List<String>
|
||||
// paramContents,
|
||||
// @RequestParam(value = "paramFiles[]", required = false)
|
||||
// List<MultipartFile> paramFiles)
|
||||
// throws Bench4QException {
|
||||
// if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
// throw new Bench4QException(HAVE_NO_POWER, HAVE_NO_POWER
|
||||
|
@ -379,4 +384,16 @@ public class ScriptController extends BaseController {
|
|||
return responseModel;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/loadFilterTypeList", method = RequestMethod.GET)
|
||||
@ResponseStatus(value = HttpStatus.OK)
|
||||
@ResponseBody
|
||||
public ScriptFilterModel loadFilterTypeList() throws Bench4QException {
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
throw new Bench4QException(HAVE_NO_POWER,
|
||||
"You don't have enough power to get filter type list!",
|
||||
"/loadFilterTypeList");
|
||||
}
|
||||
String[] filterTypeList = this.getScriptService().loadFilterTypeList();
|
||||
return new ScriptFilterModel(filterTypeList);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,6 @@ import org.springframework.web.bind.annotation.PathVariable;
|
|||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
|
@ -98,8 +97,7 @@ public class TestPlanController extends BaseController {
|
|||
this.testPlanScriptResultService = testPlanScriptResultService;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/run", method = { RequestMethod.POST,
|
||||
RequestMethod.GET })
|
||||
@RequestMapping(value = "/run", method = RequestMethod.PUT)
|
||||
@ResponseStatus(value = HttpStatus.OK)
|
||||
@ResponseBody
|
||||
public TestPlanResultModel runTestPlanWithTestPlanModel(
|
||||
|
@ -132,12 +130,11 @@ public class TestPlanController extends BaseController {
|
|||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/getRunningInfo", method = { RequestMethod.GET,
|
||||
RequestMethod.POST })
|
||||
@RequestMapping(value = "/{testPlanId}/runningInfo", method = { RequestMethod.GET })
|
||||
@ResponseStatus(value = HttpStatus.OK)
|
||||
@ResponseBody
|
||||
public TestPlanResultModel getTestPlanRunningInfo(
|
||||
@RequestParam UUID testPlanId) throws Bench4QException {
|
||||
@PathVariable UUID testPlanId) throws Bench4QException {
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
throw new Bench4QException(HAVE_NO_POWER,
|
||||
"You have not power to get test plan running info",
|
||||
|
@ -147,7 +144,7 @@ public class TestPlanController extends BaseController {
|
|||
return this.getTestPlanService().buildResultModel(testPlanId);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/scriptBrief/{testPlanId}/{scriptId}/{duationBegin}", method = RequestMethod.GET)
|
||||
@RequestMapping(value = "/{testPlanId}/scriptBrief/{scriptId}/{duationBegin}", method = RequestMethod.GET)
|
||||
@ResponseStatus(value = HttpStatus.OK)
|
||||
@ResponseBody
|
||||
public TestPlanScriptBriefResultModel getScriptBrief(
|
||||
|
@ -169,7 +166,7 @@ public class TestPlanController extends BaseController {
|
|||
return ret;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/getBehaviorsBrief/{testPlanRunID}/{scriptId}")
|
||||
@RequestMapping(value = "/{testPlanRunID}/behaviorsBrief/{scriptId}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public ScriptBehaviorsBriefModel getBehaviorsBrief(
|
||||
@PathVariable UUID testPlanRunID, @PathVariable int scriptId)
|
||||
|
@ -184,7 +181,7 @@ public class TestPlanController extends BaseController {
|
|||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/pagesBrief/{testPlanRunId}/{scriptId}")
|
||||
@RequestMapping(value = "/{testPlanRunId}/pagesBrief/{scriptId}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public ScriptPagesBriefModel getPagesBrief(
|
||||
@PathVariable UUID testPlanRunId, @PathVariable int scriptId)
|
||||
|
@ -199,49 +196,45 @@ public class TestPlanController extends BaseController {
|
|||
return pagesBriefModel;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/loadTestPlans", method = { RequestMethod.GET,
|
||||
RequestMethod.POST })
|
||||
@RequestMapping(value = "/", method = RequestMethod.GET)
|
||||
@ResponseStatus(value = HttpStatus.OK)
|
||||
@ResponseBody
|
||||
public TestPlanResponseModel loadTestPlans() {
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
return buildTestPlanResponseModel(false, "no scope", null, null);
|
||||
return buildTestPlanResponseModel(false, "no scope", null);
|
||||
}
|
||||
List<TestPlan> testPlanDBs = this.testPlanService.loadTestPlans(this
|
||||
.getPrincipal());
|
||||
return testPlanDBs == null ? buildTestPlanResponseModel(false,
|
||||
"exception", null, null) : buildTestPlanResponseModel(true,
|
||||
null, testPlanDBs, null);
|
||||
"exception", null) : buildTestPlanResponseModel(true, null,
|
||||
testPlanDBs);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/queryTestPlan/{runId}", method = RequestMethod.GET)
|
||||
@RequestMapping(value = "/{runId}", method = RequestMethod.GET)
|
||||
@ResponseStatus(value = HttpStatus.OK)
|
||||
@ResponseBody
|
||||
public TestPlanDBModel queryTestPlan(@PathVariable UUID runId)
|
||||
throws Bench4QException {
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
throw new Bench4QException(HAVE_NO_POWER, HAVE_NO_POWER,
|
||||
"/queryTestPlan/{runId}");
|
||||
throw new Bench4QException(HAVE_NO_POWER, HAVE_NO_POWER, "/{runId}");
|
||||
}
|
||||
return this.getTestPlanService().getTestPlanDBModel(runId);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/removeTestPlanFromPool", method = {
|
||||
RequestMethod.GET, RequestMethod.POST })
|
||||
@RequestMapping(value = "/{testPlanId}", method = { RequestMethod.DELETE })
|
||||
@ResponseStatus(value = HttpStatus.OK)
|
||||
@ResponseBody
|
||||
public TestPlanResponseModel removeTestPlanFromPool(int testPlanId) {
|
||||
public TestPlanResponseModel removeTestPlanFromPool(
|
||||
@PathVariable int testPlanId) {
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
return buildTestPlanResponseModel(false, "no scope", null, null);
|
||||
return buildTestPlanResponseModel(false, "no scope", null);
|
||||
}
|
||||
return buildTestPlanResponseModel(
|
||||
this.testPlanService.removeTestPlanInDB(testPlanId), null,
|
||||
null, null);
|
||||
this.testPlanService.removeTestPlanInDB(testPlanId), null, null);
|
||||
}
|
||||
|
||||
private TestPlanResponseModel buildTestPlanResponseModel(boolean success,
|
||||
String failCause, List<TestPlan> testPlanDBs,
|
||||
String[] filterTypeList) {
|
||||
String failCause, List<TestPlan> testPlanDBs) {
|
||||
TestPlanResponseModel result = new TestPlanResponseModel();
|
||||
result.setSuccess(success);
|
||||
result.setFailCause(failCause);
|
||||
|
@ -252,16 +245,14 @@ public class TestPlanController extends BaseController {
|
|||
}
|
||||
}
|
||||
result.setTestPlanDBModels(modelList);
|
||||
result.setFilterTypeList(filterTypeList);
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/getTestPlanReport", method = { RequestMethod.GET,
|
||||
RequestMethod.POST })
|
||||
@RequestMapping(value = "/{testPlanRunID}/report", method = { RequestMethod.GET })
|
||||
@ResponseStatus(value = HttpStatus.OK)
|
||||
@ResponseBody
|
||||
public void getTestPlanReport(HttpServletResponse response,
|
||||
@RequestParam UUID testPlanRunID) throws Bench4QException {
|
||||
@PathVariable UUID testPlanRunID) throws Bench4QException {
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
throw new Bench4QException(HAVE_NO_POWER,
|
||||
"You have no power to get test plan report",
|
||||
|
@ -290,7 +281,7 @@ public class TestPlanController extends BaseController {
|
|||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/scriptBrief/{testPlanId}/{scriptId}/latestResult")
|
||||
@RequestMapping(value = "/{testPlanId}/scriptBrief/{scriptId}/latestResult", method = RequestMethod.GET)
|
||||
@ResponseStatus(value = HttpStatus.OK)
|
||||
@ResponseBody
|
||||
public ScriptBriefResultModel getLatestScriptResult(
|
||||
|
@ -304,7 +295,7 @@ public class TestPlanController extends BaseController {
|
|||
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/stop/{testPlanId}")
|
||||
@RequestMapping(value = "/{testPlanId}/stop", method = RequestMethod.POST)
|
||||
@ResponseStatus(value = HttpStatus.OK)
|
||||
@ResponseBody
|
||||
public TestPlanResponseModel stop(@PathVariable UUID testPlanId)
|
||||
|
@ -314,7 +305,7 @@ public class TestPlanController extends BaseController {
|
|||
guardIsTheOwner(testPlanId);
|
||||
return buildTestPlanResponseModel(
|
||||
this.getTestPlanRunner().stop(testPlanId), "",
|
||||
Collections.<TestPlan> emptyList(), null);
|
||||
Collections.<TestPlan> emptyList());
|
||||
}
|
||||
|
||||
private void guardIsTheOwner(UUID testPlanId) {
|
||||
|
@ -325,19 +316,4 @@ public class TestPlanController extends BaseController {
|
|||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/loadFilterTypeList", method = {
|
||||
RequestMethod.POST, RequestMethod.GET })
|
||||
@ResponseStatus(value = HttpStatus.OK)
|
||||
@ResponseBody
|
||||
public TestPlanResponseModel loadFilterTypeList() throws Bench4QException {
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
throw new Bench4QException(HAVE_NO_POWER,
|
||||
"You don't have enough power to get filter type list!",
|
||||
"/loadFilterTypeList");
|
||||
}
|
||||
String[] filterTypeList = this.getTestPlanService()
|
||||
.loadFilterTypeList();
|
||||
return this
|
||||
.buildTestPlanResponseModel(true, null, null, filterTypeList);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
package org.bench4q.master.domain.service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
@ -22,6 +26,7 @@ public class ScriptService {
|
|||
private ScriptRepositoty scriptRepositoty;
|
||||
private UserRepository userRepository;
|
||||
private Logger logger = Logger.getLogger(ScriptService.class);
|
||||
private Properties properties = null;
|
||||
|
||||
private ScriptRepositoty getScriptRepositoty() {
|
||||
return scriptRepositoty;
|
||||
|
@ -120,4 +125,29 @@ public class ScriptService {
|
|||
return this.getScriptRepositoty().update(script);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: refactor this, it's not good here in this format
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String[] loadFilterTypeList() {
|
||||
return getFilterTypeList();
|
||||
}
|
||||
|
||||
private String[] getFilterTypeList() {
|
||||
if (properties == null) {
|
||||
try {
|
||||
properties = new Properties();
|
||||
InputStream inputStream = ScriptService.class
|
||||
.getClassLoader()
|
||||
.getResourceAsStream(
|
||||
"org/bench4q/master/config/FilterType.properties");
|
||||
properties.load(inputStream);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return properties.getProperty("filter.type.list", "").split(",");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
package org.bench4q.master.domain.service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
@ -29,8 +26,6 @@ public class TestPlanService {
|
|||
private BusinessModelMapFactory businessMapFactory;
|
||||
private TestPlanRepository testPlanRepository;
|
||||
|
||||
private Properties properties = null;
|
||||
|
||||
private TestPlanRepository getTestPlanRepository() {
|
||||
return testPlanRepository;
|
||||
}
|
||||
|
@ -101,23 +96,5 @@ public class TestPlanService {
|
|||
public Collection<TestPlan> loadAllRunningTestPlans() {
|
||||
return this.getTestPlanRepository().loadRunningTestPlans();
|
||||
}
|
||||
public String[] loadFilterTypeList() {
|
||||
return getFilterTypeList();
|
||||
}
|
||||
|
||||
private String[] getFilterTypeList(){
|
||||
if(properties == null){
|
||||
try {
|
||||
properties = new Properties();
|
||||
InputStream inputStream = ScriptService.class.getClassLoader()
|
||||
.getResourceAsStream(
|
||||
"org/bench4q/master/config/FilterType.properties");
|
||||
properties.load(inputStream);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return properties.getProperty("filter.type.list","").split(",");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,7 +73,6 @@ public class HttpRequester {
|
|||
|
||||
public HttpResponse sendGet(String url, Map<String, String> params,
|
||||
Map<String, String> properties) throws IOException {
|
||||
|
||||
return this.send(url, "GET", params, "", properties);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package org.bench4q.share.models.master;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement
|
||||
public class ScriptFilterModel {
|
||||
private String[] filterTypeList;
|
||||
|
||||
public String[] getFilterTypeList() {
|
||||
return filterTypeList;
|
||||
}
|
||||
|
||||
public void setFilterTypeList(String[] filterTypeList) {
|
||||
this.filterTypeList = filterTypeList;
|
||||
}
|
||||
|
||||
public ScriptFilterModel() {
|
||||
}
|
||||
|
||||
public ScriptFilterModel(String[] filterTypeList) {
|
||||
this.filterTypeList = filterTypeList;
|
||||
}
|
||||
}
|
|
@ -11,7 +11,6 @@ public class TestPlanResponseModel {
|
|||
private boolean success;
|
||||
private String failCause;
|
||||
private List<TestPlanDBModel> testPlanDBModels;
|
||||
private String[] filterTypeList;
|
||||
|
||||
@XmlElement
|
||||
public boolean isSuccess() {
|
||||
|
@ -41,12 +40,4 @@ public class TestPlanResponseModel {
|
|||
this.testPlanDBModels = testPlanDBModels;
|
||||
}
|
||||
|
||||
public String[] getFilterTypeList() {
|
||||
return filterTypeList;
|
||||
}
|
||||
|
||||
public void setFilterTypeList(String[] filterTypeList) {
|
||||
this.filterTypeList = filterTypeList;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.util.LinkedList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
@ -16,6 +17,7 @@ import org.bench4q.share.models.agent.scriptrecord.BehaviorModel;
|
|||
import org.bench4q.share.models.agent.scriptrecord.PageModel;
|
||||
import org.bench4q.share.models.agent.scriptrecord.UsePluginModel;
|
||||
import org.bench4q.share.models.master.OperateScriptServerResponseModel;
|
||||
import org.bench4q.share.models.master.ScriptFilterModel;
|
||||
import org.bench4q.share.models.master.ScriptModel;
|
||||
import org.bench4q.web.masterMessager.ScriptMessager;
|
||||
import org.bench4q.web.model.ScenarioModel;
|
||||
|
@ -283,9 +285,8 @@ public class ScriptController extends BaseController {
|
|||
@ModelAttribute("accessToken") String accessToken,
|
||||
@RequestParam String port) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
OperateScriptServerResponseModel operateScriptServerResponseModel =
|
||||
this.getScriptMessager().startRecording(accessToken,
|
||||
port);
|
||||
OperateScriptServerResponseModel operateScriptServerResponseModel = this
|
||||
.getScriptMessager().startRecording(accessToken, port);
|
||||
if (operateScriptServerResponseModel.isSuccess()) {
|
||||
map = success(map);
|
||||
map.put("server", operateScriptServerResponseModel);
|
||||
|
@ -412,4 +413,14 @@ public class ScriptController extends BaseController {
|
|||
}
|
||||
}
|
||||
|
||||
@RequestMapping("loadFilterTypeList")
|
||||
public @ResponseBody Map<String, Object> loadFilterTypeList(
|
||||
HttpServletRequest request,
|
||||
@ModelAttribute("accessToken") String accessToken) {
|
||||
ScriptFilterModel responseModel = this.getScriptMessager()
|
||||
.loadFilterTypeList(accessToken);
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("filterTypeList", responseModel.getFilterTypeList());
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
@ -421,19 +420,4 @@ public class TestPlanController extends BaseController {
|
|||
}
|
||||
}
|
||||
|
||||
@RequestMapping("loadFilterTypeList")
|
||||
public @ResponseBody Map<String, Object> loadFilterTypeList(
|
||||
HttpServletRequest request,
|
||||
@ModelAttribute("accessToken") String accessToken) {
|
||||
TestPlanResponseModel responseModel = this.getTestPlanMessager()
|
||||
.loadFilterTypeList(accessToken);
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
if (responseModel.isSuccess()) {
|
||||
map.put("filterTypeList", responseModel.getFilterTypeList());
|
||||
success(map);
|
||||
} else {
|
||||
fail(map, responseModel.getFailCause());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import javax.xml.bind.JAXBException;
|
|||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.OperateScriptServerResponseModel;
|
||||
import org.bench4q.share.models.master.ScriptFilterModel;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
|
@ -26,8 +27,8 @@ public class ScriptMessager extends MasterMessager {
|
|||
|
||||
}
|
||||
|
||||
public OperateScriptServerResponseModel startRecording(
|
||||
String accessToken, String port) {
|
||||
public OperateScriptServerResponseModel startRecording(String accessToken,
|
||||
String port) {
|
||||
String url = this.getBaseUrl() + "/startScriptRecording";
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("port", port);
|
||||
|
@ -139,7 +140,8 @@ public class ScriptMessager extends MasterMessager {
|
|||
}
|
||||
|
||||
// public OperateScriptServerResponseModel updateScript(String accessToken,
|
||||
// String scriptId, String scenarioModel,String scriptName, MultipartFile[] paramFiles) {
|
||||
// String scriptId, String scenarioModel,String scriptName, MultipartFile[]
|
||||
// paramFiles) {
|
||||
// String url = this.getBaseUrl() + "/updateScript" + "/" + scriptId;
|
||||
// List<String> stringPart = new LinkedList<String>();
|
||||
// stringPart.add(scenarioModel);
|
||||
|
@ -196,8 +198,6 @@ public class ScriptMessager extends MasterMessager {
|
|||
accessToken);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private OperateScriptServerResponseModel getOperateScriptServerResponseModelByPost(
|
||||
String url, Map<String, String> params, String accessToken) {
|
||||
HttpResponse httpResponse = null;
|
||||
|
@ -228,4 +228,22 @@ public class ScriptMessager extends MasterMessager {
|
|||
OperateScriptServerResponseModel.class,
|
||||
httpResponse.getContent());
|
||||
}
|
||||
|
||||
public ScriptFilterModel loadFilterTypeList(String accessToken) {
|
||||
String url = this.getBaseUrl() + "/loadFilterTypeList";
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendGet(url, null,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse)) {
|
||||
handleInvalidatedResponse(url);
|
||||
return null;
|
||||
}
|
||||
return (ScriptFilterModel) MarshalHelper.tryUnmarshal(
|
||||
ScriptFilterModel.class, httpResponse.getContent());
|
||||
} catch (Exception e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return new ScriptFilterModel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ public class TestPlanMessager extends MasterMessager {
|
|||
String url = this.getBaseUrl() + "/run";
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendPostXml(url,
|
||||
httpResponse = this.getHttpRequester().sendPutXml(url,
|
||||
testPlanXmlContent, makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse))
|
||||
return null;
|
||||
|
@ -62,17 +62,26 @@ public class TestPlanMessager extends MasterMessager {
|
|||
|
||||
public TestPlanResultModel getRunningTestInfo(String accessToken,
|
||||
String testPlanId) {
|
||||
String url = this.getBaseUrl() + "/getRunningInfo";
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("testPlanId", testPlanId);
|
||||
return this.getTestPlanResultModelByPost(url, params, accessToken);
|
||||
String url = this.getBaseUrl() + "/" + testPlanId.toString()
|
||||
+ "/runningInfo";
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
|
||||
httpResponse = this.getHttpRequester().sendGet(url, null,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse))
|
||||
return null;
|
||||
return extractTestPlanResultModel(httpResponse);
|
||||
} catch (Exception e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public TestPlanScriptBriefResultModel getScriptBriefResult(
|
||||
String accessToken, String testPlanId, String scriptId,
|
||||
String duationBegin) {
|
||||
String url = this.getBaseUrl() + "/scriptBrief" + "/" + testPlanId
|
||||
String url = this.getBaseUrl() + "/" + testPlanId + "/scriptBrief"
|
||||
+ "/" + scriptId + "/" + duationBegin;
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
|
@ -94,8 +103,8 @@ public class TestPlanMessager extends MasterMessager {
|
|||
|
||||
public ScriptBehaviorsBriefModel getScriptBehaviorsBriefResult(
|
||||
String accessToken, String testPlanId, String scriptId) {
|
||||
String url = this.getBaseUrl() + "/getBehaviorsBrief" + "/"
|
||||
+ testPlanId + "/" + scriptId;
|
||||
String url = this.getBaseUrl() + "/" + testPlanId + "/behaviorsBrief"
|
||||
+ "/" + scriptId;
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendGet(url, null,
|
||||
|
@ -113,7 +122,7 @@ public class TestPlanMessager extends MasterMessager {
|
|||
|
||||
public TestPlanDBModel queryTestPlanById(String accessToken,
|
||||
String testPlanRunId) {
|
||||
String url = this.getBaseUrl() + "/queryTestPlan" + "/" + testPlanRunId;
|
||||
String url = this.getBaseUrl() + "/" + testPlanRunId;
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendGet(url, null,
|
||||
|
@ -133,26 +142,48 @@ public class TestPlanMessager extends MasterMessager {
|
|||
|
||||
public TestPlanResponseModel deleteTestPlan(String accessToken,
|
||||
String testPlanId) {
|
||||
String url = this.getBaseUrl() + "/removeTestPlanFromPool";
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("testPlanId", testPlanId);
|
||||
return getTestPlanResponseModel(url, params, accessToken);
|
||||
String url = this.getBaseUrl() + "/" + testPlanId;
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendDelete(url, null,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse)) {
|
||||
handleInvalidatedResponse(url);
|
||||
return null;
|
||||
}
|
||||
return extractTestPlanResponseModel(httpResponse);
|
||||
} catch (Exception e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return createFailTestPlanResponseModel();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public TestPlanResponseModel loadTestPlans(String accessToken) {
|
||||
String url = this.getBaseUrl() + "/loadTestPlans";
|
||||
return getTestPlanResponseModel(url, null, accessToken);
|
||||
String url = this.getBaseUrl() + "/";
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendGet(url, null,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse)) {
|
||||
handleInvalidatedResponse(url);
|
||||
return null;
|
||||
}
|
||||
return extractTestPlanResponseModel(httpResponse);
|
||||
} catch (Exception e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return createFailTestPlanResponseModel();
|
||||
}
|
||||
}
|
||||
|
||||
public HttpResponse getTestPlanReport(String accessToken,
|
||||
String testPlanRunId) {
|
||||
String url = this.getBaseUrl() + "/getTestPlanReport";
|
||||
String url = this.getBaseUrl() + "/" + testPlanRunId + "/report";
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("testPlanRunID", testPlanRunId);
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendPost(url, params,
|
||||
httpResponse = this.getHttpRequester().sendGet(url, params,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse))
|
||||
return null;
|
||||
|
@ -164,25 +195,6 @@ public class TestPlanMessager extends MasterMessager {
|
|||
}
|
||||
}
|
||||
|
||||
private TestPlanResponseModel getTestPlanResponseModel(String url,
|
||||
Map<String, String> params, String accessToken) {
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendPost(url, params,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse)) {
|
||||
handleInvalidatedResponse(url);
|
||||
return null;
|
||||
}
|
||||
|
||||
return extractTestPlanResponseModel(httpResponse);
|
||||
|
||||
} catch (Exception e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return createFailTestPlanResponseModel();
|
||||
}
|
||||
}
|
||||
|
||||
private TestPlanResponseModel createFailTestPlanResponseModel() {
|
||||
TestPlanResponseModel testPlanResponseModel = new TestPlanResponseModel();
|
||||
testPlanResponseModel.setSuccess(false);
|
||||
|
@ -190,22 +202,6 @@ public class TestPlanMessager extends MasterMessager {
|
|||
return testPlanResponseModel;
|
||||
}
|
||||
|
||||
private TestPlanResultModel getTestPlanResultModelByPost(String url,
|
||||
Map<String, String> params, String accessToken) {
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
|
||||
httpResponse = this.getHttpRequester().sendPost(url, params,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse))
|
||||
return null;
|
||||
return extractTestPlanResultModel(httpResponse);
|
||||
} catch (Exception e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private TestPlanResponseModel extractTestPlanResponseModel(
|
||||
HttpResponse httpResponse) throws JAXBException,
|
||||
UnsupportedEncodingException {
|
||||
|
@ -223,7 +219,7 @@ public class TestPlanMessager extends MasterMessager {
|
|||
|
||||
public ScriptBriefResultModel getLatestScriptBriefResult(
|
||||
String accessToken, String testPlanId, String scriptId) {
|
||||
String url = this.baseUrl + "/scriptBrief" + "/" + testPlanId + "/"
|
||||
String url = this.baseUrl + "/" + testPlanId + "/scriptBrief" + "/"
|
||||
+ scriptId + "/latestResult";
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
|
@ -233,7 +229,8 @@ public class TestPlanMessager extends MasterMessager {
|
|||
handleInvalidatedResponse(url);
|
||||
return null;
|
||||
}
|
||||
System.out.println("getLatestScriptBriefResult:\r\n"+httpResponse.getContent());
|
||||
System.out.println("getLatestScriptBriefResult:\r\n"
|
||||
+ httpResponse.getContent());
|
||||
return (ScriptBriefResultModel) MarshalHelper.tryUnmarshal(
|
||||
ScriptBriefResultModel.class, httpResponse.getContent());
|
||||
|
||||
|
@ -245,7 +242,7 @@ public class TestPlanMessager extends MasterMessager {
|
|||
|
||||
public ScriptPagesBriefModel getScriptPageBriefModel(String accessToken,
|
||||
String testPlanId, String scriptId) {
|
||||
String url = this.baseUrl + "/pagesBrief" + "/" + testPlanId + "/"
|
||||
String url = this.baseUrl + "/" + testPlanId + "/pagesBrief" + "/"
|
||||
+ scriptId;
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
|
@ -266,12 +263,20 @@ public class TestPlanMessager extends MasterMessager {
|
|||
|
||||
public TestPlanResponseModel stopTestPlan(String accessToken,
|
||||
String testPlanRunId) {
|
||||
String url = this.baseUrl + "/stop" + "/" + testPlanRunId;
|
||||
return getTestPlanResponseModel(url, null, accessToken);
|
||||
String url = this.baseUrl + "/" + testPlanRunId + "/stop";
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendPost(url, null,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse)) {
|
||||
handleInvalidatedResponse(url);
|
||||
return null;
|
||||
}
|
||||
return extractTestPlanResponseModel(httpResponse);
|
||||
} catch (Exception e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return createFailTestPlanResponseModel();
|
||||
}
|
||||
}
|
||||
|
||||
public TestPlanResponseModel loadFilterTypeList(String accessToken) {
|
||||
String url = this.getBaseUrl() + "/loadFilterTypeList";
|
||||
return getTestPlanResponseModel(url, null, accessToken);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue