add scriptController

This commit is contained in:
fanfuxiaoran 2014-05-15 15:14:19 +08:00
parent e3c672a1ef
commit 9783574d0e
18 changed files with 541 additions and 1151 deletions

View File

@ -66,7 +66,7 @@ public class DeviceController extends BaseController {
logger.info(scenarioModel);
OperateScriptServerResponseModel operateScriptServerResponseModel = this
.getScriptMessager().uploadScript(accessToken,
script.getName(), scenarioModel, null, null);
script.getName(), scenarioModel, null);
if (operateScriptServerResponseModel.isSuccess()) {
return success(map);
} else {

View File

@ -1,34 +1,20 @@
package org.bench4q.web.api;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.xml.bind.JAXBException;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import org.apache.log4j.Logger;
import org.bench4q.share.communication.HttpRequester.HttpResponse;
import org.bench4q.share.helper.ExceptionLog;
import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.agent.RunScenarioModel;
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.PluginEditScriptRequestModel;
import org.bench4q.share.models.master.ScriptModel;
import org.bench4q.web.exception.CustomGenericException;
import org.bench4q.web.extractObjectFromXml.ObjectXmlExchange;
@ -40,14 +26,12 @@ import org.bench4q.web.service.ScriptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
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.SessionAttributes;
import org.springframework.web.multipart.MultipartFile;
import org.xml.sax.SAXException;
import com.google.gson.Gson;
@ -330,69 +314,6 @@ public class ScriptActionController {
}
@RequestMapping("validateScript")
public @ResponseBody
String validateScript(@ModelAttribute("accessToken") String accessToken,
@RequestParam String content) {
String result;
String message = "";
String schemaFileName = "src/main/webapp/WEB-INF/validateScript.xsd";
content = content.replace("runScenario", "runscenario")
.replace("poolSize", "poolsize")
.replace("usePlugin", "useplugin")
.replace("userBehavior", "userbehavior")
.replace("timerBehavior", "timerbehavior")
.replace("userbehaviors", "behaviors");
try {
result = validateXmlWithSchema(schemaFileName, content);
if (result == "true") {
message = "Success";
} else {
message = URLEncoder.encode(result, "UTF-8").replace("+", "");
}
} catch (Exception e) {
System.out.println("analysis of failure:" + e.toString());
message = "failed to read schema file";
}
// System.out.println(message);
return message;
}
private String validateXmlWithSchema(String schemaFileName, String xmlScript)
throws SAXException, IOException {
String validationResult = "";
SchemaFactory schemaFactory = SchemaFactory
.newInstance("http://www.w3.org/2001/XMLSchema");
File schemaFile = new File(schemaFileName);
Schema schema = schemaFactory.newSchema(schemaFile);
Validator validator = schema.newValidator();
InputStream script = new ByteArrayInputStream(xmlScript.getBytes());
Source source = new StreamSource(script);
try {
// System.out.println("enter validateXmlWithSchema");
validator.validate(source);
validationResult = "true";
} catch (Exception ex) {
validationResult = ex.toString();
}
return validationResult;
}
@RequestMapping("readSchemaContent")
public @ResponseBody
String readSchemaContent() throws Exception {
String schema = "";
FileReader fr = new FileReader("src/main/webapp/WEB-INF/schema.json");
BufferedReader br = new BufferedReader(fr);
StringBuilder sb = new StringBuilder();
while ((schema = br.readLine()) != null) {
sb.append(schema);
}
br.close();
String str = sb.toString();
return str;
}
@RequestMapping(value = "uploadEditedScipt", method = RequestMethod.POST)
@ResponseBody
public BaseResponseModel uploadEditScript(
@ -450,60 +371,6 @@ public class ScriptActionController {
return true;
}
@RequestMapping(value = "uploadPluginEditedScript", method = RequestMethod.POST)
@ResponseBody
public BaseResponseModel uploadPluginEditedScript(
@ModelAttribute("accessToken") String accessToken,
@RequestBody String content) throws CustomGenericException {
Gson gson = new Gson();
Logger.getLogger(ScriptActionController.class).info(content);
PluginEditScriptRequestModel pluginEditScriptRequestModel = null;
try {
pluginEditScriptRequestModel = gson.fromJson(content,
PluginEditScriptRequestModel.class);
} catch (Exception e) {
Logger.getLogger(ScriptActionController.class).info(
ExceptionLog.getStackTrace(e));
}
List<BehaviorModel> behaviorModelsList = pluginEditScriptRequestModel
.getBehaviorModels();
List<UsePluginModel> usePluginModelsList = pluginEditScriptRequestModel
.getUsePluginModels();
String scriptName = pluginEditScriptRequestModel.getScriptName();
if (!validateScript(behaviorModelsList, usePluginModelsList))
return new BaseResponseModel(false, "invalidate script");
RunScenarioModel runScenarioModel = this
.getScriptService()
.createRunScenarioModel(behaviorModelsList, usePluginModelsList);
try {
String script = ObjectXmlExchange.toXml(RunScenarioModel.class,
runScenarioModel);
OperateScriptServerResponseModel operateScriptServerResponseModel = this
.getScriptService().uploadScript(accessToken, script,
scriptName);
if (operateScriptServerResponseModel.isSuccess())
return new BaseResponseModel(true, (Object) new String(
"upload script:" + scriptName + " success!"));
else
return new BaseResponseModel(false,
operateScriptServerResponseModel.getFailCauseString());
} catch (JAXBException e) {
return new BaseResponseModel(false,
"Failed:invalidated script file!");
}
}
private boolean validateScript(List<BehaviorModel> behaviorModels,
List<UsePluginModel> usePluginModels) {
if (behaviorModels == null || behaviorModels.size() == 0)
return false;
if (usePluginModels == null || usePluginModels.size() == 0)
return false;
return true;
}
}

View File

@ -13,7 +13,6 @@ import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.master.OperateScriptServerResponseModel;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartRequest;
@Component
public class ScriptMessager extends MasterMessager {
@ -30,9 +29,9 @@ public class ScriptMessager extends MasterMessager {
}
public OperateScriptServerResponseModel stopScriptRecordServer(
String accessToken,String port,String fileNameUUID) {
String accessToken, String port, String fileNameUUID) {
String url = this.getBaseUrl() + "/stopScriptRecordServer";
Map<String,String> params=new HashMap<String,String>();
Map<String, String> params = new HashMap<String, String>();
params.put("port", port);
params.put("fileNameUUID", fileNameUUID);
return this.getOperateScriptServerResponseModelByPost(url, params,
@ -54,8 +53,7 @@ public class ScriptMessager extends MasterMessager {
}
public OperateScriptServerResponseModel uploadScript(String accessToken,
String scriptName, String scenarioModel,
MultipartRequest multipartRequest,MultipartFile[] paramFiles) {
String scriptName, String scenarioModel, MultipartFile[] paramFiles) {
String url = this.getBaseUrl() + "/uploadScript" + "/" + scriptName;
List<String> stringPart = new LinkedList<String>();
stringPart.add(scenarioModel);
@ -97,7 +95,7 @@ public class ScriptMessager extends MasterMessager {
}
public OperateScriptServerResponseModel loadScript(String accessToken) {
public OperateScriptServerResponseModel loadScripts(String accessToken) {
String url = this.getBaseUrl() + "/loadScriptList";
return this.getOperateScriptServerResponseModelByPost(url, null,
accessToken);
@ -108,8 +106,17 @@ public class ScriptMessager extends MasterMessager {
String url = this.getBaseUrl() + "/queryScriptById";
Map<String, String> params = new HashMap<String, String>();
params.put("scriptId", scriptId);
return this.getOperateScriptServerResponseModelByPost(url, params,
accessToken);
OperateScriptServerResponseModel operateScriptServerResponseModel = this
.getOperateScriptServerResponseModelByPost(url, params,
accessToken);
if (!operateScriptServerResponseModel.isSuccess()
|| operateScriptServerResponseModel.getScriptModels().size() != 1) {
operateScriptServerResponseModel.setSuccess(false);
operateScriptServerResponseModel
.setFailCauseString("error get script by id:" + scriptId);
}
return operateScriptServerResponseModel;
}
public OperateScriptServerResponseModel queryScriptByName(

View File

@ -62,10 +62,11 @@ public class MonitorController extends BaseController {
cpuInstance, fieldName);
if (resultModels == null) {
return fail(map, SERVER_ERROR);
} else {
success(map);
map.put("cpuInfo", resultModels);
return map;
}
success(map);
map.put("cpuInfo", resultModels);
return map;
}
@ -90,9 +91,11 @@ public class MonitorController extends BaseController {
monitorMemoryResponseModel.getMemoryModels(), fieldName);
if (resultModels == null) {
return fail(map, SERVER_ERROR);
} else {
map = success(map);
map.put("memInfo", resultModels);
return map;
}
map = success(map);
map.put("memInfo", resultModels);
return map;
}
}

View File

@ -52,13 +52,16 @@ public class PluginController extends BaseController {
Map<String, Object> map = new HashMap<String, Object>();
PluginResponseModel pluginResponseModel = this.getPluginMessager()
.loadPluginNameList(accessToken);
if (pluginResponseModel.isSuccess()) {
if (!pluginResponseModel.isSuccess()) {
map = success(map);
map.put("pluginNames", pluginResponseModel.getPluginList());
return map;
} else {
map = fail(map, pluginResponseModel.getFailMessage());
return map;
}
return map;
}

View File

@ -0,0 +1,156 @@
package org.bench4q.web.newapi;
import java.util.HashMap;
import java.util.Map;
import org.bench4q.share.models.master.OperateScriptServerResponseModel;
import org.bench4q.web.masterMessager.ScriptMessager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.multipart.MultipartFile;
@SessionAttributes({ "accessToken", "username", "testPlanTaskList" })
public class ScriptController extends BaseController {
private ScriptMessager scriptMessager;
public ScriptMessager getScriptMessager() {
return scriptMessager;
}
@Autowired
public void setScriptMessager(ScriptMessager scriptMessager) {
this.scriptMessager = scriptMessager;
}
@RequestMapping("loadScripts")
@ResponseBody
public Map<String, Object> loadScript(
@ModelAttribute("accessToken") String accessToken) {
Map<String, Object> map = new HashMap<String, Object>();
OperateScriptServerResponseModel operateScriptServerResponseModel = this
.getScriptMessager().loadScripts(accessToken);
if (!operateScriptServerResponseModel.isSuccess()) {
return fail(map,
operateScriptServerResponseModel.getFailCauseString());
} else {
map = success(map);
map.put("scripts",
operateScriptServerResponseModel.getScriptModels());
return map;
}
}
@RequestMapping("deleteScript")
@ResponseBody
public Map<String, Object> deleteScript(
@ModelAttribute("accessToken") String accessToken, String scriptId) {
Map<String, Object> map = new HashMap<String, Object>();
return processScriptResponse(map, this.getScriptMessager()
.deleteScript(accessToken, scriptId));
}
@RequestMapping("getScript")
@ResponseBody
public Map<String, Object> loadScriptContent(
@ModelAttribute("accessToken") String accessToken,
@RequestParam String scriptId) {
Map<String, Object> map = new HashMap<String, Object>();
OperateScriptServerResponseModel operateScriptServerResponseModel = this
.getScriptMessager().queryScriptById(accessToken, scriptId);
if (operateScriptServerResponseModel.isSuccess()) {
map = success(map);
return map;
} else {
map = fail(map,
operateScriptServerResponseModel.getFailCauseString());
return map;
}
}
@RequestMapping("uploadScript")
@ResponseBody
public Map<String, Object> saveScript(
@ModelAttribute("accessToken") String accessToken,
@RequestParam String scriptName, @RequestParam String script,
@RequestParam(required = false) MultipartFile[] paramFiles) {
return processScriptResponse(
new HashMap<String, Object>(),
this.getScriptMessager().uploadScript(accessToken, scriptName,
script, paramFiles));
}
@RequestMapping("updateScript")
@ResponseBody
public Map<String, Object> updateScript(
@ModelAttribute("accessToken") String accessToken,
@RequestParam String scriptId, @RequestParam String script) {
return processScriptResponse(new HashMap<String, Object>(), this
.getScriptMessager()
.updateScript(accessToken, scriptId, script));
}
@RequestMapping("startRecordServer")
@ResponseBody
public Map<String, Object> startRecordServer(
@ModelAttribute("accessToken") String accessToken) {
Map<String, Object> map = new HashMap<String, Object>();
OperateScriptServerResponseModel operateScriptServerResponseModel = this
.getScriptMessager().startScriptRecordServer(accessToken);
if (operateScriptServerResponseModel.isSuccess()) {
map = success(map);
map.put("port", operateScriptServerResponseModel.getPort());
return map;
} else {
map = fail(map,
operateScriptServerResponseModel.getFailCauseString());
return map;
}
}
@RequestMapping("stopRecordServer")
@ResponseBody
public Map<String, Object> stopRecordServer(
@ModelAttribute("accessToken") String accessToken,
@RequestParam String port, @RequestParam String scriptRecordUUID) {
return processScriptResponse(
new HashMap<String, Object>(),
this.getScriptMessager().stopScriptRecordServer(accessToken,
port, scriptRecordUUID));
}
@RequestMapping("saveScriptRecorded")
@ResponseBody
public Map<String, Object> saveScriptRecorded(
@ModelAttribute("accessToken") String accessToken,
@RequestParam String port, @RequestParam String scriptRecordUUID,
@RequestParam String scriptName) {
Map<String, Object> map = new HashMap<String, Object>();
return processScriptResponse(
map,
this.getScriptMessager().saveScriptRecorded(accessToken,
scriptName, port, scriptRecordUUID));
}
@RequestMapping()
private Map<String, Object> processScriptResponse(Map<String, Object> map,
OperateScriptServerResponseModel operateScriptServerResponseModel) {
if (operateScriptServerResponseModel.isSuccess()) {
return success(map);
} else {
map = fail(map,
operateScriptServerResponseModel.getFailCauseString());
return map;
}
}
}

View File

@ -56,9 +56,11 @@ public class UserController extends BaseController {
RegisterResponseModel registerResponseModel = this.getUserMessager()
.register(userName, password, scope);
if (!registerResponseModel.isSuccess()) {
fail(map, "please try again");
return success(map);
} else {
return fail(map, "please try again");
}
return success(map);
}
@ -75,12 +77,13 @@ public class UserController extends BaseController {
}
AuthorizeResponseModel authorizeResponseModel = this.getUserMessager()
.normalLogin(userModel.getUserName(), userModel.getPassword());
if (!authorizeResponseModel.isSuccess()) {
return fail(map, "error userName or password");
} else {
if (authorizeResponseModel.isSuccess()) {
updateSessionAttribute(modelMap, authorizeResponseModel,
userModel.getUserName());
return success(map);
} else {
return fail(map, "error userName or password");
}
}
@ -97,12 +100,13 @@ public class UserController extends BaseController {
}
AuthorizeResponseModel authorizeResponseModel = this.getUserMessager()
.adminLogin(userModel.getUserName(), userModel.getPassword());
if (!authorizeResponseModel.isSuccess()) {
return fail(map, "error userName or password");
} else {
if (authorizeResponseModel.isSuccess()) {
updateSessionAttribute(modelMap, authorizeResponseModel,
userModel.getUserName());
return success(map);
} else {
return fail(map, "error userName or password");
}
}

View File

@ -1,5 +1,4 @@
package org.bench4q.web.validation;
public class ScriptValidate {
}

View File

@ -1 +1 @@
masterAddress=133.133.12.1:7979/
masterAddress=127.0.0.1:7979/

View File

@ -1,339 +1,339 @@
#codeEditor {
height: 550px;
width: 90%;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box
}
#codeEditor {
float: left;
padding: 0px 0px 15px 15px
}
#treeEditor {
float: left;
padding: 0px 15px 15px 0
}
#splitter {
text-align: center;
float: left;
height: 100%;
padding: 15px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box
}
#splitter #drag {
font-size: 32px;
color: #d3d3d3;
border-radius: 3px;
min-width: 24px;
cursor: col-resize
}
#splitter #drag.active,#splitter #drag:hover {
color: gray;
background-color: #f5f5f5
}
button.convert {
cursor: default;
padding: 2px
}
div.convert-right {
background: url(../images/jsoneditor-icons.png) -0 -48px
}
div.convert-left {
background: url(../images/jsoneditor-icons.png) -24px -48px
}
div.convert-left,div.convert-right {
width: 24px;
height: 24px;
margin: 0
}
#splitter #toTree {
margin: 40px 0 0;
}
#splitter #toCode {
margin: 20px 0 0;
}
#action {
margin-top: 10px;
margin-right: 120px;
float: right;
text-align: left;
float: right;
}
a:hover{
background-color:#E5E3E9;
text-decoration:none;
}
#box-api {
height: 500px;
padding-left: 0px;
padding-right: 15px;
}
#api-header {
background-color: #F5F5F5;
}
#api-content {
overflow-x: hidden;
overflow-y: scroll;
height: 345px;
background-color: #EDF1DE;
}
#nav-tab {
margin-right: -5px;
margin-left: -5px;
}
.line {size =2;
color: #86B32E;
align: right;
width: 255px;
margin: 0px;
}
.title {
margin-bottom: 6px;
margin-top: 4px;
color: #E25500;
text-shadow: 0px 1px 0px #FFF;
display: inline-block;
font-size: 14px;
line-height: 1.4;
}
.title_style {
width: 300px;
line-height: 18px;loadBehaviors("other");
border: 1px solid #CCCCCC;
background-color: #F5F5F5;
text-align: center;
color: #369BD7;
}
.arguments {
display: block;
border-bottom: 1px dashed #AAA;
font-weight: bold;
color: #333;
padding: 5px 0px 2px;
}
.details {
font: 13px Arial, Helvetica, sans-serif;
border-collapse: collapse;
border-spacing: 0px;
}
td {
padding-right: 15px;
padding-bottom: 5px;
padding-top: 8px;
font-weight: normal;
vertical-align: top;
text-align: left;
}
.chooseScript {
margin-top: 10px;
margin-bottom: 60px;
margin-left: 5px;
padding-left: 0px;
font-size: 120%;
font-weight: bold;
color: #3689BB;
font-size: 120%;
}
.sample_frame {
padding: 10px;
margin: 5px 5px 5px 5px;
border: #EFEFEF solid thin;
}
.sample_sub_frame {
border: #F0ECE0 solid thin;
margin-top: 5px;
margin-bottom: 5px;
margin-left: 10px;
margin-right: 10px;
}
p {
color: #4E9BCB;
}
.btn-large {
width: 25%;
margin-left: 10px;
margin-bottom: 5px;
}
.btn-width{
width:85px;
}
.visited {
background-color: #E8F2FE;
}
#showPluginMethodForm td,th {
width: 200px;
padding-left: 10px;
padding-top: 5px;
text-align: left;
}
.left {
float: left;
}
.view {
margin-left: -15px;
}
.listArea {
height: 340px;
margin-bottom: 15px;
outline-style: outset;
outline-color: #A0D0EC;
/* color: black; */
}
a:hover {
color: #369bd7;
cursor: pointer;
}
a {
display: block;
padding: 3px 15px;
clear: both;
font-weight: normal;
line-height: 18px;
color: #369bd7;
white-space: nowrap;
}
.all-behaviors {
height: 500px;
border: 1px #A0D0EC solid;
margin-top: 0px;
width: 240px;
box-shadow: 5px 5px 5px 5px rgba(0, 0, 0, .3);
overflow-x: hidden;
overflow-y: auto;
background-color: #F5F5F5;
}
.all-behaviors #behaviorUl,#usePlugin {
overflow-x: hidden;
overflow-y: auto;
}
.all-plugins {
text-color: #A0D0EC;
margin-bottom: 10px;
}
#behaviorUl{
margin:8px 5px 0px 0px;
}
.all-behaviors .divider {
height: 1px;
width: 100%;
margin: 8px 1px;
overflow: hidden;
background-color: #e5e5e5;
border-bottom: 1px solid #ffffff;
}
BODY {
padding-left: 20px;
padding-top: 20px;
}
.tab .nav li a:hover,.nav>li>a:focus {
text-decoration: none;
background-color: #E5E3E9;
}
.tab .nav-tabs {
border-bottom: 1px solid #F7F5FA;
margin-bottom: 15px;
}
.tab .nav {
list-style: none;
}
.tab {
background-color: #F7F5FA;
margin-bottom: 15px;
margin-left: 15px;
padding-bottom: 5px;
padding-top: -10px;
}
.tab ul {
/* zoom: 1; */
clear: both;
}
.tab ul:after {
display: block;
height: 0px;
visibility: hidden;
clear: both;
content: "";
}
.tab ul li {
margin-bottom: -10px;
text-align: center;
line-height: 100%;
width: 20%;
display: inline;
float: left;
height: 26px;
color: #fff;
text-align: center;
}
.tab ul li.on {
color: black;
}
.tabList {
margin-top: 20px;
margin-left: 15px;
}
.tabList .one {
padding-bottom: 10px;
padding-right: 10px;
display: none;
color: #ff0000;
padding-top: 10px;
}
.tabList .block {
display: block;
#codeEditor {
height: 550px;
width: 90%;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box
}
#codeEditor {
float: left;
padding: 0px 0px 15px 15px
}
#treeEditor {
float: left;
padding: 0px 15px 15px 0
}
#splitter {
text-align: center;
float: left;
height: 100%;
padding: 15px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box
}
#splitter #drag {
font-size: 32px;
color: #d3d3d3;
border-radius: 3px;
min-width: 24px;
cursor: col-resize
}
#splitter #drag.active,#splitter #drag:hover {
color: gray;
background-color: #f5f5f5
}
button.convert {
cursor: default;
padding: 2px
}
div.convert-right {
background: url(../images/jsoneditor-icons.png) -0 -48px
}
div.convert-left {
background: url(../images/jsoneditor-icons.png) -24px -48px
}
div.convert-left,div.convert-right {
width: 24px;
height: 24px;
margin: 0
}
#splitter #toTree {
margin: 40px 0 0;
}
#splitter #toCode {
margin: 20px 0 0;
}
#action {
margin-top: 10px;
margin-right: 120px;
float: right;
text-align: left;
float: right;
}
a:hover{
background-color:#E5E3E9;
text-decoration:none;
}
#box-api {
height: 500px;
padding-left: 0px;
padding-right: 15px;
}
#api-header {
background-color: #F5F5F5;
}
#api-content {
overflow-x: hidden;
overflow-y: scroll;
height: 345px;
background-color: #EDF1DE;
}
#nav-tab {
margin-right: -5px;
margin-left: -5px;
}
.line {size =2;
color: #86B32E;
align: right;
width: 255px;
margin: 0px;
}
.title {
margin-bottom: 6px;
margin-top: 4px;
color: #E25500;
text-shadow: 0px 1px 0px #FFF;
display: inline-block;
font-size: 14px;
line-height: 1.4;
}
.title_style {
width: 300px;
line-height: 18px;loadBehaviors("other");
border: 1px solid #CCCCCC;
background-color: #F5F5F5;
text-align: center;
color: #369BD7;
}
.arguments {
display: block;
border-bottom: 1px dashed #AAA;
font-weight: bold;
color: #333;
padding: 5px 0px 2px;
}
.details {
font: 13px Arial, Helvetica, sans-serif;
border-collapse: collapse;
border-spacing: 0px;
}
td {
padding-right: 15px;
padding-bottom: 5px;
padding-top: 8px;
font-weight: normal;
vertical-align: top;
text-align: left;
}
.chooseScript {
margin-top: 10px;
margin-bottom: 60px;
margin-left: 5px;
padding-left: 0px;
font-size: 120%;
font-weight: bold;
color: #3689BB;
font-size: 120%;
}
.sample_frame {
padding: 10px;
margin: 5px 5px 5px 5px;
border: #EFEFEF solid thin;
}
.sample_sub_frame {
border: #F0ECE0 solid thin;
margin-top: 5px;
margin-bottom: 5px;
margin-left: 10px;
margin-right: 10px;
}
p {
color: #4E9BCB;
}
.btn-large {
width: 25%;
margin-left: 10px;
margin-bottom: 5px;
}
.btn-width{
width:85px;
}
.visited {
background-color: #E8F2FE;
}
#showPluginMethodForm td,th {
width: 200px;
padding-left: 10px;
padding-top: 5px;
text-align: left;
}
.left {
float: left;
}
.view {
margin-left: -15px;
}
.listArea {
height: 340px;
margin-bottom: 15px;
outline-style: outset;
outline-color: #A0D0EC;
/* color: black; */
}
a:hover {
color: #369bd7;
cursor: pointer;
}
a {
display: block;
padding: 3px 15px;
clear: both;
font-weight: normal;
line-height: 18px;
color: #369bd7;
white-space: nowrap;
}
.all-behaviors {
height: 500px;
border: 1px #A0D0EC solid;
margin-top: 0px;
width: 240px;
box-shadow: 5px 5px 5px 5px rgba(0, 0, 0, .3);
overflow-x: hidden;
overflow-y: auto;
background-color: #F5F5F5;
}
.all-behaviors #behaviorUl,#usePlugin {
overflow-x: hidden;
overflow-y: auto;
}
.all-plugins {
text-color: #A0D0EC;
margin-bottom: 10px;
}
#behaviorUl{
margin:8px 5px 0px 0px;
}
.all-behaviors .divider {
height: 1px;
width: 100%;
margin: 8px 1px;
overflow: hidden;
background-color: #e5e5e5;
border-bottom: 1px solid #ffffff;
}
BODY {
padding-left: 20px;
padding-top: 20px;
}
.tab .nav li a:hover,.nav>li>a:focus {
text-decoration: none;
background-color: #E5E3E9;
}
.tab .nav-tabs {
border-bottom: 1px solid #F7F5FA;
margin-bottom: 15px;
}
.tab .nav {
list-style: none;
}
.tab {
background-color: #F7F5FA;
margin-bottom: 15px;
margin-left: 15px;
padding-bottom: 5px;
padding-top: -10px;
}
.tab ul {
/* zoom: 1; */
clear: both;
}
.tab ul:after {
display: block;
height: 0px;
visibility: hidden;
clear: both;
content: "";
}
.tab ul li {
margin-bottom: -10px;
text-align: center;
line-height: 100%;
width: 20%;
display: inline;
float: left;
height: 26px;
color: #fff;
text-align: center;
}
.tab ul li.on {
color: black;
}
.tabList {
margin-top: 20px;
margin-left: 15px;
}
.tabList .one {
padding-bottom: 10px;
padding-right: 10px;
display: none;
color: #ff0000;
padding-top: 10px;
}
.tabList .block {
display: block;
}

