refactor the testplanControler's api to pure restful

refactor the testplanControler's api to pure restful
This commit is contained in:
coderfengyun 2014-09-15 20:16:08 +08:00
parent dcf91a19b1
commit 7d7d8c7837
11 changed files with 294 additions and 263 deletions

View File

@ -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
@ -67,33 +70,33 @@ public class ScriptController extends BaseController {
this.portPoolService = portPoolService;
}
// @RequestMapping(value = "/startScriptRecordServer", method = {
// RequestMethod.GET, RequestMethod.POST })
// @ResponseBody
// public OperateScriptServerResponseModel startScriptRecordServer()
// throws UnknownHostException {
// if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
// return buildReponseModel(false,
// "has no power for recording script!!!", "", -1, null, null,
// null);
// }
// Port port = new Port();
// synchronized (PORT_LOCK) {
// port = this.getPortPoolService().getAPortNotInUse();
// if (port == null) {
// return buildReponseModel(false, "port is in use!", "", -1,
// null, null, null);
// }
// }
// UUID uuid = UUID.randomUUID();
// this.getScriptCapturer().startRecord(port.getPort(),
// buildScriptSavePath(), uuid.toString());
//
// return buildReponseModel(true, "", this.getScriptCapturer()
// .getIpHttpCaptureServerAdress(), port.getPort(), null, null,
// uuid.toString());
// }
// @RequestMapping(value = "/startScriptRecordServer", method = {
// RequestMethod.GET, RequestMethod.POST })
// @ResponseBody
// public OperateScriptServerResponseModel startScriptRecordServer()
// throws UnknownHostException {
// if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
// return buildReponseModel(false,
// "has no power for recording script!!!", "", -1, null, null,
// null);
// }
// Port port = new Port();
// synchronized (PORT_LOCK) {
// port = this.getPortPoolService().getAPortNotInUse();
// if (port == null) {
// return buildReponseModel(false, "port is in use!", "", -1,
// null, null, null);
// }
// }
// UUID uuid = UUID.randomUUID();
// this.getScriptCapturer().startRecord(port.getPort(),
// buildScriptSavePath(), uuid.toString());
//
// return buildReponseModel(true, "", this.getScriptCapturer()
// .getIpHttpCaptureServerAdress(), port.getPort(), null, null,
// uuid.toString());
// }
@RequestMapping(value = "/startScriptRecordServer", method = {
RequestMethod.GET, RequestMethod.POST })
@ResponseBody
@ -112,14 +115,13 @@ public class ScriptController extends BaseController {
null, null, null);
}
}
this.getScriptCapturer().startRecordServer(port.getPort());
return buildReponseModel(true, "", this.getScriptCapturer()
.getIpHttpCaptureServerAdress(), port.getPort(), null, null,
"");
.getIpHttpCaptureServerAdress(), port.getPort(), null, null, "");
}
@RequestMapping(value = "/startScriptRecording", method = {
RequestMethod.POST, RequestMethod.GET })
@ResponseBody
@ -131,13 +133,13 @@ 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());
}
private String buildScriptSavePath() {
String dirString = "Scripts" + System.getProperty("file.separator")
+ this.getPrincipal().getUserName()
@ -182,11 +184,11 @@ public class ScriptController extends BaseController {
}
this.getScriptCapturer().stopRecording(port);
return buildReponseModel(true, "RecordServer stop", "", port, null,
null, fileNameUUID);
}
@RequestMapping(value = "/saveScriptToDB", method = { RequestMethod.GET,
RequestMethod.POST })
@ResponseBody
@ -257,7 +259,7 @@ public class ScriptController extends BaseController {
return this.buildReponseModel(true, null, null, 0,
dealWithCollection(scripts), null, null);
}
@RequestMapping(value = "/queryScriptsByDate", method = RequestMethod.POST)
@ResponseBody
public OperateScriptServerResponseModel queryScriptsByDate(
@ -325,42 +327,45 @@ 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 = {
// RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT })
// @ResponseBody
// public OperateScriptServerResponseModel updateScript(
// @PathVariable int scriptId,
// @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
// + "for update a script", "/updateScript");
// }
// try {
// boolean success = this.getScriptService().alterScriptContent(scriptId,
// this.getPrincipal().getId(), paramContents.get(0), paramContents.get(1));
// logger.info("update script:" + paramContents.get(0));
// return buildReponseModel(success, null, null, -1, null, null, null);
// } catch (Exception e) {
// this.logger.error(ExceptionLog.getStackTrace(e));
// return buildReponseModel(false,
// "The script is not in the right format", null, -1, null,
// null, null);
// }
// }
// @RequestMapping(value = "updateScript/{scriptId}", method = {
// RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT })
// @ResponseBody
// public OperateScriptServerResponseModel updateScript(
// @PathVariable int scriptId,
// @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
// + "for update a script", "/updateScript");
// }
// try {
// boolean success = this.getScriptService().alterScriptContent(scriptId,
// this.getPrincipal().getId(), paramContents.get(0), paramContents.get(1));
// logger.info("update script:" + paramContents.get(0));
// return buildReponseModel(success, null, null, -1, null, null, null);
// } catch (Exception e) {
// this.logger.error(ExceptionLog.getStackTrace(e));
// return buildReponseModel(false,
// "The script is not in the right format", null, -1, null,
// null, null);
// }
// }
private OperateScriptServerResponseModel buildReponseModel(
boolean isSuccess, String failCauseString, String hostName,
int port, List<ScriptModel> scriptModels, ScriptModel scriptModel,
@ -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);
}
}

