From 44846f04cb0238cbe998af1765572929a0dd4735 Mon Sep 17 00:00:00 2001 From: fanfuxiaoran <495538672@qq.com> Date: Wed, 7 May 2014 08:34:35 +0800 Subject: [PATCH] refactor plugin --- .../bench4q/master/api/PluginController.java | 302 +++++++++--------- .../domain/entity/plugin/BehaviorInfo.java | 17 +- .../master/domain/entity/plugin/Group.java | 49 +-- .../domain/entity/plugin/ParamInfo.java | 8 +- .../domain/entity/plugin/ParamType.java | 5 +- .../domain/entity/plugin/ParamsContainer.java | 16 +- .../domain/entity/plugin/PluginInfo.java | 16 +- .../master/domain/entity/plugin/PluginUI.java | 6 +- .../domain/factory/PluginDomainFactory.java | 207 ------------ .../domain/factory/PluginEntityFactory.java | 133 ++++---- .../domain/factory/TestPlanFactory.java | 22 -- .../master/domain/service/PluginService.java | 87 +++-- .../bench4q/master/config/hibernate.cfg.xml | 5 +- .../test/controller/PluginControllerTest.java | 102 +++--- .../factory/Test_PluginDomainFactory.java | 184 +++++------ .../factory/Test_PluginEntityFactory.java | 20 +- .../test/service/Test_PluginService.java | 32 +- .../resources/repository-test-context.xml | 3 +- 18 files changed, 504 insertions(+), 710 deletions(-) delete mode 100644 Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/PluginDomainFactory.java diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/api/PluginController.java b/Bench4Q-Master/src/main/java/org/bench4q/master/api/PluginController.java index 9fa16cb1..e0d0f160 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/api/PluginController.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/api/PluginController.java @@ -1,151 +1,151 @@ -package org.bench4q.master.api; - -import java.util.List; - -import org.apache.log4j.Logger; -import org.bench4q.master.domain.service.PluginService; -import org.bench4q.master.domain.service.UserService; -import org.bench4q.master.exception.Bench4QException; -import org.bench4q.master.exception.ExceptionLog; -import org.bench4q.share.models.master.plugin.BehaviorInfoModel; -import org.bench4q.share.models.master.plugin.PluginResponseModel; -import org.bench4q.share.models.master.plugin.PluginUIModel; -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.ResponseBody; - -@Controller -@RequestMapping("/plugin") -public class PluginController extends BaseController { - private Logger logger = Logger.getLogger(PluginController.class); - private PluginService pluginService; - - public PluginService getPluginService() { - return pluginService; - } - - @Autowired - public void setPluginService(PluginService pluginService) { - this.pluginService = pluginService; - } - - @RequestMapping(value = "/loadPluginList", method = { RequestMethod.GET, - RequestMethod.POST }) - @ResponseBody - public PluginResponseModel loadPluginUIModels() throws Bench4QException { - if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) { - throw new Bench4QException(400 + "", "not permitted", - "/loadPluginList"); - } - PluginResponseModel pluginResponseModel = new PluginResponseModel(); - try { - List pluginUIModels = this.getPluginService() - .loadPluginUIs(); - if (pluginUIModels == null) { - pluginResponseModel.setSuccess(false); - } else { - pluginResponseModel.setSuccess(true); - pluginResponseModel.setPluginUIModels(pluginUIModels); - } - return pluginResponseModel; - } catch (Exception e) { - logger.info(ExceptionLog.getStackTrace(e)); - pluginResponseModel.setSuccess(false); - return pluginResponseModel; - } - - } - - @RequestMapping("/loadPluginNameList") - @ResponseBody - public PluginResponseModel loadPluginList() throws Bench4QException { - if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) { - throw new Bench4QException(400 + "", "not permitted", - "/loadPluginNameList"); - } - PluginResponseModel pluginResponseModel = new PluginResponseModel(); - pluginResponseModel.setPluginList(this.getPluginService() - .getPluginNameList()); - - pluginResponseModel.setSuccess(true); - return pluginResponseModel; - } - - @RequestMapping(value = "/loadBehaviors/{pluginName}", method = { - RequestMethod.GET, RequestMethod.POST }) - @ResponseBody - public PluginResponseModel getBehaviorsInPlugin( - @PathVariable("pluginName") String pluginName) - throws Bench4QException { - - if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) { - throw new Bench4QException(400 + "", "not permitted", - "/loadBehaviors/{pluginName}"); - } - PluginResponseModel pluginResponseModel = new PluginResponseModel(); - try { - if (!this.getPluginService().isPluginExist(pluginName)) { - pluginResponseModel.setSuccess(false); - pluginResponseModel.setFailMessage("plugin not exist"); - return pluginResponseModel; - } - - List behaviorInfoModels = this - .getPluginService().loadBehaviorInfoModels(pluginName); - if (behaviorInfoModels == null) { - pluginResponseModel.setFailMessage("no behaviors in plugin"); - pluginResponseModel.setSuccess(false); - } - - else { - pluginResponseModel.setSuccess(true); - pluginResponseModel.setBehaviorInfoModels(behaviorInfoModels); - } - - return pluginResponseModel; - } catch (Exception e) { - logger.error(ExceptionLog.getStackTrace(e)); - pluginResponseModel.setSuccess(false); - return pluginResponseModel; - } - } - - @RequestMapping(value = "/addPlugin", method = { RequestMethod.PUT }) - @ResponseBody - public PluginResponseModel addPlugin(@RequestBody String plugin) - throws Bench4QException { - if (!this.checkScope(UserService.SUPER_AUTHENTICATION)) { - throw new Bench4QException(400 + "", "not permitted", - "addPlugin/{pluginName}/{methodName}"); - } - String pluginUIContent = plugin; - PluginResponseModel pluginResponseModel = new PluginResponseModel(); - pluginResponseModel.setSuccess(this.getPluginService().addPlugin( - pluginUIContent)); - - return pluginResponseModel; - - } - - @RequestMapping(value = "/deletePlugin/{pluginName}", method = { - RequestMethod.GET, RequestMethod.POST }) - @ResponseBody - public PluginResponseModel deletePlugin( - @PathVariable("pluginName") String pluginName) - throws Bench4QException { - if (!this.checkScope(UserService.SUPER_AUTHENTICATION)) { - throw new Bench4QException(400 + "", "not permitted", - "deletePlugin/{pluginName}"); - } - PluginResponseModel pluginResponseModel = new PluginResponseModel(); - pluginResponseModel.setSuccess(this.getPluginService().deletePlugin( - pluginName)); - return pluginResponseModel; - - } - -} +//package org.bench4q.master.api; +// +//import java.util.List; +// +//import org.apache.log4j.Logger; +//import org.bench4q.master.domain.service.PluginService; +//import org.bench4q.master.domain.service.UserService; +//import org.bench4q.master.exception.Bench4QException; +//import org.bench4q.master.exception.ExceptionLog; +//import org.bench4q.share.models.master.plugin.BehaviorInfoModel; +//import org.bench4q.share.models.master.plugin.PluginResponseModel; +//import org.bench4q.share.models.master.plugin.PluginUIModel; +//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.ResponseBody; +// +//@Controller +//@RequestMapping("/plugin") +//public class PluginController extends BaseController { +// private Logger logger = Logger.getLogger(PluginController.class); +// private PluginService pluginService; +// +// public PluginService getPluginService() { +// return pluginService; +// } +// +// @Autowired +// public void setPluginService(PluginService pluginService) { +// this.pluginService = pluginService; +// } +// +// @RequestMapping(value = "/loadPluginList", method = { RequestMethod.GET, +// RequestMethod.POST }) +// @ResponseBody +// public PluginResponseModel loadPluginUIModels() throws Bench4QException { +// if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) { +// throw new Bench4QException(400 + "", "not permitted", +// "/loadPluginList"); +// } +// PluginResponseModel pluginResponseModel = new PluginResponseModel(); +// try { +// List pluginUIModels = this.getPluginService() +// .loadPluginUIs(); +// if (pluginUIModels == null) { +// pluginResponseModel.setSuccess(false); +// } else { +// pluginResponseModel.setSuccess(true); +// pluginResponseModel.setPluginUIModels(pluginUIModels); +// } +// return pluginResponseModel; +// } catch (Exception e) { +// logger.info(ExceptionLog.getStackTrace(e)); +// pluginResponseModel.setSuccess(false); +// return pluginResponseModel; +// } +// +// } +// +// @RequestMapping("/loadPluginNameList") +// @ResponseBody +// public PluginResponseModel loadPluginList() throws Bench4QException { +// if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) { +// throw new Bench4QException(400 + "", "not permitted", +// "/loadPluginNameList"); +// } +// PluginResponseModel pluginResponseModel = new PluginResponseModel(); +// pluginResponseModel.setPluginList(this.getPluginService() +// .getPluginNameList()); +// +// pluginResponseModel.setSuccess(true); +// return pluginResponseModel; +// } +// +// @RequestMapping(value = "/loadBehaviors/{pluginName}", method = { +// RequestMethod.GET, RequestMethod.POST }) +// @ResponseBody +// public PluginResponseModel getBehaviorsInPlugin( +// @PathVariable("pluginName") String pluginName) +// throws Bench4QException { +// +// if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) { +// throw new Bench4QException(400 + "", "not permitted", +// "/loadBehaviors/{pluginName}"); +// } +// PluginResponseModel pluginResponseModel = new PluginResponseModel(); +// try { +// if (!this.getPluginService().isPluginExist(pluginName)) { +// pluginResponseModel.setSuccess(false); +// pluginResponseModel.setFailMessage("plugin not exist"); +// return pluginResponseModel; +// } +// +// List behaviorInfoModels = this +// .getPluginService().loadBehaviorInfoModels(pluginName); +// if (behaviorInfoModels == null) { +// pluginResponseModel.setFailMessage("no behaviors in plugin"); +// pluginResponseModel.setSuccess(false); +// } +// +// else { +// pluginResponseModel.setSuccess(true); +// pluginResponseModel.setBehaviorInfoModels(behaviorInfoModels); +// } +// +// return pluginResponseModel; +// } catch (Exception e) { +// logger.error(ExceptionLog.getStackTrace(e)); +// pluginResponseModel.setSuccess(false); +// return pluginResponseModel; +// } +// } +// +// @RequestMapping(value = "/addPlugin", method = { RequestMethod.PUT }) +// @ResponseBody +// public PluginResponseModel addPlugin(@RequestBody String plugin) +// throws Bench4QException { +// if (!this.checkScope(UserService.SUPER_AUTHENTICATION)) { +// throw new Bench4QException(400 + "", "not permitted", +// "addPlugin/{pluginName}/{methodName}"); +// } +// String pluginUIContent = plugin; +// PluginResponseModel pluginResponseModel = new PluginResponseModel(); +// pluginResponseModel.setSuccess(this.getPluginService().addPlugin( +// pluginUIContent)); +// +// return pluginResponseModel; +// +// } +// +// @RequestMapping(value = "/deletePlugin/{pluginName}", method = { +// RequestMethod.GET, RequestMethod.POST }) +// @ResponseBody +// public PluginResponseModel deletePlugin( +// @PathVariable("pluginName") String pluginName) +// throws Bench4QException { +// if (!this.checkScope(UserService.SUPER_AUTHENTICATION)) { +// throw new Bench4QException(400 + "", "not permitted", +// "deletePlugin/{pluginName}"); +// } +// PluginResponseModel pluginResponseModel = new PluginResponseModel(); +// pluginResponseModel.setSuccess(this.getPluginService().deletePlugin( +// pluginName)); +// return pluginResponseModel; +// +// } +// +//} diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/BehaviorInfo.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/BehaviorInfo.java index f890793b..7e8feb4a 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/BehaviorInfo.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/BehaviorInfo.java @@ -1,9 +1,12 @@ package org.bench4q.master.domain.entity.plugin; +import java.util.Set; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; import javax.persistence.Table; @Entity @@ -11,6 +14,7 @@ import javax.persistence.Table; public class BehaviorInfo extends ParamsContainer { private String behavoirType; private PluginUI pluginUI; + private Set groups; @Column(name = "behavoirType") public String getBehavoirType() { @@ -20,8 +24,9 @@ public class BehaviorInfo extends ParamsContainer { public void setBehavoirType(String behavoirType) { this.behavoirType = behavoirType; } + @ManyToOne - @JoinColumn(name = "pluginId", nullable = false) + @JoinColumn(name = "pluginUI", nullable = false) public PluginUI getPluginUI() { return pluginUI; } @@ -29,4 +34,14 @@ public class BehaviorInfo extends ParamsContainer { public void setPluginUI(PluginUI pluginUI) { this.pluginUI = pluginUI; } + + @OneToMany(mappedBy = "paramsContainer") + public Set getGroups() { + return groups; + } + + public void setGroups(Set groups) { + this.groups = groups; + } + } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/Group.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/Group.java index ebf7d41d..4866be46 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/Group.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/Group.java @@ -1,24 +1,25 @@ -package org.bench4q.master.domain.entity.plugin; - -import javax.persistence.Entity; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; - -@Entity -@Table(name = "group") -public class Group extends ParamsContainer { - - private ParamsContainer paramsContainer; - - @ManyToOne - @JoinColumn(name = "paramsContainerId", nullable = false) - public ParamsContainer getParamsContainer() { - return paramsContainer; - } - - public void setParamsContainer(ParamsContainer paramsContainer) { - this.paramsContainer = paramsContainer; - } - -} +package org.bench4q.master.domain.entity.plugin; + +import java.util.Set; + +import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "group") +public class Group extends ParamsContainer { + private ParamsContainer paramsContainer; + + @ManyToOne + @JoinColumn(name = "paramContainer", nullable = false) + public ParamsContainer getParamsContainer() { + return paramsContainer; + } + + public void setParamsContainer(ParamsContainer paramsContainer) { + this.paramsContainer = paramsContainer; + } + +} diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/ParamInfo.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/ParamInfo.java index 082ad3f0..f651e00c 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/ParamInfo.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/ParamInfo.java @@ -2,16 +2,18 @@ package org.bench4q.master.domain.entity.plugin; import javax.persistence.CascadeType; import javax.persistence.Column; +import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; -import javax.persistence.MappedSuperclass; import javax.persistence.OneToOne; +import javax.persistence.Table; -@MappedSuperclass +@Entity +@Table(name = "param") public class ParamInfo { private int id; @@ -19,6 +21,7 @@ public class ParamInfo { private String lable; private ParamType paramType; private ParamsContainer paramsContainer; + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", nullable = false) @@ -58,7 +61,6 @@ public class ParamInfo { this.paramType = paramType; } - @ManyToOne @JoinColumn(name = "paramsContainerId", nullable = false) public ParamsContainer getParamsContainer() { diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/ParamType.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/ParamType.java index 7a09c51c..59ed22f1 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/ParamType.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/ParamType.java @@ -11,7 +11,7 @@ import javax.persistence.Table; @Entity @Table(name = "paramType") -@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) +@Inheritance(strategy = InheritanceType.JOINED) public abstract class ParamType { private int id; private String type; @@ -26,7 +26,8 @@ public abstract class ParamType { public void setId(int id) { this.id = id; } - @Column(name="paramType") + + @Column(name = "editorType") public String getType() { return type; } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/ParamsContainer.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/ParamsContainer.java index ee33195b..a3cf7150 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/ParamsContainer.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/ParamsContainer.java @@ -11,17 +11,17 @@ import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; +import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; @Entity -@Table(name = "paramsContainer") -@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) +@Table(name = "paramType") +@Inheritance(strategy = InheritanceType.JOINED) public abstract class ParamsContainer { private int id; private String name; private Set params; - private Set groups; @Id @GeneratedValue(strategy = GenerationType.TABLE) @@ -51,16 +51,6 @@ public abstract class ParamsContainer { public void setParams(Set params) { this.params = params; } - @OneToMany(mappedBy = "paramsContainer", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER) - public Set getGroups() { - return groups; - } - - public void setGroups(Set groups) { - this.groups = groups; - } - - } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/PluginInfo.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/PluginInfo.java index af205e4a..7550969a 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/PluginInfo.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/PluginInfo.java @@ -1,17 +1,22 @@ package org.bench4q.master.domain.entity.plugin; +import java.util.Set; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; import javax.persistence.Table; @Entity @Table(name = "pluginInfo") public class PluginInfo extends ParamsContainer { + private PluginUI pluginUI; + private Set groups; + @ManyToOne - @JoinColumn(name = "pluginId", nullable = false) + @JoinColumn(name = "pluginUI", nullable = false) public PluginUI getPluginUI() { return pluginUI; } @@ -19,4 +24,13 @@ public class PluginInfo extends ParamsContainer { public void setPluginUI(PluginUI pluginUI) { this.pluginUI = pluginUI; } + + @OneToMany(mappedBy = "paramsContainer") + public Set getGroups() { + return groups; + } + + public void setGroups(Set groups) { + this.groups = groups; + } } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/PluginUI.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/PluginUI.java index a099ff81..c4eb64b6 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/PluginUI.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/PluginUI.java @@ -15,10 +15,12 @@ import javax.persistence.OneToMany; import javax.persistence.OneToOne; import javax.persistence.Table; +import jnr.ffi.Struct.int16_t; +import jnr.ffi.types.id_t; + @Entity @Table(name = "pluginUI") public class PluginUI { - private int id; private PluginInfo pluginInfo; private Set behaviorInfos; @@ -36,7 +38,7 @@ public class PluginUI { } @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER) - @JoinColumn(name = "pluginUIId", nullable = false) + @JoinColumn(name = "pluginUI", nullable = false) public PluginInfo getPluginInfo() { return pluginInfo; } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/PluginDomainFactory.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/PluginDomainFactory.java deleted file mode 100644 index 00d2fce2..00000000 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/PluginDomainFactory.java +++ /dev/null @@ -1,207 +0,0 @@ -package org.bench4q.master.domain.factory; - -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -import javax.xml.bind.JAXBException; - -import org.apache.log4j.Logger; -import org.bench4q.master.domain.entity.plugin.BehaviorInfo; -import org.bench4q.master.domain.entity.plugin.CheckBoxType; -import org.bench4q.master.domain.entity.plugin.ChoiceType; -import org.bench4q.master.domain.entity.plugin.ComboType; -import org.bench4q.master.domain.entity.plugin.FieldType; -import org.bench4q.master.domain.entity.plugin.FileType; -import org.bench4q.master.domain.entity.plugin.NFieldType; -import org.bench4q.master.domain.entity.plugin.ParamInfo; -import org.bench4q.master.domain.entity.plugin.ParamType; -import org.bench4q.master.domain.entity.plugin.PluginInfo; -import org.bench4q.master.domain.entity.plugin.PluginUI; -import org.bench4q.master.domain.entity.plugin.RadioButtonType; -import org.bench4q.master.domain.entity.plugin.TableType; -import org.bench4q.master.exception.ExceptionLog; -import org.bench4q.share.models.master.plugin.BehaviorInfoModel; -import org.bench4q.share.models.master.plugin.CheckBoxModel; -import org.bench4q.share.models.master.plugin.ChoiceModel; -import org.bench4q.share.models.master.plugin.ComboModel; -import org.bench4q.share.models.master.plugin.FieldModel; -import org.bench4q.share.models.master.plugin.FileModel; -import org.bench4q.share.models.master.plugin.NFieldModel; -import org.bench4q.share.models.master.plugin.ParamInfoModel; -import org.bench4q.share.models.master.plugin.ParamTypeModel; -import org.bench4q.share.models.master.plugin.PluginInfoModel; -import org.bench4q.share.models.master.plugin.PluginUIModel; -import org.bench4q.share.models.master.plugin.RadioButtonModel; -import org.bench4q.share.models.master.plugin.TableModel; -import org.springframework.stereotype.Component; - -@Component -public class PluginDomainFactory { - - private Logger logger = Logger.getLogger(PluginDomainFactory.class); - - public PluginUIModel createPluginUIModelwithOutBehaviors(PluginUI pluginUI) { - PluginUIModel pluginUIModel = new PluginUIModel(); - pluginUIModel.setPluginInfoModel(createPluginInfoModel(pluginUI - .getPluginInfo())); - pluginUIModel.setCreateTimeDate(pluginUI.getCreateDateTime()); - return pluginUIModel; - } - - private PluginInfoModel createPluginInfoModel(PluginInfo pluginInfo) { - PluginInfoModel pluginInfoModel = new PluginInfoModel(); - pluginInfoModel.setName(pluginInfo.getName()); - pluginInfoModel.setParamInfoModels(createParamInfoModels(pluginInfo - .getPluginParamInfos())); - return pluginInfoModel; - } - - private ParamInfoModel createParamInfoModel(ParamInfo paramInfo) { - ParamInfoModel paramInfoModel = new ParamInfoModel(); - paramInfoModel.setLable(paramInfo.getLable()); - paramInfoModel.setName(paramInfo.getName()); - try { - - ParamTypeModelFactory paramTypeModelFactory = new ParamTypeModelFactory(); - paramInfoModel.setParamTypeModel(paramTypeModelFactory - .createParamModel(paramInfo)); - - } catch (JAXBException e) { - // TODO Auto-generated catch block - logger.info(ExceptionLog.getStackTrace(e)); - return null; - } - return paramInfoModel; - } - - private List createParamInfoModels( - Set paramInfos) { - List paramInfoModels = new LinkedList(); - for (ParamInfo paramInfo : paramInfos) { - ParamInfoModel paramInfoModel = createParamInfoModel(paramInfo); - if (paramInfo == null) { - return null; - } - paramInfoModels.add(paramInfoModel); - } - - return paramInfoModels; - } - - public List createBehaviorInfoModels( - Set behaviorInfos) { - List behaviorInfoModels = new LinkedList(); - for (BehaviorInfo behaviorInfo : behaviorInfos) { - behaviorInfoModels.add(createBehaviorInfoModel(behaviorInfo)); - } - return behaviorInfoModels; - } - - private BehaviorInfoModel createBehaviorInfoModel(BehaviorInfo behaviorInfo) { - BehaviorInfoModel behaviorInfoModel = new BehaviorInfoModel(); - behaviorInfoModel.setName(behaviorInfo.getName()); - behaviorInfoModel.setParamInfoModels(createParamInfoModels(behaviorInfo - .getParams())); - return behaviorInfoModel; - - } - -} - -@Component -class ParamTypeModelFactory { - - public ParamTypeModel createParamModel(ParamInfo paramInfo) - throws JAXBException { - ParamType paramType = paramInfo.getParamType(); - ParamTypeModel paramTypeModel = null; - if (paramType instanceof FieldType) { - paramTypeModel = createFieldModel((FieldType) paramType); - } - - else if (paramType instanceof NFieldType) { - paramTypeModel = createNFieldModel((NFieldType) paramType); - } else if (paramType instanceof TableType) { - paramTypeModel = createTableModel((TableType) paramType); - } else if (paramType instanceof CheckBoxType) { - paramTypeModel = createCheckBoxModel((CheckBoxType) paramType); - } else if (paramType instanceof ComboType) { - paramTypeModel = createComboModel((ComboType) paramType); - } else if (paramType instanceof RadioButtonType) { - paramTypeModel = createRadioButton((RadioButtonType) paramType); - } else if (paramType instanceof FileType) { - paramTypeModel = createFileModel((FileType) paramType); - } - paramTypeModel.setType(paramType.getType()); - return paramTypeModel; - } - - private FieldModel createFieldModel(FieldType fieldType) { - FieldModel fieldModel = new FieldModel(); - fieldModel.setSize(fieldType.getSize()); - fieldModel.setText(fieldType.getText()); - return fieldModel; - - } - - private NFieldModel createNFieldModel(NFieldType nFieldType) { - NFieldModel nFieldModel = new NFieldModel(); - nFieldModel.setSize(nFieldType.getSize()); - nFieldModel.setText(nFieldType.getText()); - return nFieldModel; - - } - - private TableModel createTableModel(TableType tableType) { - TableModel tableModel = new TableModel(); - tableModel.setCols(tableType.getCols()); - return tableModel; - } - - private CheckBoxModel createCheckBoxModel(CheckBoxType checkBoxType) { - CheckBoxModel checkBoxModel = new CheckBoxModel(); - checkBoxModel.setChoiceModels(createChoiceModels(checkBoxType - .getChoiceList())); - return checkBoxModel; - - } - - private ComboModel createComboModel(ComboType comboType) { - ComboModel comboModel = new ComboModel(); - comboModel - .setChoiceModels(createChoiceModels(comboType.getChoiceList())); - return comboModel; - } - - private RadioButtonModel createRadioButton(RadioButtonType radioButtonType) { - RadioButtonModel radioButtonModel = new RadioButtonModel(); - radioButtonModel.setChoiceModels(createChoiceModels(radioButtonType - .getChoices())); - return radioButtonModel; - - } - - private FileModel createFileModel(FileType fileType) { - FileModel fileModel = new FileModel(); - fileModel.setText(fileType.getText()); - return fileModel; - - } - - private List createChoiceModels(List choiceTypes) { - List choiceModels = new LinkedList(); - for (ChoiceType choiceType : choiceTypes) { - choiceModels.add(createChoiceModel(choiceType)); - } - return choiceModels; - } - - private ChoiceModel createChoiceModel(ChoiceType choiceType) { - ChoiceModel choiceModel = new ChoiceModel(); - choiceModel.setDefaultValue(choiceType.isDefaultValue()); - choiceModel.setValue(choiceType.getValue()); - return choiceModel; - - } -} \ No newline at end of file diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/PluginEntityFactory.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/PluginEntityFactory.java index f62189af..f58090c3 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/PluginEntityFactory.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/PluginEntityFactory.java @@ -35,16 +35,26 @@ import org.springframework.stereotype.Component; @Component public class PluginEntityFactory { private Logger logger = Logger.getLogger(PluginEntityFactory.class); + private final String[] behaviorTypes = { "behavior", "timer", "control" }; + + private Document getDocument(String pluginUI) { + try { + return DocumentHelper.parseText(pluginUI); + + } catch (DocumentException e) { + logger.info(ExceptionLog.getStackTrace(e)); + return null; + } + } public PluginUI createPluginUIWithOutId(String pluginUIContent) { Element root = getDocument(pluginUIContent).getRootElement(); PluginUI pluginUI = new PluginUI(); - String[] behaviorNames = { "behavior", "timer", "control" }; - pluginUI.setPluginInfo(createPluginInfoWithOutId(XmlParseHelper - .getOneChildElementByName(root, "plugin"))); - + pluginUI.setPluginInfo(createPluginInfoWithOutId( + XmlParseHelper.getOneChildElementByName(root, "plugin"), + pluginUI)); pluginUI.setBehaviorInfos(createBehaviorInfosWithOutId( - XmlParseHelper.getChildElements(root, behaviorNames), pluginUI)); + XmlParseHelper.getChildElements(root, behaviorTypes), pluginUI)); pluginUI.setCreateDateTime(new Date()); return pluginUI; } @@ -58,7 +68,7 @@ public class PluginEntityFactory { return behaviorInfos; } - private ParamsContainer createBehaviorInfoWithOutId(Element element, + private BehaviorInfo createBehaviorInfoWithOutId(Element element, PluginUI pluginUI) { BehaviorInfo behaviorInfo = new BehaviorInfo(); behaviorInfo.setBehavoirType(element.getName()); @@ -66,63 +76,33 @@ public class PluginEntityFactory { behaviorInfo.setPluginUI(pluginUI); Element paramsElement = XmlParseHelper.getOneChildElementByName( element, "params"); - behaviorInfo.setParams(createBehaviorParamInfos( - XmlParseHelper.getChildElements(paramsElement), behaviorInfo)); + behaviorInfo.setParams(createParamInfos( + XmlParseHelper.getChildElementsByName(paramsElement, "params"), + behaviorInfo)); + behaviorInfo.setGroups(createGroups( + XmlParseHelper.getChildElementsByName(paramsElement, "group"), + behaviorInfo)); return behaviorInfo; } - // combine this code with the pluginParamInfo - - private Set createBehaviorParamInfos( - List elements, BehaviorInfo behaviorInfo) { - Set paramInfos = new HashSet(); - for (Element element : elements) { - BehaviorParamInfo behaviorParamInfo = createBehaviorParamInfo( - element, behaviorInfo); - if (behaviorParamInfo != null) - paramInfos.add(behaviorParamInfo); - } - if (paramInfos.size() == 0) - paramInfos = null; - return paramInfos; - } - - private Document getDocument(String pluginUI) { - try { - return DocumentHelper.parseText(pluginUI); - - } catch (DocumentException e) { - logger.info(ExceptionLog.getStackTrace(e)); - return null; - } - } - - private PluginInfo createPluginInfoWithOutId(Element element) { + private PluginInfo createPluginInfoWithOutId(Element element, + PluginUI pluginUI) { PluginInfo pluginInfo = new PluginInfo(); pluginInfo.setName(XmlParseHelper.getAttribute(element, "name")); + pluginInfo.setPluginUI(pluginUI); Element paramsElement = XmlParseHelper.getOneChildElementByName( element, "params"); - pluginInfo.setPluginParamInfos(createPluginParamInfos( - XmlParseHelper.getChildElements(paramsElement), pluginInfo)); + pluginInfo.setGroups(createGroups( + XmlParseHelper.getChildElementsByName(paramsElement, "group"), + pluginInfo)); + pluginInfo.setParams(createParamInfos( + XmlParseHelper.getChildElementsByName(paramsElement, "param"), + pluginInfo)); return pluginInfo; } - private Set createPluginParamInfos(List elements, - PluginInfo pluginInfo) { - Set paramInfos = new HashSet(); - for (Element element : elements) { - PluginParamInfo pluginParamInfo = createPluginParamInfoWithOutId( - element, pluginInfo); - if (pluginParamInfo != null) - paramInfos.add(pluginParamInfo); - } - if (paramInfos.size() == 0) - paramInfos = null; - return paramInfos; - } - private ParamInfo createParamInfoWithOutId(Element paramElement, ParamsContainer paramsContainer) { if (!paramElement.getName().equals("param")) { @@ -142,12 +122,33 @@ public class PluginEntityFactory { return paramInfo; } - private List createParamInfos(List paramElements, - ParamsContainer paramsContainer) { - if (paramElements == null) { + private Group createGroup(Element groupElement, + ParamsContainer fatherParamsContainer) { + if (!groupElement.getName().equals("group")) { + logger.info("element is not a group:" + groupElement.getName()); return null; } - List paramInfos = new LinkedList(); + Group paramsContainer = new Group(); + paramsContainer.setName(XmlParseHelper.getAttribute(groupElement, + "name")); + + List paramElements = XmlParseHelper.getChildElementsByName( + groupElement, "param"); + + if (paramElements.size() > 0) { + paramsContainer.setParams(createParamInfos(paramElements, + paramsContainer)); + } + paramsContainer.setParamsContainer(paramsContainer); + return paramsContainer; + } + + private Set createParamInfos(List paramElements, + ParamsContainer paramsContainer) { + if (paramElements.size() == 0) { + return null; + } + Set paramInfos = new HashSet(); for (Element paramElement : paramElements) { paramInfos.add(createParamInfoWithOutId(paramElement, paramsContainer)); @@ -155,21 +156,17 @@ public class PluginEntityFactory { return paramInfos; } - private Group createGroup(Element groupElement, - ParamsContainer paramsContainer) { - if (!groupElement.getName().equals("group")) { - logger.info("element is not a group:" + groupElement.getName()); + private Set createGroups( + + List groupElements, ParamsContainer baseContainer) { + if (groupElements.size() == 0) { return null; } - Group group = new Group(); - group.setName(XmlParseHelper.getAttribute(groupElement, "name")); - List groupElements = XmlParseHelper.getChildElementsByName( - groupElement, "group"); - List paramElements = XmlParseHelper.getChildElementsByName( - groupElement, "param"); -I - group.setParamsContainer(paramsContainer); - return group; + Set groups = new HashSet(); + for (Element element : groupElements) { + groups.add(createGroup(element, baseContainer)); + } + return groups; } private static class ParamTypeFactory { diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/TestPlanFactory.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/TestPlanFactory.java index 1e96c202..e1028080 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/TestPlanFactory.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/TestPlanFactory.java @@ -261,28 +261,6 @@ public class TestPlanFactory { } } - // TODO: remove this, because it's has no use - // public List createRunningAgentDBsWithoutId( - // List runningAgents, - // TestPlanScript testPlanScript) { - // // TODO: see this kind of map RunningAgent to agent, maybe there's a - // // problem - // List runningAgentDBs = new ArrayList(); - // for (RunningAgentInterface runningAgent : runningAgents) { - // RunningAgentDB runningAgentDB = new RunningAgentDB(); - // runningAgentDB.setAgent(this.getAgentRepository().getAgentBy( - // runningAgent.getAgent().getHostName())); - // runningAgentDB.setAgentRunId(runningAgent.getAgentRunId()); - // runningAgentDB.setLoadInUse(runningAgent.getLoadInUse()); - // runningAgentDB.setAgentMessenger(this.getAgentMessenger()); - // runningAgentDB.setScript(this.getScriptService().getScript( - // runningAgent.getScriptId())); - // runningAgentDB.setTestPlanScript(testPlanScript); - // runningAgentDBs.add(runningAgentDB); - // } - // return runningAgentDBs; - // } - private void convertToDomain(Monitor monitor) { monitor.setTestPlanFactory(this); } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/PluginService.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/PluginService.java index 969efc27..42b341d0 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/PluginService.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/PluginService.java @@ -7,7 +7,6 @@ import java.util.Set; import org.bench4q.master.domain.repository.PluginRepository; import org.bench4q.master.domain.entity.plugin.BehaviorInfo; import org.bench4q.master.domain.entity.plugin.PluginUI; -import org.bench4q.master.domain.factory.PluginDomainFactory; import org.bench4q.master.domain.factory.PluginEntityFactory; import org.bench4q.share.models.master.plugin.BehaviorInfoModel; import org.bench4q.share.models.master.plugin.PluginUIModel; @@ -18,7 +17,7 @@ import org.springframework.stereotype.Component; public class PluginService { private PluginRepository pluginRepository; private PluginEntityFactory pluginEntityFactory; - private PluginDomainFactory pluginDomainFactory; +// private PluginDomainFactory pluginDomainFactory; public PluginRepository getPluginRepository() { return pluginRepository; @@ -38,14 +37,14 @@ public class PluginService { this.pluginEntityFactory = pluginEntityFactory; } - public PluginDomainFactory getPluginDomainFactory() { - return pluginDomainFactory; - } - - @Autowired - public void setPluginDomainFactory(PluginDomainFactory pluginDomainFactory) { - this.pluginDomainFactory = pluginDomainFactory; - } +// public PluginDomainFactory getPluginDomainFactory() { +// return pluginDomainFactory; +// } +// +// @Autowired +// public void setPluginDomainFactory(PluginDomainFactory pluginDomainFactory) { +// this.pluginDomainFactory = pluginDomainFactory; +// } public boolean addPlugin(String pluginUIContent) { return this.getPluginRepository().attatch( @@ -57,41 +56,41 @@ public class PluginService { return this.getPluginRepository().detach(pluginName); } - public List getPluginNameList() { - List pluginUIModels = this.loadPluginUIs(); - if (pluginUIModels == null) - return null; - List pluginNameList = new LinkedList(); - for (PluginUIModel pluginUIModel : this.loadPluginUIs()) { - pluginNameList.add(pluginUIModel.getPluginInfoModel().getName()); - } - return pluginNameList; +// public List getPluginNameList() { +// List pluginUIModels = this.loadPluginUIs(); +// if (pluginUIModels == null) +// return null; +// List pluginNameList = new LinkedList(); +// for (PluginUIModel pluginUIModel : this.loadPluginUIs()) { +// pluginNameList.add(pluginUIModel.getPluginInfoModel().getName()); +// } +// return pluginNameList; +// +// } - } - - public List loadPluginUIs() { - List pluginUIs = this.getPluginRepository().loadPlugins(); - if (pluginUIs == null) - return null; - List pluginUIModels = new LinkedList(); - for (PluginUI pluginUI : pluginUIs) { - pluginUIModels.add(this.getPluginDomainFactory() - .createPluginUIModelwithOutBehaviors(pluginUI)); - } - - return pluginUIModels; - } - - public List loadBehaviorInfoModels(String pluginName) { - - Set behaviorInfos = this.getPluginRepository() - .loadBehaviorInfos(pluginName); - if (behaviorInfos == null) - return null; - return this.getPluginDomainFactory().createBehaviorInfoModels( - this.getPluginRepository().loadBehaviorInfos(pluginName)); - - } +// public List loadPluginUIs() { +// List pluginUIs = this.getPluginRepository().loadPlugins(); +// if (pluginUIs == null) +// return null; +// List pluginUIModels = new LinkedList(); +// for (PluginUI pluginUI : pluginUIs) { +// pluginUIModels.add(this.getPluginDomainFactory() +// .createPluginUIModelwithOutBehaviors(pluginUI)); +// } +// +// return pluginUIModels; +// } +// +// public List loadBehaviorInfoModels(String pluginName) { +// +// Set behaviorInfos = this.getPluginRepository() +// .loadBehaviorInfos(pluginName); +// if (behaviorInfos == null) +// return null; +// return this.getPluginDomainFactory().createBehaviorInfoModels( +// this.getPluginRepository().loadBehaviorInfos(pluginName)); +// +// } public boolean isPluginExist(String pluginName) { return this.getPluginRepository().isExist(pluginName); diff --git a/Bench4Q-Master/src/main/resources/org/bench4q/master/config/hibernate.cfg.xml b/Bench4Q-Master/src/main/resources/org/bench4q/master/config/hibernate.cfg.xml index a39c503d..3ffa486d 100644 --- a/Bench4Q-Master/src/main/resources/org/bench4q/master/config/hibernate.cfg.xml +++ b/Bench4Q-Master/src/main/resources/org/bench4q/master/config/hibernate.cfg.xml @@ -28,12 +28,13 @@ + + + - - diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/test/controller/PluginControllerTest.java b/Bench4Q-Master/src/test/java/org/bench4q/master/test/controller/PluginControllerTest.java index 4f393c41..573f3cec 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/test/controller/PluginControllerTest.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/test/controller/PluginControllerTest.java @@ -83,57 +83,57 @@ public class PluginControllerTest extends TestBase { this.getPluginService().deletePlugin(pluginName); } - @Test - public void testLoadPluginNameList() throws JAXBException, IOException { - this.getPluginService().deletePlugin(pluginName); - String url = URLSTRING + "/loadPluginNameList"; - int insertBefore = this.getPluginService().loadPluginUIs().size(); - this.test_PluginHelper.addPlugin("ui.xml", pluginService, pluginName); - HttpResponse httpResponse = this.httpRequester.sendPost(url, null, - makeAccessTockenMap(this.getAccessTocken())); - PluginResponseModel pluginResponseModel = (PluginResponseModel) MarshalHelper - .tryUnmarshal(PluginResponseModel.class, - httpResponse.getContent()); - assertNotNull(pluginResponseModel); - Assert.assertTrue(pluginResponseModel.isSuccess()); - Assert.assertTrue(pluginResponseModel.getPluginList().size() > 0); - assertEquals(insertBefore + 1, pluginResponseModel.getPluginList() - .size()); - this.getPluginService().deletePlugin(pluginName); - } - - @Test - public void testLoadPluginList() throws IOException, JAXBException { - this.getPluginService().deletePlugin(pluginName); - int insertBefore = this.getPluginService().loadPluginUIs().size(); - this.getTest_PluginHelper().addPlugin(fileName, - this.getPluginService(), pluginName); - String url = URLSTRING + "/loadPluginList"; - HttpResponse httpResponse = this.httpRequester.sendPost(url, null, - makeAccessTockenMap(this.getAccessTocken())); - PluginResponseModel pluginResponseModel = (PluginResponseModel) MarshalHelper - .tryUnmarshal(PluginResponseModel.class, - httpResponse.getContent()); - assertNotNull(pluginResponseModel); - assertEquals(insertBefore + 1, pluginResponseModel.getPluginUIModels() - .size()); - this.getPluginService().deletePlugin(pluginName); - } - - @Test - public void testDeletePlugin() throws IOException { - this.getPluginService().deletePlugin(pluginName); - this.getTest_PluginHelper().addPlugin(fileName, - this.getPluginService(), pluginName); - String url = URLSTRING + "/deletePlugin" + "/" + this.pluginName; - HttpResponse httpResponse = this.httpRequester.sendPost(url, null, - makeAccessTockenMap(this.getAccessTocken())); - PluginResponseModel pluginResponseModel = (PluginResponseModel) MarshalHelper - .tryUnmarshal(PluginResponseModel.class, - httpResponse.getContent()); - assertNotNull(pluginResponseModel); - assertTrue(pluginResponseModel.isSuccess()); - } +// @Test +// public void testLoadPluginNameList() throws JAXBException, IOException { +// this.getPluginService().deletePlugin(pluginName); +// String url = URLSTRING + "/loadPluginNameList"; +// int insertBefore = this.getPluginService().loadPluginUIs().size(); +// this.test_PluginHelper.addPlugin("ui.xml", pluginService, pluginName); +// HttpResponse httpResponse = this.httpRequester.sendPost(url, null, +// makeAccessTockenMap(this.getAccessTocken())); +// PluginResponseModel pluginResponseModel = (PluginResponseModel) MarshalHelper +// .tryUnmarshal(PluginResponseModel.class, +// httpResponse.getContent()); +// assertNotNull(pluginResponseModel); +// Assert.assertTrue(pluginResponseModel.isSuccess()); +// Assert.assertTrue(pluginResponseModel.getPluginList().size() > 0); +// assertEquals(insertBefore + 1, pluginResponseModel.getPluginList() +// .size()); +// this.getPluginService().deletePlugin(pluginName); +// } +// +// @Test +// public void testLoadPluginList() throws IOException, JAXBException { +// this.getPluginService().deletePlugin(pluginName); +// int insertBefore = this.getPluginService().loadPluginUIs().size(); +// this.getTest_PluginHelper().addPlugin(fileName, +// this.getPluginService(), pluginName); +// String url = URLSTRING + "/loadPluginList"; +// HttpResponse httpResponse = this.httpRequester.sendPost(url, null, +// makeAccessTockenMap(this.getAccessTocken())); +// PluginResponseModel pluginResponseModel = (PluginResponseModel) MarshalHelper +// .tryUnmarshal(PluginResponseModel.class, +// httpResponse.getContent()); +// assertNotNull(pluginResponseModel); +// assertEquals(insertBefore + 1, pluginResponseModel.getPluginUIModels() +// .size()); +// this.getPluginService().deletePlugin(pluginName); +// } +// +// @Test +// public void testDeletePlugin() throws IOException { +// this.getPluginService().deletePlugin(pluginName); +// this.getTest_PluginHelper().addPlugin(fileName, +// this.getPluginService(), pluginName); +// String url = URLSTRING + "/deletePlugin" + "/" + this.pluginName; +// HttpResponse httpResponse = this.httpRequester.sendPost(url, null, +// makeAccessTockenMap(this.getAccessTocken())); +// PluginResponseModel pluginResponseModel = (PluginResponseModel) MarshalHelper +// .tryUnmarshal(PluginResponseModel.class, +// httpResponse.getContent()); +// assertNotNull(pluginResponseModel); +// assertTrue(pluginResponseModel.isSuccess()); +// } @Test public void testGetBehaviors() throws IOException, JAXBException { diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/test/factory/Test_PluginDomainFactory.java b/Bench4Q-Master/src/test/java/org/bench4q/master/test/factory/Test_PluginDomainFactory.java index 2b3cc367..beeab9ef 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/test/factory/Test_PluginDomainFactory.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/test/factory/Test_PluginDomainFactory.java @@ -1,92 +1,92 @@ -package org.bench4q.master.test.factory; - -import static org.junit.Assert.*; - -import java.util.Set; - -import javax.xml.bind.JAXBException; -import org.bench4q.master.domain.entity.plugin.BehaviorInfo; -import org.bench4q.master.domain.entity.plugin.PluginUI; -import org.bench4q.master.domain.factory.PluginDomainFactory; -import org.bench4q.master.domain.repository.PluginRepository; -import org.bench4q.master.test.testHelper.Test_PluginHelper; -import org.bench4q.share.models.master.plugin.PluginUIModel; -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; - - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = { "classpath:service-test-context.xml" }) -public class Test_PluginDomainFactory extends Test_PluginHelper { - private PluginDomainFactory pluginDomainFactory; - private PluginRepository pluginRepository; - private String pluginName; - - public PluginDomainFactory getPluginDomainFactory() { - return pluginDomainFactory; - } - - @Autowired - public void setPluginDomainFactory(PluginDomainFactory pluginDomainFactory) { - this.pluginDomainFactory = pluginDomainFactory; - } - - public PluginRepository getPluginRepository() { - return pluginRepository; - } - - @Autowired - public void setPluginRepository(PluginRepository pluginRepository) { - this.pluginRepository = pluginRepository; - } - - @Before - public void setUp() { - this.pluginName = addPlugin("ui.xml", pluginRepository); - } - - @After - public void clear() { - - } - - @Test - public void test_createPluginUIModel() { - assertNotNull(pluginName); - PluginUI pluginUI = this.getPluginRepository().getPluginUI(pluginName); - - PluginUIModel pluginUIModel = this.getPluginDomainFactory() - .createPluginUIModelwithOutBehaviors(pluginUI); - assertNotNull(pluginUIModel); - assertNull(pluginUIModel.getBehaviorInfos()); - assertEquals(7, pluginUIModel.getPluginInfoModel().getParamInfoModels() - .size()); - - } - - @Test - public void test_createParamInfoModel() throws JAXBException { - assertNotNull(pluginName); - PluginUI pluginUI = this.getPluginRepository().getPluginUI(pluginName); - - PluginUIModel pluginUIModel = this.getPluginDomainFactory() - .createPluginUIModelwithOutBehaviors(pluginUI); - assertNotNull(pluginUIModel); - } - - @Test - public void test_CreateBehaviorModels() { - assertNotNull(pluginName); - Set behaviorInfos = this.getPluginRepository() - .loadBehaviorInfos(pluginName); - assertNotNull(behaviorInfos); - assertTrue(behaviorInfos.size() > 0); - assertEquals(2, behaviorInfos.size()); - } - -} +//package org.bench4q.master.test.factory; +// +//import static org.junit.Assert.*; +// +//import java.util.Set; +// +//import javax.xml.bind.JAXBException; +//import org.bench4q.master.domain.entity.plugin.BehaviorInfo; +//import org.bench4q.master.domain.entity.plugin.PluginUI; +//import org.bench4q.master.domain.factory.PluginDomainFactory; +//import org.bench4q.master.domain.repository.PluginRepository; +//import org.bench4q.master.test.testHelper.Test_PluginHelper; +//import org.bench4q.share.models.master.plugin.PluginUIModel; +//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; +// +// +//@RunWith(SpringJUnit4ClassRunner.class) +//@ContextConfiguration(locations = { "classpath:service-test-context.xml" }) +//public class Test_PluginDomainFactory extends Test_PluginHelper { +// private PluginDomainFactory pluginDomainFactory; +// private PluginRepository pluginRepository; +// private String pluginName; +// +// public PluginDomainFactory getPluginDomainFactory() { +// return pluginDomainFactory; +// } +// +// @Autowired +// public void setPluginDomainFactory(PluginDomainFactory pluginDomainFactory) { +// this.pluginDomainFactory = pluginDomainFactory; +// } +// +// public PluginRepository getPluginRepository() { +// return pluginRepository; +// } +// +// @Autowired +// public void setPluginRepository(PluginRepository pluginRepository) { +// this.pluginRepository = pluginRepository; +// } +// +// @Before +// public void setUp() { +// this.pluginName = addPlugin("ui.xml", pluginRepository); +// } +// +// @After +// public void clear() { +// +// } +// +// @Test +// public void test_createPluginUIModel() { +// assertNotNull(pluginName); +// PluginUI pluginUI = this.getPluginRepository().getPluginUI(pluginName); +// +// PluginUIModel pluginUIModel = this.getPluginDomainFactory() +// .createPluginUIModelwithOutBehaviors(pluginUI); +// assertNotNull(pluginUIModel); +// assertNull(pluginUIModel.getBehaviorInfos()); +// assertEquals(7, pluginUIModel.getPluginInfoModel().getParamInfoModels() +// .size()); +// +// } +// +// @Test +// public void test_createParamInfoModel() throws JAXBException { +// assertNotNull(pluginName); +// PluginUI pluginUI = this.getPluginRepository().getPluginUI(pluginName); +// +// PluginUIModel pluginUIModel = this.getPluginDomainFactory() +// .createPluginUIModelwithOutBehaviors(pluginUI); +// assertNotNull(pluginUIModel); +// } +// +// @Test +// public void test_CreateBehaviorModels() { +// assertNotNull(pluginName); +// Set behaviorInfos = this.getPluginRepository() +// .loadBehaviorInfos(pluginName); +// assertNotNull(behaviorInfos); +// assertTrue(behaviorInfos.size() > 0); +// assertEquals(2, behaviorInfos.size()); +// } +// +//} diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/test/factory/Test_PluginEntityFactory.java b/Bench4Q-Master/src/test/java/org/bench4q/master/test/factory/Test_PluginEntityFactory.java index 5c96bf29..4895765e 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/test/factory/Test_PluginEntityFactory.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/test/factory/Test_PluginEntityFactory.java @@ -9,8 +9,8 @@ import java.util.Set; import org.apache.commons.io.FileUtils; import org.bench4q.master.domain.entity.plugin.BehaviorInfo; import org.bench4q.master.domain.entity.plugin.FieldType; +import org.bench4q.master.domain.entity.plugin.ParamInfo; import org.bench4q.master.domain.entity.plugin.PluginInfo; -import org.bench4q.master.domain.entity.plugin.PluginParamInfo; import org.bench4q.master.domain.entity.plugin.PluginUI; import org.bench4q.master.domain.factory.PluginEntityFactory; import org.junit.Test; @@ -48,23 +48,23 @@ public class Test_PluginEntityFactory { assertNotNull(pluginUI.getBehaviorInfos()); assertNotNull(pluginUI.getPluginInfo()); PluginInfo pluginInfo = pluginUI.getPluginInfo(); - assertNotNull(pluginInfo.getPluginParamInfos()); - assertEquals(pluginInfo.getPluginParamInfos().size(), 7); - Set pluginParamInfos = pluginInfo - .getPluginParamInfos(); + assertNotNull(pluginInfo.getPluginUI()); + assertEquals(pluginInfo.getParams().size(), 7); + Set pluginParamInfos = pluginInfo.getParams(); FieldType fieldType = null; - for (PluginParamInfo pluginParamInfo : pluginParamInfos) { + for (ParamInfo pluginParamInfo : pluginParamInfos) { if (pluginParamInfo.getParamType() instanceof FieldType) fieldType = (FieldType) pluginParamInfo.getParamType(); } assertTrue(fieldType.getSize() == 7); assertEquals(2, pluginUI.getBehaviorInfos().size()); - int timerCount=0; - for( BehaviorInfo behaviorInfo:pluginUI.getBehaviorInfos()){ - if(behaviorInfo.getBehavoirType().equals("timer")) + int timerCount = 0; + System.out.println(pluginUI.getBehaviorInfos().size()); + for (BehaviorInfo behaviorInfo : pluginUI.getBehaviorInfos()) { + if (behaviorInfo.getBehavoirType().equals("timer")) timerCount++; } assertEquals(1, timerCount); - + } } diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/test/service/Test_PluginService.java b/Bench4Q-Master/src/test/java/org/bench4q/master/test/service/Test_PluginService.java index 0e231f79..723cf965 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/test/service/Test_PluginService.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/test/service/Test_PluginService.java @@ -70,22 +70,22 @@ public class Test_PluginService extends Test_PluginHelper { } - @Test - public void test_loadPlugins() { - int insertBefore = this.getPluginService().loadPluginUIs().size(); - addPluginByString(); - assertEquals(insertBefore + 1, this.getPluginService().loadPluginUIs() - .size()); - this.getPluginService().deletePlugin(pluginName); - } - - @Test - public void test_loadBehaviors() { - addPluginByString(); - assertEquals(2, - this.getPluginService().loadBehaviorInfoModels(pluginName) - .size()); - } +// @Test +// public void test_loadPlugins() { +// int insertBefore = this.getPluginService().loadPluginUIs().size(); +// addPluginByString(); +// assertEquals(insertBefore + 1, this.getPluginService().loadPluginUIs() +// .size()); +// this.getPluginService().deletePlugin(pluginName); +// } +// +// @Test +// public void test_loadBehaviors() { +// addPluginByString(); +// assertEquals(2, +// this.getPluginService().loadBehaviorInfoModels(pluginName) +// .size()); +// } private void assertTure(boolean deletePlugin) { diff --git a/Bench4Q-Master/src/test/resources/repository-test-context.xml b/Bench4Q-Master/src/test/resources/repository-test-context.xml index e80efd18..6478e603 100644 --- a/Bench4Q-Master/src/test/resources/repository-test-context.xml +++ b/Bench4Q-Master/src/test/resources/repository-test-context.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file