View File

@ -553,12 +553,14 @@
font-family: arial, sans-serif;
font-size: 10pt;
color: #1A1A1A;
margin-left:100px;
}
.jsoneditor .search {
position: absolute;
right: 2px;
top: 2px;
}
.jsoneditor .search .frame {

View File

@ -133,13 +133,13 @@
<hr>
<jsp:include page="publiccontrol/footer.jsp"></jsp:include>
<script
src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.0.min.js"></script>
<script
src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.10.4/jquery-ui.js"></script>
<script
src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
src='http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js'></script>
<script
src="http://ajax.aspnetcdn.com/ajax/bootstrap/2.3.1/bootstrap.min.js"></script>
<script src="lib/jqueryi18n/jquery.i18n.properties-1.0.9.js"></script>

View File

@ -1,63 +0,0 @@
package org.bench4q.web.api.test;
import org.bench4q.share.models.master.UserModel;
import org.bench4q.web.api.AuthorizeActionController;
import org.bench4q.web.exception.CustomGenericException;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.ui.ModelMap;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.ContextConfiguration;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "file:src/test/resources/bench4qweb-servlet.xml" })
public class AuthorizeActionControllerTest {
@Autowired
private AuthorizeActionController authorizeActionController;
private ModelMap modelMap;
private UserModel user;
@Before
public void setUp() {
this.modelMap = new ModelMap();
this.user = new UserModel();
}
@Test
public void loginTest() throws CustomGenericException {
// right
this.user.setUserName("www");
this.user.setPassword("www");
Assert.assertTrue(this.authorizeActionController.login(user, modelMap)
.isSuccess());
this.user.setUserName("www");
this.user.setPassword("123");
Assert.assertFalse(this.authorizeActionController.login(user, modelMap)
.isSuccess());
}
@Test
public void adminLoginTest() {
try {
// right
this.user.setUserName("www");
this.user.setPassword("www");
this.user.setUserName("www");
this.user.setPassword("123");
Assert.assertFalse(this.authorizeActionController.adminLogin(user,
modelMap).isSuccess());
Assert.assertFalse(this.authorizeActionController.adminLogin(null,
modelMap).isSuccess());
} catch (CustomGenericException e) {
e.printStackTrace();
}
}
}

