fix the bug in get behavior infos ,add test

This commit is contained in:
fanfuxiaoran 2014-04-22 11:11:13 +08:00
parent dc45262df6
commit d035288cfa
4 changed files with 396 additions and 366 deletions

View File

@ -1,42 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- <!DOCTYPE ui SYSTEM "ui.dtd"> -->
<ui>
<plugin name="CsvProvider">
<params>
<param name="fileName" label="The name of the input file(Required)">
<field size="7" />
</param>
<param name="separator"
label="The separator of the input file and the following fieldNames">
<field size="7" />
</param>
<param name="fieldNames" label="fields names:">
<nfield />
</param>
<param name="shared" label="to share the file descriptor">
<checkbox>
<choice value="enable" default="false" />
</checkbox>
</param>
<param name="loop" label="when to the EOF, is in loop">
<checkbox>
<choice value="enable" default="true" />
</checkbox>
</param>
<param name="loadAtRuntime" label="is to load it at runtime">
<checkbox>
<choice value="loadAtRuntime" default="true" />
</checkbox>
</param>
<param name="commentPrefix" label="perfix of the commnet">
<nfield></nfield>
</param>
</params>
</plugin>
<behavior name="next">
<params />
</behavior>
<timer name="reset">
<params />
</timer>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<!-- <!DOCTYPE ui SYSTEM "ui.dtd"> -->
<ui>
<plugin name="CsvProvider">
<params>
<param name="fileName" label="The name of the input file(Required)">
<field size="7" />
</param>
<param name="separator"
label="The separator of the input file and the following fieldNames">
<field size="7" />
</param>
<param name="fieldNames" label="fields names:">
<nfield />
</param>
<param name="shared" label="to share the file descriptor">
<checkbox>
<choice value="enable" default="false" />
</checkbox>
</param>
<param name="loop" label="when to the EOF, is in loop">
<checkbox>
<choice value="enable" default="true" />
</checkbox>
</param>
<param name="loadAtRuntime" label="is to load it at runtime">
<checkbox>
<choice value="loadAtRuntime" default="true" />
</checkbox>
</param>
<param name="commentPrefix" label="perfix of the commnet">
<nfield></nfield>
</param>
</params>
</plugin>
<behavior name="next">
<params>
<param name="loadAtRuntime" label="is to load it at runtime">
<checkbox>
<choice value="loadAtRuntime" default="true" />
</checkbox>
</param>
<param name="commentPrefix" label="perfix of the commnet">
<nfield></nfield>
</param>
</params>
</behavior>
<timer name="reset">
<params>
<param name="fileName" label="The name of the input file(Required)">
<field size="7" />
</param>
</params>
</timer>
</ui>

View File