View File

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

View File

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

View File

@ -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;
@ -28,8 +25,6 @@ import org.springframework.stereotype.Component;
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(",");
}
}

View File

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

View File

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

View File

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

View File

@ -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);
@ -322,11 +323,11 @@ public class ScriptController extends BaseController {
@RequestMapping("testRecordProxy")
@ResponseBody
public Map<String, Object> testRecordProxy(
@RequestHeader HttpHeaders headers,@RequestParam String port) {
@RequestHeader HttpHeaders headers, @RequestParam String port) {
Map<String, Object> map = new HashMap<String, Object>();
// is from proxy
String proxyPort = headers.getFirst("FromProxyPort");
if (proxyPort!=null && proxyPort.equals(port)) {
if (proxyPort != null && proxyPort.equals(port)) {
success(map);
} else {
fail(map, "proxy setting error!");
@ -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;
}
}

View File

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

View File

@ -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,16 +27,16 @@ 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);
// params.put("fileNameUUID", fileNameUUID);
// params.put("fileNameUUID", fileNameUUID);
return this.getOperateScriptServerResponseModelByPost(url, params,
accessToken);
}
public OperateScriptServerResponseModel stopScriptRecordServer(
String accessToken, String port, String fileNameUUID) {
String url = this.getBaseUrl() + "/stopScriptRecordServer";
@ -55,7 +56,7 @@ public class ScriptMessager extends MasterMessager {
return this.getOperateScriptServerResponseModelByPost(url, params,
accessToken);
}
public OperateScriptServerResponseModel saveScriptRecorded(
String accessToken, String scriptName, String port,
String fileNameUUID) {
@ -128,7 +129,7 @@ public class ScriptMessager extends MasterMessager {
}
public OperateScriptServerResponseModel updateScript(String accessToken,
String scriptId,String scriptContent, String scriptName) {
String scriptId, String scriptContent, String scriptName) {
String url = this.getBaseUrl() + "/updateScript" + "/" + scriptId;
Map<String, String> params = new HashMap<String, String>();
params.put("content", scriptContent);
@ -138,31 +139,32 @@ public class ScriptMessager extends MasterMessager {
}
// public OperateScriptServerResponseModel updateScript(String accessToken,
// String scriptId, String scenarioModel,String scriptName, MultipartFile[] paramFiles) {
// String url = this.getBaseUrl() + "/updateScript" + "/" + scriptId;
// List<String> stringPart = new LinkedList<String>();
// stringPart.add(scenarioModel);
// stringPart.add(scriptName);
// HttpResponse httpResponse = null;
//
// try {
// httpResponse = this.getHttpRequester().postFilesMulti(
// makeAccessTockenMap(accessToken), url, "paramFiles[]",
// paramFiles, "paramContents[]", stringPart);
// if (!validateHttpResponse(httpResponse))
// return null;
// return (OperateScriptServerResponseModel) MarshalHelper.unmarshal(
// OperateScriptServerResponseModel.class,
// httpResponse.getContent());
//
// } catch (Exception e) {
// this.handleException(httpResponse, e);
// return createFailOperateScriptServerResponseModel();
// }
//
// }
// public OperateScriptServerResponseModel updateScript(String accessToken,
// String scriptId, String scenarioModel,String scriptName, MultipartFile[]
// paramFiles) {
// String url = this.getBaseUrl() + "/updateScript" + "/" + scriptId;
// List<String> stringPart = new LinkedList<String>();
// stringPart.add(scenarioModel);
// stringPart.add(scriptName);
// HttpResponse httpResponse = null;
//
// try {
// httpResponse = this.getHttpRequester().postFilesMulti(
// makeAccessTockenMap(accessToken), url, "paramFiles[]",
// paramFiles, "paramContents[]", stringPart);
// if (!validateHttpResponse(httpResponse))
// return null;
// return (OperateScriptServerResponseModel) MarshalHelper.unmarshal(
// OperateScriptServerResponseModel.class,
// httpResponse.getContent());
//
// } catch (Exception e) {
// this.handleException(httpResponse, e);
// return createFailOperateScriptServerResponseModel();
// }
//
// }
public OperateScriptServerResponseModel loadScripts(String accessToken) {
String url = this.getBaseUrl() + "/loadScriptList";
return this.getOperateScriptServerResponseModelByPost(url, null,
@ -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();
}
}
}

View File

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