View File

@ -1,87 +0,0 @@
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;
import org.bench4q.web.exception.CustomGenericException;
import org.bench4q.web.model.TestPlanRequestModel;
import org.bench4q.web.model.WebScriptModel;
import org.bench4q.web.tool.test.LoginHelper;
import org.junit.Before;
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.ui.ModelMap;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "file:src/main/resources/bench4qweb-servlet.xml" })
public class RunTestPlanTest {
private ScriptActionController scriptActionController;
private RunTestPlan runTestPlan;
private LoginHelper loginHelper;
private String accessToken;
private ScriptActionController getScriptActionController() {
return scriptActionController;
}
@Autowired
private void setScriptActionController(
ScriptActionController scriptActionController) {
this.scriptActionController = scriptActionController;
}
private RunTestPlan getRunTestPlan() {
return runTestPlan;
}
@Autowired
private void setRunTestPlan(RunTestPlan runTestPlan) {
this.runTestPlan = runTestPlan;
}
public LoginHelper getLoginHelper() {
return loginHelper;
}
@Autowired
public void setLoginHelper(LoginHelper loginHelper) {
this.loginHelper = loginHelper;
}
@Before
public void setUp() {
this.accessToken = this.getLoginHelper().login();
}
@SuppressWarnings("unchecked")
@Test
public void runTestPlanTest() throws CustomGenericException {
TestPlanRequestModel testPlanRequestModel = new TestPlanRequestModel();
WebScriptModel webScriptModel = new WebScriptModel();
webScriptModel.setCooldown(1);
webScriptModel.setWarmup(1);
webScriptModel.setLoad(100);
webScriptModel.setExecuteRange(50);
List<ScriptModel> scripts = (List<ScriptModel>) this
.getScriptActionController().loadScript(accessToken).getData();
webScriptModel.setId(scripts.get(0).getId());
List<WebScriptModel> webScriptModels = new ArrayList<WebScriptModel>();
webScriptModels.add(webScriptModel);
testPlanRequestModel.setScriptList(webScriptModels);
this.getRunTestPlan().runTestPlan(accessToken, testPlanRequestModel,
new ModelMap());
testPlanRequestModel.setTestPlanName("test");
testPlanRequestModel.setIpList(new ArrayList<String>());
}
}