@ -1,303 +1,305 @@
package org.bench4q.master.api;
import java.io.File;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import javax.xml.bind.JAXBException;
import org.apache.commons.io.FileUtils;
import org.apache.log4j.Logger;
import org.bench4q.master.domain.entity.Port;
import org.bench4q.master.domain.entity.Script;
import org.bench4q.master.domain.factory.BusinessModelMapFactory;
import org.bench4q.master.domain.service.PortPoolService;
import org.bench4q.master.domain.service.ScriptService;
import org.bench4q.master.domain.service.UserService;
import org.bench4q.master.exception.Bench4QException;
import org.bench4q.master.exception.ExceptionLog;
import org.bench4q.recorder.ScriptCapturer;
import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.agent.RunScenarioModel;
import org.bench4q.share.models.master.OperateScriptServerResponseModel;
import org.bench4q.share.models.master.ScriptModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
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;
@Controller
@RequestMapping("/RecordScript")
public class ScriptController extends BaseController {
private ScriptCapturer scriptCapturer;
private ScriptService scriptService;
private PortPoolService portPoolService = new PortPoolService();
private static final Object PORT_LOCK = new Object();
private Logger logger = Logger.getLogger(ScriptController.class);
private ScriptCapturer getScriptCapturer() {
return scriptCapturer;
}
@Autowired
private void setScriptCapturer(ScriptCapturer scriptCapturer) {
this.scriptCapturer = scriptCapturer;
}
private ScriptService getScriptService() {
return scriptService;
}
@Autowired
private void setScriptService(ScriptService scriptService) {
this.scriptService = scriptService;
}
private PortPoolService getPortPoolService() {
return portPoolService;
}
@Autowired
private void setPortPoolService(PortPoolService portPoolService) {
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());
}
private String buildScriptSavePath() {
String dirString = "Scripts" + System.getProperty("file.separator")
+ this.getPrincipal().getUserName()
+ System.getProperty("file.separator")
+ new SimpleDateFormat("yyyyMMdd").format(new Date());
File dirFile = new File(dirString);
if (!dirFile.exists()) {
dirFile.mkdirs();
}
return dirString;
}
@RequestMapping(value = "/stopScriptRecordServer", method = {
RequestMethod.POST, RequestMethod.GET })
@ResponseBody
public OperateScriptServerResponseModel stopScriptRecordServer(
@RequestParam int port, @RequestParam String fileNameUUID) {
if (!checkScope(UserService.NORAML_AUTHENTICATION)) {
return buildReponseModel(false,
"has no power for stopScriptCapture!!!", "", -1, null,
null, null);
}
this.getScriptCapturer().stopCurrentRecord(port);
synchronized (PORT_LOCK) {
this.getPortPoolService().backPort(port);
}
return buildReponseModel(true, "RecordServer stop", "", port, null,
null, fileNameUUID);
}
@RequestMapping(value = "/saveScriptToDB", method = { RequestMethod.GET,
RequestMethod.POST })
@ResponseBody
public OperateScriptServerResponseModel saveScriptToDB(
@RequestParam String scriptName, @RequestParam int port,
@RequestParam String fileNameUUID) {
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
return buildReponseModel(false,
"saveScriptToDB check your scope fail!", "", -1, null,
null, null);
}
File file = new File(buildScriptSavePath()
+ System.getProperty("file.separator") + fileNameUUID + ".xml");
if (!file.exists()) {
return buildReponseModel(false, "no that script", null, -1, null,
null, fileNameUUID);
}
try {
String content = FileUtils.readFileToString(file);
logger.info("when saveToDB, scriptContent is " + content);
boolean success = this.getScriptService().saveScript(scriptName,
this.getPrincipal().getId(), content);
// this.getUserService().add
return buildReponseModel(success, "Save to DataBase!!", "", port,
null, null, null);
} catch (Exception e) {
return buildReponseModel(false, "exception when read from file",
null, -1, null, null, fileNameUUID);
}
}
@RequestMapping(value = "/uploadScript/{scriptName}", method = RequestMethod.PUT)
@ResponseBody
public OperateScriptServerResponseModel uploadScriptToDB(
@PathVariable String scriptName,
@RequestBody RunScenarioModel scenarioModel)
throws Bench4QException {
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
throw new Bench4QException(HAVE_NO_POWER, HAVE_NO_POWER
+ "for upload a script", "/uploadScript");
}
try {
boolean success = this.getScriptService().saveScript(
scriptName,
this.getPrincipal().getId(),
MarshalHelper
.marshal(RunScenarioModel.class, scenarioModel));
logger.info("upload script:"
+ MarshalHelper.marshal(RunScenarioModel.class,
scenarioModel));
return buildReponseModel(success, null, null, -1, null, null, null);
} catch (JAXBException 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 = "/loadScriptList", method = { RequestMethod.POST,
RequestMethod.GET })
@ResponseBody
public OperateScriptServerResponseModel loadScriptList() {
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
return null;
}
List<Script> scripts = this.getScriptService().loadScripts(
this.getPrincipal());
return this.buildReponseModel(true, null, null, 0,
dealWithCollection(scripts), null, null);
}
@RequestMapping(value = "/queryScriptsByDate", method = RequestMethod.POST)
@ResponseBody
public OperateScriptServerResponseModel queryScriptsByDate(
@RequestParam Date startDate, @RequestParam Date endDate) {
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
return null;
}
List<Script> scripts = this.getScriptService()
.queryScriptsByCreateTime(startDate, endDate,
this.getPrincipal());
return this.buildReponseModel(true, null, null, 0,
dealWithCollection(scripts), null, null);
}
private List<ScriptModel> dealWithCollection(Collection<Script> scripts) {
List<ScriptModel> scriptModels = new ArrayList<ScriptModel>();
for (Script script : scripts) {
scriptModels.add(BusinessModelMapFactory.toModel(script));
}
return scriptModels;
}
@RequestMapping(value = "/queryScriptById", method = { RequestMethod.GET,
RequestMethod.POST })
@ResponseBody
public OperateScriptServerResponseModel queryScriptById(
@RequestParam int scriptId) {
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
return null;
}
return this.buildReponseModel(true, null, null, 0, null,
BusinessModelMapFactory.toModel(this.getScriptService()
.getScript(scriptId)), null);
}
@RequestMapping(value = "/queryScriptByName", method = { RequestMethod.GET,
RequestMethod.POST })
@ResponseBody
public OperateScriptServerResponseModel queryScriptByName(
@RequestParam String name) {
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
return null;
}
return this.buildReponseModel(true, null, null, 0, null,
BusinessModelMapFactory.toModel(this.getScriptService()
.getScriptByName(name)), null);
}
@RequestMapping(value = "/deleteScript", method = { RequestMethod.GET,
RequestMethod.POST })
@ResponseBody
public OperateScriptServerResponseModel deleteScript(
@RequestParam int scriptId) {
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
return null;
}
return this.buildReponseModel(
this.getScriptService().deleteScript(scriptId,
this.getPrincipal().getId()), "", "", 0, null, null,
null);
}
@RequestMapping(value = "updateScript/{scriptId}", method = {
RequestMethod.GET, RequestMethod.PUT })
@ResponseBody
public OperateScriptServerResponseModel updateScript(
@PathVariable int scriptId, @RequestBody String content) {
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), "", "", 0, null,
null, null);
}
private OperateScriptServerResponseModel buildReponseModel(
boolean isSuccess, String failCauseString, String hostName,
int port, List<ScriptModel> scriptModels, ScriptModel scriptModel,
String fileName) {
OperateScriptServerResponseModel responseModel = new OperateScriptServerResponseModel();
responseModel.setSuccess(isSuccess);
responseModel.setFailCauseString(failCauseString);
responseModel.setHostName(hostName);
responseModel.setPort(port);
responseModel.setFileName(fileName);
if (scriptModels == null || scriptModels.size() == 0) {
scriptModels = new ArrayList<ScriptModel>();
scriptModels.add(scriptModel);
}
responseModel.setScriptModels(scriptModels);
return responseModel;
}
}
package org.bench4q.master.api;
import java.io.File;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import javax.xml.bind.JAXBException;
import org.apache.commons.io.FileUtils;
import org.apache.log4j.Logger;
import org.bench4q.master.domain.entity.Port;
import org.bench4q.master.domain.entity.Script;
import org.bench4q.master.domain.factory.BusinessModelMapFactory;
import org.bench4q.master.domain.service.PortPoolService;
import org.bench4q.master.domain.service.ScriptService;
import org.bench4q.master.domain.service.UserService;
import org.bench4q.master.exception.Bench4QException;
import org.bench4q.master.exception.ExceptionLog;
import org.bench4q.recorder.ScriptCapturer;
import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.agent.RunScenarioModel;
import org.bench4q.share.models.master.OperateScriptServerResponseModel;
import org.bench4q.share.models.master.ScriptModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
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;
@Controller
@RequestMapping("/RecordScript")
public class ScriptController extends BaseController {
private ScriptCapturer scriptCapturer;
private ScriptService scriptService;
private PortPoolService portPoolService = new PortPoolService();
private static final Object PORT_LOCK = new Object();
private Logger logger = Logger.getLogger(ScriptController.class);
private ScriptCapturer getScriptCapturer() {
return scriptCapturer;
}
@Autowired
private void setScriptCapturer(ScriptCapturer scriptCapturer) {
this.scriptCapturer = scriptCapturer;
}
private ScriptService getScriptService() {
return scriptService;
}
@Autowired
private void setScriptService(ScriptService scriptService) {
this.scriptService = scriptService;
}
private PortPoolService getPortPoolService() {
return portPoolService;
}
@Autowired
private void setPortPoolService(PortPoolService portPoolService) {
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());
}
private String buildScriptSavePath() {
String dirString = "Scripts" + System.getProperty("file.separator")
+ this.getPrincipal().getUserName()
+ System.getProperty("file.separator")
+ new SimpleDateFormat("yyyyMMdd").format(new Date());
File dirFile = new File(dirString);
if (!dirFile.exists()) {
dirFile.mkdirs();
}
return dirString;
}
@RequestMapping(value = "/stopScriptRecordServer", method = {
RequestMethod.POST, RequestMethod.GET })
@ResponseBody
public OperateScriptServerResponseModel stopScriptRecordServer(
@RequestParam int port, @RequestParam String fileNameUUID) {
if (!checkScope(UserService.NORAML_AUTHENTICATION)) {
return buildReponseModel(false,
"has no power for stopScriptCapture!!!", "", -1, null,
null, null);
}
this.getScriptCapturer().stopCurrentRecord(port);
synchronized (PORT_LOCK) {
this.getPortPoolService().backPort(port);
}
return buildReponseModel(true, "RecordServer stop", "", port, null,
null, fileNameUUID);
}
@RequestMapping(value = "/saveScriptToDB", method = { RequestMethod.GET,
RequestMethod.POST })
@ResponseBody
public OperateScriptServerResponseModel saveScriptToDB(
@RequestParam String scriptName, @RequestParam int port,
@RequestParam String fileNameUUID) {
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
return buildReponseModel(false,
"saveScriptToDB check your scope fail!", "", -1, null,
null, null);
}
File file = new File(buildScriptSavePath()
+ System.getProperty("file.separator") + fileNameUUID + ".xml");
if (!file.exists()) {
return buildReponseModel(false, "no that script", null, -1, null,
null, fileNameUUID);
}
try {
String content = FileUtils.readFileToString(file);
logger.info("when saveToDB, scriptContent is " + content);
boolean success = this.getScriptService().saveScript(scriptName,
this.getPrincipal().getId(), content);
// this.getUserService().add
return buildReponseModel(success, "Save to DataBase!!", "", port,
null, null, null);
} catch (Exception e) {
return buildReponseModel(false, "exception when read from file",
null, -1, null, null, fileNameUUID);
}
}
@RequestMapping(value = "/uploadScript/{scriptName}", method = RequestMethod.PUT)
@ResponseBody
public OperateScriptServerResponseModel uploadScriptToDB(
@PathVariable String scriptName,
@RequestBody RunScenarioModel scenarioModel)
throws Bench4QException {
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
throw new Bench4QException(HAVE_NO_POWER, HAVE_NO_POWER
+ "for upload a script", "/uploadScript");
}
try {
boolean success = this.getScriptService().saveScript(
scriptName,
this.getPrincipal().getId(),
MarshalHelper
.marshal(RunScenarioModel.class, scenarioModel));
logger.info("upload script:"
+ MarshalHelper.marshal(RunScenarioModel.class,
scenarioModel));
return buildReponseModel(success, null, null, -1, null, null, null);
} catch (JAXBException 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 = "/loadScriptList", method = { RequestMethod.POST,
RequestMethod.GET })
@ResponseBody
public OperateScriptServerResponseModel loadScriptList() {
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
return null;
}
List<Script> scripts = this.getScriptService().loadScripts(
this.getPrincipal());
OperateScriptServerResponseModel result = this.buildReponseModel(true,
null, null, 0, dealWithCollection(scripts), null, null);
logger.info(MarshalHelper.tryMarshal( result));
return result;
}
@RequestMapping(value = "/queryScriptsByDate", method = RequestMethod.POST)
@ResponseBody
public OperateScriptServerResponseModel queryScriptsByDate(
@RequestParam Date startDate, @RequestParam Date endDate) {
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
return null;
}
List<Script> scripts = this.getScriptService()
.queryScriptsByCreateTime(startDate, endDate,
this.getPrincipal());
return this.buildReponseModel(true, null, null, 0,
dealWithCollection(scripts), null, null);
}
private List<ScriptModel> dealWithCollection(Collection<Script> scripts) {
List<ScriptModel> scriptModels = new ArrayList<ScriptModel>();
for (Script script : scripts) {
scriptModels.add(BusinessModelMapFactory.toModel(script));
}
return scriptModels;
}
@RequestMapping(value = "/queryScriptById", method = { RequestMethod.GET,
RequestMethod.POST })
@ResponseBody
public OperateScriptServerResponseModel queryScriptById(
@RequestParam int scriptId) {
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
return null;
}
return this.buildReponseModel(true, null, null, 0, null,
BusinessModelMapFactory.toModel(this.getScriptService()
.getScript(scriptId)), null);
}
@RequestMapping(value = "/queryScriptByName", method = { RequestMethod.GET,
RequestMethod.POST })
@ResponseBody
public OperateScriptServerResponseModel queryScriptByName(
@RequestParam String name) {
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
return null;
}
return this.buildReponseModel(true, null, null, 0, null,
BusinessModelMapFactory.toModel(this.getScriptService()
.getScriptByName(name)), null);
}
@RequestMapping(value = "/deleteScript", method = { RequestMethod.GET,
RequestMethod.POST })
@ResponseBody
public OperateScriptServerResponseModel deleteScript(
@RequestParam int scriptId) {
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
return null;
}
return this.buildReponseModel(
this.getScriptService().deleteScript(scriptId,
this.getPrincipal().getId()), "", "", 0, null, null,
null);
}
@RequestMapping(value = "updateScript/{scriptId}", method = {
RequestMethod.GET, RequestMethod.PUT })
@ResponseBody
public OperateScriptServerResponseModel updateScript(
@PathVariable int scriptId, @RequestBody String content) {
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), "", "", 0, null,
null, null);
}
private OperateScriptServerResponseModel buildReponseModel(
boolean isSuccess, String failCauseString, String hostName,
int port, List<ScriptModel> scriptModels, ScriptModel scriptModel,
String fileName) {
OperateScriptServerResponseModel responseModel = new OperateScriptServerResponseModel();
responseModel.setSuccess(isSuccess);
responseModel.setFailCauseString(failCauseString);
responseModel.setHostName(hostName);
responseModel.setPort(port);
responseModel.setFileName(fileName);
if (scriptModels == null || scriptModels.size() == 0) {
scriptModels = new ArrayList<ScriptModel>();
scriptModels.add(scriptModel);
}
responseModel.setScriptModels(scriptModels);
return responseModel;
}
}