View File

@ -1,120 +0,0 @@
package org.bench4q.web.api.test;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import org.bench4q.share.models.agent.ParameterModel;
import org.bench4q.share.models.agent.scriptrecord.BehaviorModel;
import org.bench4q.share.models.agent.scriptrecord.UsePluginModel;
import org.bench4q.share.models.master.PluginEditScriptRequestModel;
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.junit.Assert;
import org.junit.Before;
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 com.google.gson.Gson;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "file:src/main/resources/bench4qweb-servlet.xml" })
public class ScriptActionControllerTest {
private ScriptActionController scriptActionController;
private String accessToken;
private LoginHelper loginHelper;
public ScriptActionController getScriptActionController() {
return scriptActionController;
}
@Autowired
public void setScriptActionController(
ScriptActionController scriptActionController) {
this.scriptActionController = scriptActionController;
}
public LoginHelper getLoginHelper() {
return loginHelper;
}
@Autowired
public void setLoginHelper(LoginHelper loginHelper) {
this.loginHelper = loginHelper;
}
@Before
public void setUp() {
this.accessToken = this.getLoginHelper().login();
}
@Test
public void loadScriptsTest() throws CustomGenericException {
BaseResponseModel baseResponseModel = this.getScriptActionController()
.loadScript(this.accessToken);
if (baseResponseModel.isSuccess())
Assert.assertNotNull(baseResponseModel.getData());
@SuppressWarnings("unchecked")
List<ScriptModel> scriptModels = (List<ScriptModel>) baseResponseModel
.getData();
Logger.getLogger(ScriptActionControllerTest.class).info(
scriptModels.size());
assertTrue(scriptModels.size() > 0);
}
@Test
public void uploadPluginEditedScript() throws CustomGenericException {
@SuppressWarnings("unchecked")
int insertCountBefore = ((List<ScriptModel>) scriptActionController
.loadScript(accessToken).getData()).size();
PluginEditScriptRequestModel pluginEditScriptRequestModel = new PluginEditScriptRequestModel();
pluginEditScriptRequestModel
.setBehaviorModels(createBheBehaviorModels());
pluginEditScriptRequestModel
.setUsePluginModels(createUsePluginModels());
pluginEditScriptRequestModel.setScriptName("testScriptName");
Gson gson = new Gson();
BaseResponseModel baseResponseModel = scriptActionController
.uploadPluginEditedScript(accessToken,
gson.toJson(pluginEditScriptRequestModel));
@SuppressWarnings("unchecked")
int insertCountAfter = ((List<ScriptModel>) scriptActionController
.loadScript(accessToken).getData()).size();
Assert.assertTrue(baseResponseModel.isSuccess());
Assert.assertEquals(insertCountBefore + 1, insertCountAfter);
}
private List<BehaviorModel> createBheBehaviorModels() {
List<BehaviorModel> behaviorModels = new ArrayList<BehaviorModel>();
ParameterModel parameterModel = new ParameterModel();
parameterModel.setKey("url");
parameterModel.setValue("http://133.133.12.3:7979");
List<ParameterModel> parameterModels = new ArrayList<ParameterModel>();
BehaviorModel behaviorModel = BehaviorModel.UserBehaviorBuilder(0,
"url", "http", parameterModels);
behaviorModels.add(behaviorModel);
return behaviorModels;
}
private List<UsePluginModel> createUsePluginModels() {
List<UsePluginModel> usePluginModels = new ArrayList<UsePluginModel>();
UsePluginModel httpPluginModel = new UsePluginModel();
httpPluginModel.setId("http");
httpPluginModel.setName("Http");
usePluginModels.add(httpPluginModel);
return usePluginModels;
}
}

View File

@ -1,112 +0,0 @@
package org.bench4q.web.api.test;
import static org.junit.Assert.*;
import java.util.List;
import javax.xml.bind.JAXBException;
import junit.framework.Assert;
import org.apache.log4j.Logger;
import org.bench4q.share.enums.master.TestPlanStatus;
import org.bench4q.web.api.MonitorController;
import org.bench4q.web.exception.CustomGenericException;
import org.bench4q.web.model.BaseResponseModel;
import org.bench4q.web.model.ResultModel;
import org.bench4q.web.model.WebTestPlanResultModel;
import org.bench4q.web.tool.test.GsonHelper;
import org.bench4q.web.tool.test.LoginHelper;
import org.bench4q.web.tool.test.TestPlanHelper;
import org.junit.Before;
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 TestMonitorResult extends LoginHelper {
private MonitorController monitorController;
private TestPlanHelper startTestPlan;
private String accessToken;
private String testPlanId;
private Logger logger = Logger.getLogger(TestMonitorResult.class);
public MonitorController getMonitorController() {
return monitorController;
}
@Autowired
public void setMonitorController(MonitorController monitorController) {
this.monitorController = monitorController;
}
public TestPlanHelper getStartTestPlan() {
return startTestPlan;
}
@Autowired
public void setStartTestPlan(TestPlanHelper startTestPlan) {
this.startTestPlan = startTestPlan;
}
@Before
public void setUp() {
this.accessToken = login();
this.getStartTestPlan().startTest(accessToken);
this.testPlanId = this.getStartTestPlan().getTestPlanRunId();
}
@SuppressWarnings("unchecked")
@Test
public void test_getMemoryResult() throws InterruptedException,
CustomGenericException, JAXBException {
testTestPlanStatus();
BaseResponseModel baseResponseModel = this.getMonitorController()
.getMemoryStatus(accessToken, testPlanId,
TestPlanHelper.MONITOR_IP, "5556", "pagesPerSecond",
"0");
assertTrue(baseResponseModel.isSuccess());
List<ResultModel> resultModels = (List<ResultModel>) baseResponseModel
.getData();
logger.info(GsonHelper.getGson().toJson(resultModels));
assertTrue(resultModels.size() > 0);
}
@Test
public void test_getCpuResult() throws InterruptedException, CustomGenericException, JAXBException{
testTestPlanStatus();
BaseResponseModel baseResponseModel = this.getMonitorController()
.getCpuResult(accessToken, testPlanId, TestPlanHelper.MONITOR_IP, "5556", "cpu0", "processorTimePercent", "0");
assertTrue(baseResponseModel.isSuccess());
@SuppressWarnings("unchecked")
List<ResultModel> resultModels = (List<ResultModel>) baseResponseModel
.getData();
logger.info(GsonHelper.getGson().toJson(resultModels));
assertTrue(resultModels.size() > 0);
}
@Test
public void test_getNetwork() throws InterruptedException, CustomGenericException, JAXBException{
testTestPlanStatus();
BaseResponseModel baseResponseModel = this.getMonitorController()
.getCpuResult(accessToken, testPlanId, TestPlanHelper.MONITOR_IP, "5556", "cpu0", "processorTimePercent", "0");
assertTrue(baseResponseModel.isSuccess());
@SuppressWarnings("unchecked")
List<ResultModel> resultModels = (List<ResultModel>) baseResponseModel
.getData();
logger.info(GsonHelper.getGson().toJson(resultModels));
assertTrue(resultModels.size() > 0);
}
private void testTestPlanStatus() throws InterruptedException,
CustomGenericException, JAXBException {
Assert.assertNotNull(this.getStartTestPlan().getTestPlanRunId());
assertNotNull(testPlanId);
Thread.sleep(6000);
WebTestPlanResultModel webTestPlanResultModel = this.getStartTestPlan()
.queryTestPlanResultModel(testPlanId, accessToken);
assertEquals(TestPlanStatus.InRunning,
webTestPlanResultModel.getCurrentStatus());
}
}