View File

@ -54,16 +54,21 @@ public class PluginEntityFactory {
return behaviorInfos;
}
private BehaviorInfo createBehaviorInfoWithOutId(Element element,
PluginUI pluginUI) {
BehaviorInfo behaviorInfo = new BehaviorInfo();
behaviorInfo.setBehavoirType(element.getName());
behaviorInfo.setName(XmlParseHelper.getAttribute(element, "name"));
behaviorInfo.setPluginUI(pluginUI);
Element paramsElement = XmlParseHelper.getOneChildElementByName(
element, "params");
behaviorInfo.setParams(createBehaviorParamInfos(
XmlParseHelper.getChildElements(element), behaviorInfo));
XmlParseHelper.getChildElements(paramsElement), behaviorInfo));
return behaviorInfo;
}
//combine this code with the pluginParamInfo
private Set<BehaviorParamInfo> createBehaviorParamInfos(
List<Element> elements, BehaviorInfo behaviorInfo) {
@ -79,21 +84,7 @@ public class PluginEntityFactory {
return paramInfos;
}
private BehaviorParamInfo createBehaviorParamInfo(Element element,
BehaviorInfo behaviorInfo) {
if (XmlParseHelper.getAttribute(element, "name") == null)
return null;
BehaviorParamInfo behaviorParamInfo = new BehaviorParamInfo();
behaviorParamInfo.setLable(XmlParseHelper
.getAttribute(element, "lable"));
behaviorParamInfo.setName(XmlParseHelper.getAttribute(element, "name"));
ParamTypeFactory paramTypeFactory = new ParamTypeFactory();
behaviorParamInfo.setParamType(paramTypeFactory
.createParamTypeInfo(XmlParseHelper.getSingleChild(element)));
behaviorParamInfo.setBehaviorInfo(behaviorInfo);
return behaviorParamInfo;
}
private Document getDocument(String pluginUI) {
try {
@ -130,7 +121,22 @@ public class PluginEntityFactory {
paramInfos = null;
return paramInfos;
}
private BehaviorParamInfo createBehaviorParamInfo(Element element,
BehaviorInfo behaviorInfo) {
if (XmlParseHelper.getAttribute(element, "name") == null)
return null;
BehaviorParamInfo behaviorParamInfo = new BehaviorParamInfo();
behaviorParamInfo.setLable(XmlParseHelper
.getAttribute(element, "lable"));
behaviorParamInfo.setName(XmlParseHelper.getAttribute(element, "name"));
ParamTypeFactory paramTypeFactory = new ParamTypeFactory();
behaviorParamInfo.setParamType(paramTypeFactory
.createParamTypeInfo(XmlParseHelper.getSingleChild(element)));
behaviorParamInfo.setBehaviorInfo(behaviorInfo);
System.out.println(behaviorParamInfo.getName());
return behaviorParamInfo;
}
private PluginParamInfo createPluginParamInfoWithOutId(Element element,
PluginInfo pluginInfo) {
if (XmlParseHelper.getAttribute(element, "name") == null)
@ -204,7 +210,7 @@ class ParamTypeFactory {
private CheckBoxType createCheckBoxType(Element element) {
CheckBoxType checkBoxType = new CheckBoxType();
checkBoxType.setType("choiceBox");
checkBoxType.setType("checkBox");
checkBoxType.setChoiceList(createChoiceTypes(
XmlParseHelper.getChildElements(element), checkBoxType));
return checkBoxType;

View File

@ -7,7 +7,6 @@ import java.io.IOException;
import java.util.Map;
import javax.xml.bind.JAXBException;
import org.apache.commons.io.FileUtils;
import org.apache.log4j.Logger;
import org.bench4q.master.domain.service.PluginService;
@ -15,6 +14,7 @@ import org.bench4q.master.exception.ExceptionLog;
import org.bench4q.master.test.testHelper.Test_PluginHelper;
import org.bench4q.share.communication.HttpRequester.HttpResponse;
import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.master.plugin.BehaviorInfoModel;
import org.bench4q.share.models.master.plugin.PluginResponseModel;
import org.junit.After;
import org.junit.Assert;
@ -25,7 +25,6 @@ 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 = { "classpath:service-test-context.xml" })
public class PluginControllerTest extends TestBase {
@ -137,8 +136,8 @@ public class PluginControllerTest extends TestBase {
}
@Test
public void testGetBehaviors() throws IOException {
public void testGetBehaviors() throws IOException, JAXBException {
this.getPluginService().deletePlugin(pluginName);
this.getTest_PluginHelper().addPlugin(fileName,
this.getPluginService(), pluginName);
String url = URLSTRING + "/loadBehaviors/" + this.pluginName;
@ -150,6 +149,16 @@ public class PluginControllerTest extends TestBase {
assertNotNull(pluginResponseModel);
assertTrue(pluginResponseModel.isSuccess());
assertEquals(2, pluginResponseModel.getBehaviorInfoModels().size());
this.getPluginService().deletePlugin(pluginName);
int behaviorParamCount = 0;
for (BehaviorInfoModel behaviorInfoModel : pluginResponseModel
.getBehaviorInfoModels()) {
behaviorParamCount += behaviorInfoModel.getParamInfoModels().size();
}
assertEquals(3, behaviorParamCount);
System.out.println(MarshalHelper.marshal(PluginResponseModel.class,
pluginResponseModel));
this.getPluginService().deletePlugin(pluginName);
}
@Test