View File

@ -1,217 +0,0 @@
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.TestPlanHelper;
import org.junit.After;
import org.junit.Before;
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 com.google.gson.Gson;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "file:src/test/resources/bench4qweb-servlet.xml" })
public class TestScriptResultTest extends LoginHelper {
private TestPlanActionController testPlanActionController;
private TestPlanHelper testPlanHelper;
private String testPlanId;
private String accessToken;
private Logger logger = Logger.getLogger(TestScriptResultTest.class);
private TestPlanService testPlanService;
private String scriptId;
public TestPlanActionController getTestPlanActionController() {
return testPlanActionController;
}
@Autowired
public void setTestPlanActionController(
TestPlanActionController testPlanActionController) {
this.testPlanActionController = testPlanActionController;
}
public TestPlanHelper getStartTestPlan() {
return testPlanHelper;
}
@Autowired
public void setStartTestPlan(TestPlanHelper startTestPlan) {
this.testPlanHelper = startTestPlan;
}
public TestPlanService getTestPlanService() {
return testPlanService;
}
@Autowired
public void setTestPlanService(TestPlanService testPlanService) {
this.testPlanService = testPlanService;
}
@Before
public void setUp() {
this.accessToken = this.login();
this.testPlanHelper.startTest(accessToken);
this.testPlanId = this.testPlanHelper.getTestPlanRunId();
this.scriptId = this.getOneScriptId(testPlanId, accessToken);
}
@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(this.accessToken,
this.testPlanHelper.getTestPlanRunId());
@SuppressWarnings("unchecked")
Map<String, Integer> scriptIdMap = (Map<String, Integer>) baseResponseModel
.getData();
Assert.assertTrue(scriptIdMap.size() > 0);
}
@Test
public void test_getTestPageBriefModel() throws InterruptedException,
CustomGenericException, JAXBException {
assertNotNull(this.testPlanId);
assertNotNull(this.scriptId);
Thread.sleep(3000);
WebTestPlanResultModel webTestPlanResultModel = this.getStartTestPlan()
.queryTestPlanResultModel(testPlanId, accessToken);
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(), accessToken);
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, accessToken),
"averageResponseTime", "0");
assertTrue(baseResponseModel.isSuccess());
List<ResultModel> resultModels = (List<ResultModel>) baseResponseModel
.getData();
Logger.getLogger("get result model");
Logger.getLogger(TestScriptResultTest.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(), accessToken);
Thread.sleep(3000);
BaseResponseModel baseResponseModel = this
.getTestPlanActionController().getScriptBehaviorBriefModel(
accessToken, this.testPlanId, scriptId);
ScriptBehaviorsBriefModel scriptBehaviorsBriefModel = (ScriptBehaviorsBriefModel) baseResponseModel
.getData();
logger.info(GsonHelper.getGson().toJson(scriptBehaviorsBriefModel));
Assert.assertNotNull(scriptBehaviorsBriefModel);
Assert.assertNotNull(scriptBehaviorsBriefModel
.getTestBehaviorsBriefModel());
Assert.assertTrue(scriptBehaviorsBriefModel
.getTestBehaviorsBriefModel().getBehaviorBriefModels().size() > 0);
}
private String getOneScriptId(String testPlanRunId, String accessToken) {
try {
return this.getStartTestPlan()
.queryTestPlanResultModel(testPlanRunId, accessToken)
.getScriptIds().get(0).toString();
} catch (CustomGenericException e) {
logger.info(ExceptionLog.getStackTrace(e));
return null;
} catch (JAXBException e) {
logger.info(ExceptionLog.getStackTrace(e));
return null;
}
}
@SuppressWarnings("unchecked")
@Test
public void test_getSutInfo() throws CustomGenericException, JAXBException,
InterruptedException {
testTestPlanStatus();
List<SutInfo> sutInfos = (List<SutInfo>) this
.getTestPlanActionController()
.getSutInfo(accessToken, testPlanId).getData();
for (SutInfo sutInfo : sutInfos) {
assertEquals("5556", sutInfo.getPort());
assertEquals(TestPlanHelper.MONITOR_IP, sutInfo.getIp());
Gson gson = new Gson();
logger.info(gson.toJson(sutInfo));
}
assertEquals(1, sutInfos.size());
}
private void testTestPlanStatus() throws InterruptedException,
CustomGenericException, JAXBException {
Assert.assertNotNull(this.getStartTestPlan().getTestPlanRunId());
assertNotNull(testPlanId);
Thread.sleep(6000);
WebTestPlanResultModel webTestPlanResultModel = this.getStartTestPlan()
.queryTestPlanResultModel(testPlanId, accessToken);
assertEquals(TestPlanStatus.InRunning,
webTestPlanResultModel.getCurrentStatus());
}
}

View File

@ -1,52 +0,0 @@
package org.bench4q.web.api.test;
import static org.junit.Assert.*;
import org.apache.log4j.Logger;
import org.bench4q.web.api.TestPlanHistoryResult;
import org.bench4q.web.exception.CustomGenericException;
import org.bench4q.web.model.BaseResponseModel;
import org.bench4q.web.model.TestPlanListModel;
import org.bench4q.web.tool.test.GsonHelper;
import org.bench4q.web.tool.test.LoginHelper;
import org.junit.Before;
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 TestTestHistory extends LoginHelper {
private TestPlanHistoryResult testPlanHistoryResult;
private String accessToken;
private Logger logger = Logger.getLogger(TestTestHistory.class);
public TestPlanHistoryResult getTestPlanHistoryResult() {
return testPlanHistoryResult;
}
@Autowired
public void setTestPlanHistoryResult(
TestPlanHistoryResult testPlanHistoryResult) {
this.testPlanHistoryResult = testPlanHistoryResult;
}
@Before
public void setUp() {
this.accessToken = login();
}
@Test
public void test_loadTestHistory() throws CustomGenericException {
BaseResponseModel baseResponseModel = this.getTestPlanHistoryResult()
.loadTestPlans(accessToken);
logger.info(GsonHelper.getGson().toJson(baseResponseModel));
assertTrue(baseResponseModel.isSuccess());
TestPlanListModel testPlanListModel = (TestPlanListModel) baseResponseModel
.getData();
assertTrue(testPlanListModel.getList().size() > 0);
}
}