From 60726bfe3b75675b8838edf016da4a78e9e88ec6 Mon Sep 17 00:00:00 2001 From: fanfuxiaoran <495538672@qq.com> Date: Wed, 16 Apr 2014 15:05:09 +0800 Subject: [PATCH] refactor the plugin manange :now add plugin ui of xml is able --- Bench4Q-Master/pluginUI/pluginUITest.xml | 18 ++ Bench4Q-Master/pluginUI/test.xml | 42 +++ Bench4Q-Master/pluginUI/ui.dtd | 37 +++ Bench4Q-Master/pluginUI/ui.xml | 42 +++ Bench4Q-Master/pom.xml | 6 + .../bench4q/master/api/PluginController.java | 78 +---- .../plugin/{Method.java => BehaviorInfo.java} | 127 ++++---- .../entity/plugin/BehaviorParamInfo.java | 22 ++ .../domain/entity/plugin/CheckBoxType.java | 25 ++ .../domain/entity/plugin/ChoiceType.java | 44 +++ .../domain/entity/plugin/ComboType.java | 26 ++ .../domain/entity/plugin/FieldType.java | 31 ++ .../domain/entity/plugin/MethodParam.java | 105 ------ .../entity/plugin/MethodParamProperty.java | 60 ---- .../domain/entity/plugin/NFieldType.java | 31 ++ .../domain/entity/plugin/ParamInfo.java | 60 ++++ .../domain/entity/plugin/ParamType.java | 22 +- .../plugin/{Plugin.java => PluginInfo.java} | 15 +- .../domain/entity/plugin/PluginParamInfo.java | 21 ++ .../master/domain/entity/plugin/PluginUI.java | 55 ++++ .../domain/entity/plugin/RadioButtonType.java | 25 ++ .../domain/entity/plugin/TableType.java | 20 ++ .../domain/factory/PluginDomainFactory.java | 182 +++++++++++ .../domain/factory/PluginEntityFactory.java | 298 ++++++++++++++++++ .../master/domain/factory/PluginFactory.java | 148 --------- .../domain/repository/PluginRepository.java | 157 ++++----- .../domain/repository/TestPlanRepository.java | 20 -- .../master/domain/service/PluginService.java | 103 +----- .../bench4q/master/helper/SessionHelper.java | 4 - .../bench4q/master/config/hibernate.cfg.xml | 18 +- .../java/TestHelper/Test_PluginHelper.java | 21 ++ .../java/TestHelper/Test_PlunginHelper.java | 59 ---- .../test/controller/PluginControllerTest.java | 115 +++---- .../domain/testPlan/Test_TestResultSave.java | 2 - .../factory/Test_PluginEntityFactory.java | 63 ++++ .../repository/Test_PluginRepository.java | 97 +++--- .../test/service/Test_PluginService.java | 192 +++++------ 37 files changed, 1437 insertions(+), 954 deletions(-) create mode 100644 Bench4Q-Master/pluginUI/pluginUITest.xml create mode 100644 Bench4Q-Master/pluginUI/test.xml create mode 100644 Bench4Q-Master/pluginUI/ui.dtd create mode 100644 Bench4Q-Master/pluginUI/ui.xml rename Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/{Method.java => BehaviorInfo.java} (55%) create mode 100644 Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/BehaviorParamInfo.java create mode 100644 Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/CheckBoxType.java create mode 100644 Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/ChoiceType.java create mode 100644 Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/ComboType.java create mode 100644 Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/FieldType.java delete mode 100644 Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/MethodParam.java delete mode 100644 Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/MethodParamProperty.java create mode 100644 Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/NFieldType.java create mode 100644 Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/ParamInfo.java rename Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/{Plugin.java => PluginInfo.java} (67%) create mode 100644 Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/PluginParamInfo.java create mode 100644 Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/PluginUI.java create mode 100644 Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/RadioButtonType.java create mode 100644 Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/TableType.java create mode 100644 Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/PluginDomainFactory.java create mode 100644 Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/PluginEntityFactory.java delete mode 100644 Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/PluginFactory.java create mode 100644 Bench4Q-Master/src/test/java/TestHelper/Test_PluginHelper.java delete mode 100644 Bench4Q-Master/src/test/java/TestHelper/Test_PlunginHelper.java create mode 100644 Bench4Q-Master/src/test/java/org/bench4q/master/test/factory/Test_PluginEntityFactory.java diff --git a/Bench4Q-Master/pluginUI/pluginUITest.xml b/Bench4Q-Master/pluginUI/pluginUITest.xml new file mode 100644 index 00000000..2d69b410 --- /dev/null +++ b/Bench4Q-Master/pluginUI/pluginUITest.xml @@ -0,0 +1,18 @@ + + + + + reset + + + next + + + CsvProvider + + + The name of the input file(Required) + fileName + + + diff --git a/Bench4Q-Master/pluginUI/test.xml b/Bench4Q-Master/pluginUI/test.xml new file mode 100644 index 00000000..269765f1 --- /dev/null +++ b/Bench4Q-Master/pluginUI/test.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Bench4Q-Master/pluginUI/ui.dtd b/Bench4Q-Master/pluginUI/ui.dtd new file mode 100644 index 00000000..7242423d --- /dev/null +++ b/Bench4Q-Master/pluginUI/ui.dtd @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/Bench4Q-Master/pluginUI/ui.xml b/Bench4Q-Master/pluginUI/ui.xml new file mode 100644 index 00000000..fb73c343 --- /dev/null +++ b/Bench4Q-Master/pluginUI/ui.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Bench4Q-Master/pom.xml b/Bench4Q-Master/pom.xml index 6f5a7b9b..191b5459 100644 --- a/Bench4Q-Master/pom.xml +++ b/Bench4Q-Master/pom.xml @@ -22,6 +22,12 @@ 4.11 test + + dom4j + dom4j + 1.6.1 + + org.springframework spring-webmvc 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 c47f2b8a..6d7afdc8 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,19 +1,20 @@ package org.bench4q.master.api; + 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.PluginGUI; import org.bench4q.share.models.master.plugin.PluginResponseModel; 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; +import org.springframework.web.multipart.commons.CommonsMultipartFile; @Controller @RequestMapping("/plugin") @@ -59,8 +60,8 @@ public class PluginController extends BaseController { PluginResponseModel pluginResponseModel = new PluginResponseModel(); try { - pluginResponseModel.setMethodModels(this.getPluginService() - .getMethodsInPlugin(pluginName)); + // pluginResponseModel.setMethodModels(this.getPluginService() + // .getMethodsInPlugin(pluginName)); pluginResponseModel.setSuccess(true); return pluginResponseModel; } catch (Exception e) { @@ -70,62 +71,22 @@ public class PluginController extends BaseController { } } - @RequestMapping(value = "loadMethodList/{pluginName}", method = { - RequestMethod.GET, RequestMethod.POST }) - @ResponseBody - public PluginResponseModel getMethodList( - @PathVariable("pluginName") String pluginName) - throws Bench4QException { - if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) { - throw new Bench4QException(400 + "", "not permitted", - "/loadMethodList/{pluginName}"); - } - PluginResponseModel pluginResponseModel = new PluginResponseModel(); - try { - - pluginResponseModel.setMethodList(this.getPluginService() - .getMethodNameInPlugin(pluginName)); - pluginResponseModel.setSuccess(true); - return pluginResponseModel; - } catch (Exception e) { - logger.error(ExceptionLog.getStackTrace(e)); - pluginResponseModel.setSuccess(false); - return pluginResponseModel; - } - } - - @RequestMapping(value = "loadMethodParams/{pluginName}/{methodName}", method = { - RequestMethod.GET, RequestMethod.POST }) - @ResponseBody - public PluginResponseModel getMethodParams( - @PathVariable("pluginName") String pluginName, - @PathVariable("methodName") String methodName) - throws Bench4QException { - if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) { - throw new Bench4QException(400 + "", "not permitted", - "loadMethodParams/{pluginName}/{methodName}"); - } - PluginResponseModel pluginResponseModel = new PluginResponseModel(); - pluginResponseModel.setMethosMethodParamModels(this.getPluginService() - .getMethodParamModelsInPlugin(pluginName, methodName)); - pluginResponseModel.setSuccess(true); - return pluginResponseModel; - } - @RequestMapping(value = "/addPlugin", method = { RequestMethod.PUT }) @ResponseBody - public PluginResponseModel addPlugin(@RequestBody PluginGUI pluginGUI) + public PluginResponseModel addPlugin( + @RequestParam("script") CommonsMultipartFile plugin) throws Bench4QException { if (!this.checkScope(UserService.SUPER_AUTHENTICATION)) { throw new Bench4QException(400 + "", "not permitted", "addPlugin/{pluginName}/{methodName}"); } - PluginResponseModel pluginResponseModel = validatePlugin(pluginGUI); + String pluginUIContent = new String(plugin.getBytes()); + PluginResponseModel pluginResponseModel = new PluginResponseModel(); + if (pluginResponseModel.isSuccess()) { pluginResponseModel.setSuccess(this.getPluginService().addPlugin( - pluginGUI.getPlugin())); + pluginUIContent)); } - return pluginResponseModel; } @@ -138,7 +99,7 @@ public class PluginController extends BaseController { throws Bench4QException { if (!this.checkScope(UserService.SUPER_AUTHENTICATION)) { throw new Bench4QException(400 + "", "not permitted", - "loadMethodParams/{pluginName}/{methodName}"); + "deletePlugin/{pluginName}"); } PluginResponseModel pluginResponseModel = new PluginResponseModel(); pluginResponseModel.setSuccess(this.getPluginService().deletePlugin( @@ -147,19 +108,4 @@ public class PluginController extends BaseController { } - private PluginResponseModel validatePlugin(PluginGUI pluginGUI) { - PluginResponseModel pluginResponseModel = new PluginResponseModel(); - pluginResponseModel.setSuccess(true); - if (pluginGUI.getPlugin() == null) { - pluginResponseModel.setSuccess(false); - pluginResponseModel.setFailMessage("plugin is null"); - } - if (pluginGUI.getPlugin().getMethods() == null - || pluginGUI.getPlugin().getMethods().size() == 0) { - pluginResponseModel.setSuccess(false); - pluginResponseModel.setFailMessage("method is empty"); - } - return pluginResponseModel; - } - } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/Method.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/BehaviorInfo.java similarity index 55% rename from Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/Method.java rename to Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/BehaviorInfo.java index c2d6464b..d9e81af0 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/Method.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/BehaviorInfo.java @@ -1,64 +1,63 @@ -package org.bench4q.master.domain.entity.plugin; - -import java.util.Set; - -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.OneToMany; -import javax.persistence.Table; - -@Entity -@Table(name = "method") -public class Method { - private int id; - private String name; - private Plugin plugin; - private Set methodParams; - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id", nullable = false) - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - @Column(name = "method", nullable = false) - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - @ManyToOne - @JoinColumn(name = "pluginId",nullable = false) - public Plugin getPlugin() { - return plugin; - } - - public void setPlugin(Plugin plugin) { - this.plugin = plugin; - } - - @OneToMany(mappedBy = "method", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER) - public Set getMethodParams() { - return methodParams; - } - - public void setMethodParams(Set methodParams) { - this.methodParams = methodParams; - } - -} +package org.bench4q.master.domain.entity.plugin; + +import java.util.Set; + +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.OneToMany; +import javax.persistence.Table; + +@Entity +@Table(name = "behaviorInfo") +public class BehaviorInfo { + private int id; + private String name; + private Set params; + private PluginUI pluginUI; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", nullable = false) + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Column(name = "name", nullable = false) + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @OneToMany(mappedBy = "behaviorInfo", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER) + public Set getParams() { + return params; + } + + public void setParams(Set params) { + this.params = params; + } + + @ManyToOne + @JoinColumn(name = "pluginId", nullable = false) + public PluginUI getPluginUI() { + return pluginUI; + } + + public void setPluginUI(PluginUI pluginUI) { + this.pluginUI = pluginUI; + } +} diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/BehaviorParamInfo.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/BehaviorParamInfo.java new file mode 100644 index 00000000..8efcd83c --- /dev/null +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/BehaviorParamInfo.java @@ -0,0 +1,22 @@ +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 = "behaviorParamInfo") +public class BehaviorParamInfo extends ParamInfo { + private BehaviorInfo behaviorInfo; + @ManyToOne + @JoinColumn(name = "behaviorId", nullable = false) + public BehaviorInfo getBehaviorInfo() { + return behaviorInfo; + } + + public void setBehaviorInfo(BehaviorInfo behaviorInfo) { + this.behaviorInfo = behaviorInfo; + }; + +} diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/CheckBoxType.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/CheckBoxType.java new file mode 100644 index 00000000..1e8c7bec --- /dev/null +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/CheckBoxType.java @@ -0,0 +1,25 @@ +package org.bench4q.master.domain.entity.plugin; + +import java.util.List; + +import javax.persistence.CascadeType; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +@Entity +@Table(name = "checboxType") +public class CheckBoxType extends ParamType { + private List choiceList; + + @OneToMany(mappedBy = "parentContainer", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER) + public List getChoiceList() { + return choiceList; + } + + public void setChoiceList(List choiceList) { + this.choiceList = choiceList; + } + +} diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/ChoiceType.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/ChoiceType.java new file mode 100644 index 00000000..c49edace --- /dev/null +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/ChoiceType.java @@ -0,0 +1,44 @@ +package org.bench4q.master.domain.entity.plugin; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "choiceType") +public class ChoiceType extends ParamType { + private String value; + private boolean defaultValue; + private ParamType parentContainer; + + @Column(name = "value") + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + @Column(name = "defaultValue") + public boolean isDefaultValue() { + return defaultValue; + } + + public void setDefaultValue(Boolean defaultValue) { + this.defaultValue = defaultValue; + } + + @ManyToOne + @JoinColumn(name = "containerId") + public ParamType getParentContainer() { + return parentContainer; + } + + public void setParentContainer(ParamType parentContainer) { + this.parentContainer = parentContainer; + } + +} diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/ComboType.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/ComboType.java new file mode 100644 index 00000000..4cbec372 --- /dev/null +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/ComboType.java @@ -0,0 +1,26 @@ +package org.bench4q.master.domain.entity.plugin; + +import java.util.List; + +import javax.persistence.CascadeType; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +@Entity +@Table(name = "comboType") +public class ComboType extends ParamType { + + private List choiceList; + + @OneToMany(mappedBy = "parentContainer", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER) + public List getChoiceList() { + return choiceList; + } + + public void setChoiceList(List choiceList) { + this.choiceList = choiceList; + } + +} diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/FieldType.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/FieldType.java new file mode 100644 index 00000000..fcf2d455 --- /dev/null +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/FieldType.java @@ -0,0 +1,31 @@ +package org.bench4q.master.domain.entity.plugin; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +@Entity +@Table(name = "fieldType") +public class FieldType extends ParamType { + private int size; + private String text; + + @Column(name = "size") + public int getSize() { + return size; + } + + public void setSize(int size) { + this.size = size; + } + + @Column(name = "text") + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + +} diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/MethodParam.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/MethodParam.java deleted file mode 100644 index a645e807..00000000 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/MethodParam.java +++ /dev/null @@ -1,105 +0,0 @@ -package org.bench4q.master.domain.entity.plugin; - -import java.util.Set; - -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.OneToMany; -import javax.persistence.Table; - -@Entity -@Table(name = "methodParam") -public class MethodParam { - private int id; - private Method method; - private String lable; - private String name; - private ParamType paramType; - private String valueSeperator = ";"; - private String fieldSeperator = ","; - private Set methodParamProperties; - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id", nullable = false) - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - @Column(name = "name", nullable = false) - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - @ManyToOne - @JoinColumn(name = "methodId", nullable = false) - public Method getMethod() { - return method; - } - - public void setMethod(Method method) { - this.method = method; - } - - @Column(name = "lable") - public String getLable() { - return lable; - } - - public void setLable(String lable) { - this.lable = lable; - } - - @ManyToOne(cascade = CascadeType.MERGE, fetch = FetchType.EAGER) - @JoinColumn(name = "paramTypeId", nullable = false) - public ParamType getParamType() { - return paramType; - } - - public void setParamType(ParamType paramType) { - this.paramType = paramType; - } - - @Column(name = "valueSeperator") - public String getValueSeperator() { - return valueSeperator; - } - - public void setValueSeperator(String valueSeperator) { - this.valueSeperator = valueSeperator; - } - - @Column(name = "fieldSeperator") - public String getFieldSeperator() { - return fieldSeperator; - } - - public void setFieldSeperator(String fieldSeperator) { - this.fieldSeperator = fieldSeperator; - } - - @OneToMany(mappedBy = "methodParam", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER) - public Set getMethodParamProperties() { - return methodParamProperties; - } - - public void setMethodParamProperties( - Set methodParamProperties) { - this.methodParamProperties = methodParamProperties; - } - -} diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/MethodParamProperty.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/MethodParamProperty.java deleted file mode 100644 index c45db4bb..00000000 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/MethodParamProperty.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.bench4q.master.domain.entity.plugin; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; - -@Entity -@Table(name = "methodParamProperty") -public class MethodParamProperty { - - private int id; - private String propertyKey; - private String propertyValue; - private MethodParam methodParam; - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id", nullable = false) - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - @Column(name = "propertyKey", nullable = false) - public String getPropertyKey() { - return propertyKey; - } - - public void setPropertyKey(String propertyKey) { - this.propertyKey = propertyKey; - } - - @Column(name = "propertyValue", nullable = false) - public String getPropertyValue() { - return propertyValue; - } - - public void setPropertyValue(String propertyValue) { - this.propertyValue = propertyValue; - } - - @ManyToOne - @JoinColumn(name = "methodParamId") - public MethodParam getMethodParam() { - return methodParam; - } - - public void setMethodParam(MethodParam methodParam) { - this.methodParam = methodParam; - } - -} diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/NFieldType.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/NFieldType.java new file mode 100644 index 00000000..95046be2 --- /dev/null +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/NFieldType.java @@ -0,0 +1,31 @@ +package org.bench4q.master.domain.entity.plugin; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +@Entity +@Table(name = "nfieldType") +public class NFieldType extends ParamType { + private int size; + private String text; + + @Column(name = "size") + public int getSize() { + return size; + } + + public void setSize(int size) { + this.size = size; + } + + @Column(name = "text") + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + +} 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 new file mode 100644 index 00000000..41a82a7d --- /dev/null +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/ParamInfo.java @@ -0,0 +1,60 @@ +package org.bench4q.master.domain.entity.plugin; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.MappedSuperclass; +import javax.persistence.OneToOne; + +@MappedSuperclass +public class ParamInfo { + + private int id; + private String name; + private String lable; + private ParamType type; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", nullable = false) + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Column(name = "name", nullable = false) + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Column(name = "lable") + public String getLable() { + return lable; + } + + public void setLable(String lable) { + this.lable = lable; + } + + @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER) + @JoinColumn(name = "typeId", nullable = false) + public ParamType getType() { + return type; + } + + public void setType(ParamType type) { + this.type = type; + } + +} 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 66110f9b..dab50e4b 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 @@ -2,23 +2,21 @@ package org.bench4q.master.domain.entity.plugin; import javax.persistence.Column; import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; import javax.persistence.Table; -import org.bench4q.share.models.master.plugin.ParamTypeEnum; - @Entity @Table(name = "paramType") -public class ParamType { +@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) +public abstract class ParamType { private int id; - private ParamTypeEnum type; @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) + @GeneratedValue(strategy = GenerationType.TABLE) @Column(name = "id", nullable = false) public int getId() { return id; @@ -28,14 +26,4 @@ public class ParamType { this.id = id; } - @Enumerated(EnumType.STRING) - @Column(name="type",columnDefinition = "ENUM('Field', 'MultiField', 'Table','CheckBox')") - public ParamTypeEnum getType() { - return type; - } - - public void setType(ParamTypeEnum type) { - this.type = type; - } - } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/Plugin.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/PluginInfo.java similarity index 67% rename from Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/Plugin.java rename to Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/PluginInfo.java index 9582fbe8..b31bf527 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/Plugin.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/PluginInfo.java @@ -14,10 +14,10 @@ import javax.persistence.Table; @Entity @Table(name = "plugin") -public class Plugin { +public class PluginInfo { private int id; private String name; - private Set pluginMethods; + private Set pluginParamInfos; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -33,19 +33,20 @@ public class Plugin { @Column(name = "name", nullable = false) public String getName() { return name; + } public void setName(String name) { this.name = name; } - @OneToMany(mappedBy = "plugin", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) - public Set getPluginMethods() { - return pluginMethods; + @OneToMany(mappedBy = "pluginInfo", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) + public Set getPluginParamInfos() { + return pluginParamInfos; } - public void setPluginMethods(Set pluginMethods) { - this.pluginMethods = pluginMethods; + public void setPluginParamInfos(Set pluginParamInfos) { + this.pluginParamInfos = pluginParamInfos; } } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/PluginParamInfo.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/PluginParamInfo.java new file mode 100644 index 00000000..47ba7a8e --- /dev/null +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/PluginParamInfo.java @@ -0,0 +1,21 @@ +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 = "pluginParamInfo") +public class PluginParamInfo extends ParamInfo { + private PluginInfo pluginInfo; + @ManyToOne + @JoinColumn(name = "pluginId", nullable = false) + public PluginInfo getPluginInfo() { + return pluginInfo; + } + + public void setPluginInfo(PluginInfo pluginInfo) { + this.pluginInfo = pluginInfo; + } +} 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 new file mode 100644 index 00000000..ceaccbfc --- /dev/null +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/PluginUI.java @@ -0,0 +1,55 @@ +package org.bench4q.master.domain.entity.plugin; + +import java.util.Set; + +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.OneToMany; +import javax.persistence.OneToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "pluginUI") +public class PluginUI { + + private int id; + private PluginInfo pluginInfo; + private Set behaviorInfos; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", nullable = false) + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER) + @JoinColumn(name = "pluginUIId", nullable = false) + public PluginInfo getPluginInfo() { + return pluginInfo; + } + + public void setPluginInfo(PluginInfo pluginInfo) { + this.pluginInfo = pluginInfo; + } + + @OneToMany(mappedBy = "pluginUI", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) + public Set getBehaviorInfos() { + return behaviorInfos; + } + + public void setBehaviorInfos(Set behaviorInfos) { + this.behaviorInfos = behaviorInfos; + } + +} diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/RadioButtonType.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/RadioButtonType.java new file mode 100644 index 00000000..0cd391c5 --- /dev/null +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/RadioButtonType.java @@ -0,0 +1,25 @@ +package org.bench4q.master.domain.entity.plugin; + +import java.util.List; + +import javax.persistence.CascadeType; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +@Entity +@Table(name = "radioButtonType") +public class RadioButtonType extends ParamType { + private List choices; + + @OneToMany(mappedBy = "parentContainer", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER) + public List getChoices() { + return choices; + } + + public void setChoices(List choices) { + this.choices = choices; + } + +} diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/TableType.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/TableType.java new file mode 100644 index 00000000..5ede4389 --- /dev/null +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/TableType.java @@ -0,0 +1,20 @@ +package org.bench4q.master.domain.entity.plugin; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +@Entity +@Table(name="tableType") +public class TableType extends ParamType { + private String cols; + @Column(name="cols") + public String getCols() { + return cols; + } + + public void setCols(String cols) { + this.cols = cols; + } + +} 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 new file mode 100644 index 00000000..5c04d089 --- /dev/null +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/PluginDomainFactory.java @@ -0,0 +1,182 @@ +package org.bench4q.master.domain.factory; + +import java.util.LinkedList; +import java.util.List; +import java.util.Set; +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.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.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.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.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class PluginDomainFactory { + private ParamTypeModelFactory paramTypeModelFactory; + + public ParamTypeModelFactory getParamTypeModelFactory() { + return paramTypeModelFactory; + } + + @Autowired + public void setParamTypeModelFactory( + ParamTypeModelFactory paramTypeModelFactory) { + this.paramTypeModelFactory = paramTypeModelFactory; + } + + public PluginUIModel createPluginUIModel(PluginUI pluginUI) { + PluginUIModel pluginUIModel = new PluginUIModel(); + pluginUIModel.setPluginInfoModel(createPluginInfoModel(pluginUI + .getPluginInfo())); + pluginUIModel.setBehaviorInfos(createBehaviorInfoModels(pluginUI.getBehaviorInfos())); + return pluginUIModel; + + } + + private PluginInfoModel createPluginInfoModel(PluginInfo pluginInfo) { + PluginInfoModel pluginInfoModel = new PluginInfoModel(); + pluginInfoModel.setName(pluginInfo.getName()); + pluginInfoModel.setParamInfoModels(createParamInfoModels(pluginInfo + .getPluginParamInfos())); + return pluginInfoModel; + } + + private 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; + + } + + @SuppressWarnings("rawtypes") + private List createParamInfoModels( + Set paramInfos) { + List paramInfoModels = new LinkedList(); + for (ParamInfo paramInfo : paramInfos) { + paramInfoModels.add(createParamInfoModel(paramInfo)); + } + return paramInfoModels; + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + private ParamInfoModel createParamInfoModel(ParamInfo paramInfo) { + ParamInfoModel paramInfoModel = new ParamInfoModel(); + paramInfoModel.setName(paramInfo.getName()); + paramInfoModel.setLable(paramInfo.getLable()); + paramInfoModel.setParamTypeModel(this.getParamTypeModelFactory() + .createParamTypeModel(paramInfo.getType())); + return paramInfoModel; + } +} + +@Component +class ParamTypeModelFactory { + public ParamTypeModel createParamTypeModel(ParamType paramType) { + if (paramType instanceof FieldType) + return createFieldModel((FieldType) paramType); + else if (paramType instanceof NFieldType) + return createNFieldModel((NFieldType) paramType); + else if (paramType instanceof TableType) + return createTableModel((TableType) paramType); + else if (paramType instanceof CheckBoxType) + return createCheckBoxModel((CheckBoxType) paramType); + else if (paramType instanceof ComboType) + return createComboModel((ComboType) paramType); + else if (paramType instanceof RadioButtonType) + return createRadioButton((RadioButtonType) paramType); + else + return null; + } + + 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 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 new file mode 100644 index 00000000..0cf84c15 --- /dev/null +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/PluginEntityFactory.java @@ -0,0 +1,298 @@ +package org.bench4q.master.domain.factory; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; +import org.apache.log4j.Logger; +import org.bench4q.master.domain.entity.plugin.BehaviorInfo; +import org.bench4q.master.domain.entity.plugin.BehaviorParamInfo; +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.NFieldType; +import org.bench4q.master.domain.entity.plugin.ParamType; +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.entity.plugin.RadioButtonType; +import org.bench4q.master.domain.entity.plugin.TableType; +import org.bench4q.master.exception.ExceptionLog; +import org.dom4j.Attribute; +import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.DocumentHelper; +import org.dom4j.Element; +import org.springframework.stereotype.Component; + +@Component +public class PluginEntityFactory { + private Logger logger = Logger.getLogger(PluginEntityFactory.class); + + public PluginUI createPluginUIWithOutId(String pluginUIContent) { + Element root = getDocument(pluginUIContent).getRootElement(); + PluginUI pluginUI = new PluginUI(); + pluginUI.setPluginInfo(createPluginInfoWithOutId(XmlParseHelper + .getOneChildElementByName(root, "plugin"))); + pluginUI.setBehaviorInfos(createBehaviorInfosWithOutId( + XmlParseHelper.getChildElementsByName(root, "behavior"), + pluginUI)); + return pluginUI; + } + + 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) { + + PluginInfo pluginInfo = new PluginInfo(); + pluginInfo.setName(XmlParseHelper.getAttribute(element, "name")); + Element paramsElement = XmlParseHelper.getOneChildElementByName( + element, "params"); + pluginInfo.setPluginParamInfos(createPluginParamInfos( + XmlParseHelper.getChildElements(paramsElement), pluginInfo)); + return pluginInfo; + + } + + private Set createBehaviorInfosWithOutId( + List elements, PluginUI pluginUI) { + Set behaviorInfos = new HashSet(); + for (Element element : elements) { + behaviorInfos.add(createBehaviorInfoWithOutId(element, pluginUI)); + } + return behaviorInfos; + } + + private BehaviorInfo createBehaviorInfoWithOutId(Element element, + PluginUI pluginUI) { + BehaviorInfo behaviorInfo = new BehaviorInfo(); + behaviorInfo.setName(XmlParseHelper.getAttribute(element, "name")); + behaviorInfo.setPluginUI(pluginUI); + behaviorInfo.setParams(createBehaviorParamInfos( + XmlParseHelper.getChildElements(element), behaviorInfo)); + return behaviorInfo; + } + + 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 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 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(); + if (XmlParseHelper.getSingleChild(element) != null) + behaviorParamInfo + .setType(paramTypeFactory + .createParamTypeInfo(XmlParseHelper + .getSingleChild(element))); + + behaviorParamInfo.setBehaviorInfo(behaviorInfo); + + return behaviorParamInfo; + } + + private PluginParamInfo createPluginParamInfoWithOutId(Element element, + PluginInfo pluginInfo) { + if (XmlParseHelper.getAttribute(element, "name") == null) + return null; + PluginParamInfo pluginParamInfo = new PluginParamInfo(); + pluginParamInfo.setLable(XmlParseHelper.getAttribute(element, "lable")); + pluginParamInfo.setName(XmlParseHelper.getAttribute(element, "name")); + ParamTypeFactory paramTypeFactory = new ParamTypeFactory(); + pluginParamInfo.setType(paramTypeFactory + .createParamTypeInfo(XmlParseHelper.getSingleChild(element))); + pluginParamInfo.setPluginInfo(pluginInfo); + return pluginParamInfo; + + } +} + +class ParamTypeFactory { + public ParamType createParamTypeInfo(Element element) { + String type = element.getName(); + switch (type) { + case "field": + return createFileType(element); + case "nfield": + return createNFieldType(element); + case "table": + return createTableType(element); + case "radiobutton": + return createRadioButtonType(element); + case "checkbox": + return createCheckBoxType(element); + case "combo": + return createComboType(element); + } + return null; + + } + + private FieldType createFileType(Element element) { + FieldType fieldType = new FieldType(); + fieldType.setSize(Integer.parseInt(XmlParseHelper.getAttribute(element, + "size"))); + fieldType.setText(XmlParseHelper.getAttribute(element, "text")); + return fieldType; + } + + private NFieldType createNFieldType(Element element) { + NFieldType nFieldType = new NFieldType(); + if (XmlParseHelper.getAttribute(element, "size") != null) + nFieldType.setSize(Integer.parseInt(XmlParseHelper.getAttribute( + element, "size"))); + nFieldType.setText(XmlParseHelper.getAttribute(element, "text")); + return nFieldType; + } + + private TableType createTableType(Element element) { + TableType tableType = new TableType(); + tableType.setCols(XmlParseHelper.getAttribute(element, "cols")); + return tableType; + } + + private RadioButtonType createRadioButtonType(Element element) { + RadioButtonType radioButtonType = new RadioButtonType(); + radioButtonType.setChoices(createChoiceTypes( + XmlParseHelper.getChildElements(element), radioButtonType)); + return radioButtonType; + } + + private CheckBoxType createCheckBoxType(Element element) { + CheckBoxType checkBoxType = new CheckBoxType(); + + checkBoxType.setChoiceList(createChoiceTypes( + XmlParseHelper.getChildElements(element), checkBoxType)); + return checkBoxType; + } + + private ComboType createComboType(Element element) { + ComboType comboType = new ComboType(); + comboType.setChoiceList(createChoiceTypes( + XmlParseHelper.getChildElements(element), comboType)); + return comboType; + } + + private List createChoiceTypes(List elements, + ParamType parentContainer) { + List choiceTypes = new LinkedList(); + for (Element element : elements) { + choiceTypes.add(createChoiceType(element, parentContainer)); + } + return choiceTypes; + + } + + private ChoiceType createChoiceType(Element element, + ParamType parentContainer) { + ChoiceType choiceType = new ChoiceType(); + choiceType.setValue(XmlParseHelper.getAttribute(element, "value")); + choiceType.setDefaultValue(Boolean.getBoolean(XmlParseHelper + .getAttribute(element, "default"))); + choiceType.setParentContainer(parentContainer); + return choiceType; + + } +} + +class XmlParseHelper { + public static Element getSingleChild(Element element) { + List choiceElements = new LinkedList(); + for (@SuppressWarnings("rawtypes") + Iterator iterator = element.elementIterator(); iterator.hasNext();) { + choiceElements.add((Element) iterator.next()); + } + if (choiceElements.size() == 0) + return null; + else + return choiceElements.get(0); + } + + public static String getAttribute(Element element, String attributeName) { + for (@SuppressWarnings("rawtypes") + Iterator iterator = element.attributeIterator(); iterator.hasNext();) { + Attribute attribute = (Attribute) iterator.next(); + if (attribute.getName().equals(attributeName)) { + return attribute.getValue(); + + } + + } + return null; + } + + public static List getChildElements(Element element) { + List choiceElements = new LinkedList(); + for (@SuppressWarnings("rawtypes") + Iterator iterator = element.elementIterator(); iterator.hasNext();) { + choiceElements.add((Element) iterator.next()); + } + return choiceElements; + } + + public static Element getOneChildElementByName(Element element, + String elementName) { + for (@SuppressWarnings("rawtypes") + Iterator iterator = element.elementIterator(); iterator.hasNext();) { + Element childElement = (Element) iterator.next(); + if (childElement.getName().equals(elementName)) + + return childElement; + } + return null; + } + + @SuppressWarnings("rawtypes") + public static List getChildElementsByName(Element element, + String elementName) { + + List elements = new LinkedList<>(); + for (Iterator iterator = element.elementIterator(); iterator.hasNext();) { + Element childElement = (Element) iterator.next(); + if (childElement.getName().equals(elementName)) + elements.add(childElement); + } + return elements; + + } +} diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/PluginFactory.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/PluginFactory.java deleted file mode 100644 index 031e09b1..00000000 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/PluginFactory.java +++ /dev/null @@ -1,148 +0,0 @@ -package org.bench4q.master.domain.factory; - -import java.util.HashSet; - -import org.apache.log4j.Logger; -import org.bench4q.master.domain.entity.plugin.Method; -import org.bench4q.master.domain.entity.plugin.MethodParam; -import org.bench4q.master.domain.entity.plugin.MethodParamProperty; -import org.bench4q.master.domain.entity.plugin.ParamType; -import org.bench4q.master.domain.entity.plugin.Plugin; -import org.bench4q.master.domain.repository.PluginRepository; -import org.bench4q.master.exception.Bench4QException; -import org.bench4q.share.models.master.plugin.MethodModel; -import org.bench4q.share.models.master.plugin.MethodParamModel; -import org.bench4q.share.models.master.plugin.MethodParamPropertyModel; -import org.bench4q.share.models.master.plugin.ParamTypeEnum; -import org.bench4q.share.models.master.plugin.PluginModel; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -@Component -public class PluginFactory { - - private PluginRepository pluginRepository; - - public PluginRepository getPluginRepository() { - return pluginRepository; - } - - @Autowired - public void setPluginRepository(PluginRepository pluginRepository) { - this.pluginRepository = pluginRepository; - } - - public Plugin createPluginEntity(PluginModel pluginModel) - throws Bench4QException { - Plugin plugin = new Plugin(); - plugin.setPluginMethods(new HashSet()); - if (pluginModel.getMethods() != null) { - for (MethodModel methodModel : pluginModel.getMethods()) { - plugin.getPluginMethods().add( - createMethodEntity(methodModel, plugin)); - } - plugin.setName(pluginModel.getName()); - return plugin; - } else - throw new Bench4QException("", "no method in plugin", ""); - - } - - private Method createMethodEntity(MethodModel methodModel, Plugin plugin) - throws Bench4QException { - Method method = new Method(); - method.setMethodParams(new HashSet()); - method.setName(methodModel.getName()); - if (methodModel.getMethodParams() != null) { - for (MethodParamModel methodParamModel : methodModel - .getMethodParams()) { - Logger.getLogger(PluginFactory.class).info( - "method model:" + methodModel.getName()); - method.getMethodParams().add( - createMethodParamEntity(methodParamModel, method)); - } - } - method.setPlugin(plugin); - - return method; - } - - private MethodParam createMethodParamEntity( - MethodParamModel methodParamModel, Method method) - throws Bench4QException { - MethodParam methodParam = new MethodParam(); - methodParam.setLable(methodParamModel.getLable()); - methodParam.setName(methodParamModel.getName()); - methodParam.setMethod(method); - methodParam.setParamType(createPraParamTypeWithOutId(methodParamModel - .getParamType())); - if (methodParamModel.getMethodParamProperties() != null) { - methodParam - .setMethodParamProperties(new HashSet()); - for (MethodParamPropertyModel methodParamPropertyModel : methodParamModel - .getMethodParamProperties()) { - methodParam.getMethodParamProperties().add( - createMethodParamPropertyWithOutId( - methodParamPropertyModel, methodParam)); - } - } - return methodParam; - } - - private ParamType createPraParamTypeWithOutId(ParamTypeEnum paramTypeEnum) - throws Bench4QException { - return this.getPluginRepository().getParamTypeByType(paramTypeEnum); - } - - private MethodParamProperty createMethodParamPropertyWithOutId( - MethodParamPropertyModel methodParamPropertyModel, - MethodParam methodParam) { - MethodParamProperty methodParamProperty = new MethodParamProperty(); - methodParamProperty.setPropertyKey(methodParamPropertyModel.getKey()); - methodParamProperty.setPropertyValue(methodParamPropertyModel - .getValue()); - methodParamProperty.setMethodParam(methodParam); - return methodParamProperty; - } - - public static MethodModel extractMethodModel(Method method) { - MethodModel methodModel = new MethodModel(); - methodModel.setName(method.getName()); - if (method.getMethodParams() != null) { - methodModel.setMethodParams(new HashSet()); - for (MethodParam methodParam : method.getMethodParams()) { - methodModel.getMethodParams().add( - extractMethodParamModel(methodParam)); - } - } - return methodModel; - } - - private static MethodParamModel extractMethodParamModel( - MethodParam methodParam) { - MethodParamModel methodParamModel = new MethodParamModel(); - methodParamModel.setLable(methodParam.getLable()); - methodParamModel.setName(methodParam.getName()); - methodParamModel.setParamType(methodParam.getParamType().getType()); - if (methodParam.getMethodParamProperties() != null) { - methodParamModel - .setMethodParamProperties(new HashSet()); - for (MethodParamProperty methodParamProperty : methodParam - .getMethodParamProperties()) { - methodParamModel.getMethodParamProperties().add( - extractMethodParamPropertyModel(methodParamProperty)); - } - } - return methodParamModel; - } - - private static MethodParamPropertyModel extractMethodParamPropertyModel( - MethodParamProperty methodParamProperty) { - MethodParamPropertyModel methodParamPropertyModel = new MethodParamPropertyModel(); - methodParamPropertyModel.setKey(methodParamProperty.getPropertyKey()); - methodParamPropertyModel.setValue(methodParamProperty - .getPropertyValue()); - return methodParamPropertyModel; - } - -} diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/repository/PluginRepository.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/repository/PluginRepository.java index ff8d694b..76332b1e 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/repository/PluginRepository.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/repository/PluginRepository.java @@ -1,13 +1,12 @@ package org.bench4q.master.domain.repository; import java.util.List; - -import org.bench4q.master.domain.entity.plugin.Method; -import org.bench4q.master.domain.entity.plugin.ParamType; -import org.bench4q.master.domain.entity.plugin.Plugin; -import org.bench4q.master.exception.Bench4QException; +import java.util.Set; +import org.bench4q.master.domain.entity.plugin.BehaviorInfo; +import org.bench4q.master.domain.entity.plugin.PluginInfo; +import org.bench4q.master.domain.entity.plugin.PluginUI; +import org.bench4q.master.exception.ExceptionLog; import org.bench4q.master.exception.ExceptionUtils.EntityUniqueAlReadyExistException; -import org.bench4q.share.models.master.plugin.ParamTypeEnum; import org.hibernate.Criteria; import org.hibernate.Session; import org.hibernate.Transaction; @@ -16,64 +15,26 @@ import org.springframework.stereotype.Component; @Component public class PluginRepository extends AbstractRepositoty { - @SuppressWarnings("unchecked") - private void fillParamType(Session session) throws Bench4QException { - Transaction transaction = session.beginTransaction(); - List ret = session.createCriteria(ParamType.class).list(); - if (ret.size() == 0) { - try { - for (ParamTypeEnum paramTypeEnum : ParamTypeEnum.values()) { - ParamType paramType = new ParamType(); - paramType.setType(paramTypeEnum); - session.merge(paramType); - } - transaction.commit(); - } catch (Exception e) { - transaction.rollback(); - logger.error(e, e.fillInStackTrace()); - throw new Bench4QException("", "fill paramType fail", ""); - } - } - } - - public ParamType getParamTypeByType(ParamTypeEnum paramTypeEnum) - throws Bench4QException { - - ParamType paramType = null; - Session session = this.getSessionHelper().openSession(); - @SuppressWarnings("unchecked") - List ret = session.createCriteria(ParamType.class).list(); - if (ret.size() == 0) { - fillParamType(session); - } - paramType = (ParamType) session.createCriteria(ParamType.class) - .add(Restrictions.eq("type", paramTypeEnum)).uniqueResult(); - if (paramType == null) - logger.info("paramType not exit"); - releaseSession(session); - return paramType; - } - - public boolean attatch(Plugin plugin) throws Bench4QException { - + public boolean attatch(PluginUI pluginUI) { Session session = this.getSessionHelper().openSession(); Transaction transaction = session.beginTransaction(); - Plugin pluginExist = null; try { - pluginExist = (Plugin) session.createCriteria(Plugin.class) - .add(Restrictions.eq("name", plugin.getName())) - .uniqueResult(); - if (pluginExist != null) { - logger.info("the plugin exist"); + PluginInfo pluginInfo = null; + pluginInfo = (PluginInfo) session + .createCriteria(PluginInfo.class) + .add(Restrictions.eq("name", pluginUI.getPluginInfo() + .getName())).uniqueResult(); + if (pluginInfo != null) { + logger.info("the plugin already exists"); return false; } - session.merge(plugin); + session.merge(pluginUI); transaction.commit(); return true; } catch (Exception e) { transaction.rollback(); - logger.error(e, e.fillInStackTrace()); - throw new Bench4QException("", "add plugin fail", ""); + logger.error(ExceptionLog.getStackTrace(e)); + return false; } finally { releaseSession(session); } @@ -83,82 +44,100 @@ public class PluginRepository extends AbstractRepositoty { protected void guardOtherUniqueConditionForEntity( String uniquePropertyName, String value) throws EntityUniqueAlReadyExistException { - if (getPlugin(value) != null) { + if (getPluginUI(value) != null) { throw new EntityUniqueAlReadyExistException("User with the name " + value + "already exists"); } } - public boolean detach(String pluginName) throws Bench4QException { + public boolean detach(String pluginName) { Session session = this.getSessionHelper().openSession(); Transaction transaction = session.beginTransaction(); try { - Plugin pluginExist = (Plugin) session.createCriteria(Plugin.class) - .add(Restrictions.eq("name", pluginName)).uniqueResult(); - if (pluginExist == null) { + PluginUI pluginUI = getPluginUI(pluginName); + if (pluginUI == null) { logger.info("plugin not exist"); return false; } - session.delete(pluginExist); + session.delete(pluginUI); transaction.commit(); return true; } catch (Exception e) { - logger.error(e, e.fillInStackTrace()); + logger.error(ExceptionLog.getStackTrace(e)); transaction.rollback(); - throw new Bench4QException("", "delete plugin fail", ""); + return false; } finally { releaseSession(session); } } - public List loadPlugins() throws Bench4QException { + public List loadPlugins() { Session session = this.getSessionHelper().openSession(); try { @SuppressWarnings("unchecked") - List ret = session.createCriteria(Plugin.class) + List ret = session.createCriteria(PluginUI.class) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); return ret; } catch (Exception e) { - logger.error("load Plugins "); - logger.error(e, e.fillInStackTrace()); - throw new Bench4QException("", "load plugin failed", ""); + logger.error(ExceptionLog.getStackTrace(e)); + return null; } finally { releaseSession(session); } } - public boolean isExist(Plugin plugin) { + public Set loadBehaviorInfos(String pluginName) { Session session = this.getSessionHelper().openSession(); - Plugin pluginAlreadyExist = (Plugin) session - .createCriteria(Plugin.class) - .add(Restrictions.eq("userName", plugin.getName())) + try { + + PluginUI pluginUI = dogetPluginUI(pluginName, session); + Set behaviorInfos = pluginUI.getBehaviorInfos(); + logger.info(behaviorInfos.size()); + + return behaviorInfos; + } catch (Exception e) { + logger.info(ExceptionLog.getStackTrace(e)); + return null; + } finally { + releaseSession(session); + } + } + + public boolean isExist(PluginUI plugin) { + Session session = this.getSessionHelper().openSession(); + PluginInfo pluginAlreadyExist = (PluginInfo) session + .createCriteria(PluginInfo.class) + .add(Restrictions.eq("name", plugin.getPluginInfo().getName())) .uniqueResult(); releaseSession(session); return pluginAlreadyExist != null; } - public Plugin getPlugin(String pluginName) { - Plugin plugin = null; + public PluginUI getPluginUI(String pluginName) { + if (pluginName == null) { + logger.info("plugin name is null"); + return null; + } + PluginUI pluginUI = null; Session session = this.getSessionHelper().openSession(); - plugin = deGetPlugin(pluginName, session); - plugin.getPluginMethods(); + pluginUI = dogetPluginUI(pluginName, session); releaseSession(session); - return plugin; + if (pluginUI == null) + logger.info(pluginName + " plugin is null from repository"); + return pluginUI; } - private Plugin deGetPlugin(String pluginName, Session session) { - return (Plugin) session.createCriteria(Plugin.class) + public PluginUI dogetPluginUI(String pluginName, Session session) { + PluginInfo pluginInfo = deGetPluginInfo(pluginName, session); + if (pluginInfo == null) + return null; + return (PluginUI) session.createCriteria(PluginUI.class) + .add(Restrictions.eq("pluginInfo", pluginInfo)).uniqueResult(); + } + + private PluginInfo deGetPluginInfo(String pluginName, Session session) { + return (PluginInfo) session.createCriteria(PluginInfo.class) .add(Restrictions.eq("name", pluginName)).uniqueResult(); } - public List loadMethodsInPlugin(Plugin plugin) { - Session session = this.getSessionHelper().openSession(); - @SuppressWarnings("unchecked") - List methods = (List) session - .createCriteria(Method.class) - .add(Restrictions.eq("plugin", plugin)).list(); - releaseSession(session); - return methods; - } - } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/repository/TestPlanRepository.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/repository/TestPlanRepository.java index 175cff2f..453eb879 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/repository/TestPlanRepository.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/repository/TestPlanRepository.java @@ -60,26 +60,6 @@ public class TestPlanRepository extends AbstractRepositoty { } } - // public TestPlan getTestPlanWithOneMonitorResult(String - // testPlanRunId,Monitor monitor){ - // - // Session session = this.getSessionHelper().openSession(); - // try{ - // TestPlan testPlan=(TestPlan) session - // .createCriteria(TestPlan.class) - // .add(Restrictions.eq("testPlanRunId", testPlanRunId)) - // .uniqueResult(); - // monitor=testPlan.extractSpecifiedMonitor(monitor.getHostName()); - // List monitorResults=session - // .createCriteria(MonitorResult.class) - // .add(Restrictions.eq("testPlanRunId", monitor)) - // .uniqueResult(); - // - // }catch(Exception e){ - // logger.info(ExceptionLog.getStackTrace(e)); - // return null; - // } - // } @Override protected void guardOtherUniqueConditionForEntity( 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 6949fec6..5e61453a 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 @@ -1,27 +1,17 @@ package org.bench4q.master.domain.service; -import java.util.ArrayList; -import java.util.HashSet; +import java.util.LinkedList; import java.util.List; -import java.util.Set; -import org.apache.log4j.Logger; -import org.bench4q.master.domain.entity.plugin.Plugin; import org.bench4q.master.domain.repository.PluginRepository; -import org.bench4q.master.exception.Bench4QException; -import org.bench4q.master.domain.entity.plugin.Method; -import org.bench4q.master.domain.factory.PluginFactory; -import org.bench4q.share.models.master.plugin.MethodModel; -import org.bench4q.share.models.master.plugin.MethodParamModel; -import org.bench4q.share.models.master.plugin.PluginModel; +import org.bench4q.master.domain.factory.PluginEntityFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component public class PluginService { private PluginRepository pluginRepository; - private PluginFactory pluginFactory; - private Logger logger = Logger.getLogger(PluginService.class); + private PluginEntityFactory pluginEntityFactory; public PluginRepository getPluginRepository() { return pluginRepository; @@ -32,96 +22,29 @@ public class PluginService { this.pluginRepository = pluginRepository; } - public PluginFactory getPluginFactory() { - return pluginFactory; + public PluginEntityFactory getPluginEntityFactory() { + return pluginEntityFactory; } @Autowired - private void setPluginFactory(PluginFactory pluginFactory) { - this.pluginFactory = pluginFactory; + private void setPluginEntityFactory(PluginEntityFactory pluginEntityFactory) { + this.pluginEntityFactory = pluginEntityFactory; } - public boolean addPlugin(PluginModel pluginModel) throws Bench4QException { + public boolean addPlugin(String pluginUIContent) { return this.getPluginRepository().attatch( - - this.getPluginFactory().createPluginEntity(pluginModel)); + this.getPluginEntityFactory().createPluginUIWithOutId( + pluginUIContent)); } - public boolean deletePlugin(String pluginName) throws Bench4QException { + public boolean deletePlugin(String pluginName) { return this.getPluginRepository().detach(pluginName); } - public List getPluginNameList() throws Bench4QException { - List pluginNameList = new ArrayList(); - Set plugins = getPlugins(); - if (plugins != null) { - for (Plugin plugin : plugins) { - pluginNameList.add(plugin.getName()); - } - } + public List getPluginNameList() { + List pluginNameList = new LinkedList(); return pluginNameList; - } - private Set getPlugins() throws Bench4QException { - List loadPluginList = this.getPluginRepository().loadPlugins(); - Set plugins = new HashSet(); - if (loadPluginList != null) { - - for (Plugin plugin : loadPluginList) { - plugins.add(plugin); - } - } - - return plugins; - } - - public List getMethodNameInPlugin(String pluginName) { - List methodNameList = new ArrayList(); - Plugin plugin = this.getPluginRepository().getPlugin(pluginName); - List methods = this.getPluginRepository().loadMethodsInPlugin( - plugin); - - if (methods != null) { - for (Method method : methods) { - methodNameList.add(method.getName()); - } - } - return methodNameList; - } - - private Method getMethodInPlugin(String pluginName, String methodName) - throws Bench4QException { - Plugin plugin = this.getPluginRepository().getPlugin(pluginName); - List methods = this.getPluginRepository().loadMethodsInPlugin( - plugin); - if (methods != null) { - for (Method method : methods) { - if (method.getName().equals(methodName)) - return method; - } - } - logger.info("method is empty"); - - throw new Bench4QException("", "no such method:" + methodName - + "in plugin:" + pluginName, ""); - - } - - public Set getMethodParamModelsInPlugin( - String pluginName, String methodName) throws Bench4QException { - return PluginFactory.extractMethodModel( - this.getMethodInPlugin(pluginName, methodName)) - .getMethodParams(); - } - - public Set getMethodsInPlugin(String pluginName) { - Plugin plugin = this.getPluginRepository().getPlugin(pluginName); - Set methodModels = new HashSet(); - for (Method method : this.getPluginRepository().loadMethodsInPlugin( - plugin)) { - methodModels.add(PluginFactory.extractMethodModel(method)); - } - return methodModels; } } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/helper/SessionHelper.java b/Bench4Q-Master/src/main/java/org/bench4q/master/helper/SessionHelper.java index 6f38c0d4..de3baabb 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/helper/SessionHelper.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/helper/SessionHelper.java @@ -30,10 +30,6 @@ public final class SessionHelper { } } - public Session getCurrentSession(){ - return this.getSessionFactory().getCurrentSession(); - - } public Session openSession() { return this.getSessionFactory().openSession(); } 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 b72cad92..c1ba5fb6 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 @@ -17,7 +17,6 @@ true true true - @@ -29,10 +28,19 @@ - - - + + + - + + + + + + + + + + \ No newline at end of file diff --git a/Bench4Q-Master/src/test/java/TestHelper/Test_PluginHelper.java b/Bench4Q-Master/src/test/java/TestHelper/Test_PluginHelper.java new file mode 100644 index 00000000..60aef88e --- /dev/null +++ b/Bench4Q-Master/src/test/java/TestHelper/Test_PluginHelper.java @@ -0,0 +1,21 @@ +package TestHelper; + +import java.io.File; +import java.io.IOException; + +import org.apache.commons.io.FileUtils; +import org.bench4q.master.domain.entity.plugin.PluginUI; +import org.bench4q.master.domain.factory.PluginEntityFactory; +public class Test_PluginHelper{ + public static PluginUI createPluginUI(String fileName) throws IOException { + PluginEntityFactory pluginEntityFactory = new PluginEntityFactory(); + String fileSeparator = System.getProperty("file.separator"); + String filePath = System.getProperty("user.dir") + fileSeparator + + "pluginUI" + fileSeparator + fileName; + File file = new File(filePath); + String uiContent = FileUtils.readFileToString(file); + PluginUI pluginUI = pluginEntityFactory + .createPluginUIWithOutId(uiContent); + return pluginUI; + } +} diff --git a/Bench4Q-Master/src/test/java/TestHelper/Test_PlunginHelper.java b/Bench4Q-Master/src/test/java/TestHelper/Test_PlunginHelper.java deleted file mode 100644 index a07377f0..00000000 --- a/Bench4Q-Master/src/test/java/TestHelper/Test_PlunginHelper.java +++ /dev/null @@ -1,59 +0,0 @@ -package TestHelper; -import java.util.HashSet; -import java.util.Set; -import java.util.UUID; - -import org.bench4q.share.models.master.plugin.MethodModel; -import org.bench4q.share.models.master.plugin.MethodParamModel; -import org.bench4q.share.models.master.plugin.ParamTypeEnum; -import org.bench4q.share.models.master.plugin.PluginModel; -import org.bench4q.share.models.master.plugin.MethodParamPropertyModel; - -public class Test_PlunginHelper { - - public static PluginModel createOnePlugin() { - PluginModel plugin = new PluginModel(); - MethodModel method = new MethodModel(); - MethodParamModel methodParamModelUrl = new MethodParamModel(); - methodParamModelUrl.setLable("input url"); - methodParamModelUrl.setName("url"); - methodParamModelUrl.setMethodParamProperties(generatePropertyForField()); - methodParamModelUrl.setParamType(ParamTypeEnum.Field); - - MethodParamModel methodParamsParamModel = new MethodParamModel(); - methodParamsParamModel.setName("queryparams"); - methodParamsParamModel.setLable("key=value"); - methodParamsParamModel.setMethodParamProperties(generatePropertyForMulti()); - methodParamsParamModel.setParamType(ParamTypeEnum.MultiField); - Set methodParams = new HashSet(); - methodParams.add(methodParamModelUrl); - methodParams.add(methodParamsParamModel); - method.setName("get"); - method.setMethodParams(methodParams); - - Set methods = new HashSet(); - methods.add(method); - plugin.setMethods(methods); - plugin.setName("http" + UUID.randomUUID()); - return plugin; - - } - private static Set generatePropertyForField() { - Set metList = new HashSet(); - MethodParamPropertyModel methodParamPropertyModel = new MethodParamPropertyModel(); - methodParamPropertyModel.setKey("size"); - methodParamPropertyModel.setValue("20"); - metList.add(methodParamPropertyModel); - return metList; - - } - private static Set generatePropertyForMulti() { - Set metList = new HashSet(); - MethodParamPropertyModel methodParamPropertyModel = new MethodParamPropertyModel(); - methodParamPropertyModel.setKey("size"); - methodParamPropertyModel.setValue("20"); - metList.add(methodParamPropertyModel); - return metList; - - } -} 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 ff98591d..d6307318 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 @@ -7,16 +7,16 @@ import java.io.IOException; import javax.xml.bind.JAXBException; import org.apache.log4j.Logger; +import org.bench4q.master.domain.entity.plugin.PluginUI; import org.bench4q.share.communication.HttpRequester.HttpResponse; import org.bench4q.share.helper.MarshalHelper; -import org.bench4q.share.models.master.plugin.PluginGUI; import org.bench4q.share.models.master.plugin.PluginResponseModel; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import TestHelper.Test_PlunginHelper; +import TestHelper.Test_PluginHelper; public class PluginControllerTest extends TestBase { private final String URLSTRING = BASE_URL + "/plugin"; @@ -36,10 +36,9 @@ public class PluginControllerTest extends TestBase { public void testAddPlugin() throws JAXBException, IOException { this.setAccessTocken(this.login()); String url = URLSTRING + "/addPlugin"; - PluginGUI pluginGUI = new PluginGUI(); - pluginGUI.setPlugin(Test_PlunginHelper.createOnePlugin()); - pluginName = pluginGUI.getPlugin().getName(); - String pluginContentString = MarshalHelper.marshal(PluginGUI.class, + PluginUI pluginGUI = Test_PluginHelper.createPluginUI("ui.xml"); + pluginName = pluginGUI.getPluginInfo().getName(); + String pluginContentString = MarshalHelper.marshal(PluginUI.class, pluginGUI); HttpResponse httpResponse = this.httpRequester.sendPutXml(url, pluginContentString, @@ -55,27 +54,29 @@ public class PluginControllerTest extends TestBase { Assert.assertTrue(pluginResponseModel.isSuccess()); } - @Test - public void testGetMethodParamModel() throws IOException, JAXBException { - String url = URLSTRING + "/loadMethodParams"; - String urlForLoadMethod = URLSTRING + "/loadMethodList/" + pluginName; - HttpResponse httpResponseMethod = this.httpRequester.sendPost( - urlForLoadMethod, null, - makeAccessTockenMap(this.getAccessTocken())); - PluginResponseModel pluginResponseModelMethod = (PluginResponseModel) MarshalHelper - .unmarshal(PluginResponseModel.class, - httpResponseMethod.getContent()); - assertTrue(pluginResponseModelMethod.isSuccess()); - String methodName = pluginResponseModelMethod.getMethodList().get(0); - url += "/" + pluginName + "/" + methodName; - HttpResponse httpResponse = this.httpRequester.sendPost(url, null, - makeAccessTockenMap(this.getAccessTocken())); - PluginResponseModel pluginResponseModel = (PluginResponseModel) MarshalHelper - .tryUnmarshal(PluginResponseModel.class, - httpResponse.getContent()); - Assert.assertTrue(pluginResponseModel.isSuccess()); - assertEquals(2, pluginResponseModel.getMethosMethodParamModels().size()); - } + // @Test + // public void testGetMethodParamModel() throws IOException, JAXBException { + // String url = URLSTRING + "/loadMethodParams"; + // String urlForLoadMethod = URLSTRING + "/loadMethodList/" + pluginName; + // HttpResponse httpResponseMethod = this.httpRequester.sendPost( + // urlForLoadMethod, null, + // makeAccessTockenMap(this.getAccessTocken())); + // PluginResponseModel pluginResponseModelMethod = (PluginResponseModel) + // MarshalHelper + // .unmarshal(PluginResponseModel.class, + // httpResponseMethod.getContent()); + // assertTrue(pluginResponseModelMethod.isSuccess()); + // String methodName = pluginResponseModelMethod.getMethodList().get(0); + // url += "/" + pluginName + "/" + methodName; + // HttpResponse httpResponse = this.httpRequester.sendPost(url, null, + // makeAccessTockenMap(this.getAccessTocken())); + // PluginResponseModel pluginResponseModel = (PluginResponseModel) + // MarshalHelper + // .tryUnmarshal(PluginResponseModel.class, + // httpResponse.getContent()); + // Assert.assertTrue(pluginResponseModel.isSuccess()); + // assertEquals(2, pluginResponseModel.getMethosMethodParamModels().size()); + // } @Test public void testLoadPluginList() throws JAXBException, IOException { @@ -90,19 +91,20 @@ public class PluginControllerTest extends TestBase { Assert.assertTrue(pluginResponseModel.getPluginList().size() > 0); } - @Test - public void testLoadMethodNameList() throws IOException, JAXBException { - String urlForLoadMethod = URLSTRING + "/loadMethodList/" + pluginName; - HttpResponse httpResponse = this.httpRequester.sendPost( - urlForLoadMethod, null, - makeAccessTockenMap(this.getAccessTocken())); - System.out.println(httpResponse.getContent()); - PluginResponseModel pluginResponseModel = (PluginResponseModel) MarshalHelper - .unmarshal(PluginResponseModel.class, httpResponse.getContent()); - assertNotNull(pluginResponseModel); - Assert.assertTrue(pluginResponseModel.isSuccess()); - assertEquals(2, pluginResponseModel.getMethodList().size()); - } + // @Test + // public void testLoadMethodNameList() throws IOException, JAXBException { + // String urlForLoadMethod = URLSTRING + "/loadMethodList/" + pluginName; + // HttpResponse httpResponse = this.httpRequester.sendPost( + // urlForLoadMethod, null, + // makeAccessTockenMap(this.getAccessTocken())); + // System.out.println(httpResponse.getContent()); + // PluginResponseModel pluginResponseModel = (PluginResponseModel) + // MarshalHelper + // .unmarshal(PluginResponseModel.class, httpResponse.getContent()); + // assertNotNull(pluginResponseModel); + // Assert.assertTrue(pluginResponseModel.isSuccess()); + // assertEquals(2, pluginResponseModel.getMethodList().size()); + // } @Test public void testDeletePlugin() throws IOException, JAXBException { @@ -123,22 +125,23 @@ public class PluginControllerTest extends TestBase { Assert.assertTrue(pluginResponseModel.isSuccess()); } - @Test - public void testGetMethodInPlugin() throws IOException { - String url = URLSTRING + "/loadMethods/" + pluginName; - HttpResponse httpResponse = this.httpRequester.sendPost(url, null, - makeAccessTockenMap(this.getAccessTocken())); - Logger.getLogger(PluginControllerTest.class).info( - httpResponse.getContent()); - PluginResponseModel pluginResponseModel = (PluginResponseModel) MarshalHelper - .tryUnmarshal(PluginResponseModel.class, - httpResponse.getContent()); - - assertNotNull(pluginResponseModel); - assertTrue(pluginResponseModel.isSuccess()); - assertTrue(pluginResponseModel.getMethodModels().size() == 2); - - } + // @Test + // public void testGetMethodInPlugin() throws IOException { + // String url = URLSTRING + "/loadMethods/" + pluginName; + // HttpResponse httpResponse = this.httpRequester.sendPost(url, null, + // makeAccessTockenMap(this.getAccessTocken())); + // Logger.getLogger(PluginControllerTest.class).info( + // httpResponse.getContent()); + // PluginResponseModel pluginResponseModel = (PluginResponseModel) + // MarshalHelper + // .tryUnmarshal(PluginResponseModel.class, + // httpResponse.getContent()); + // + // assertNotNull(pluginResponseModel); + // assertTrue(pluginResponseModel.isSuccess()); + // assertTrue(pluginResponseModel.getMethodModels().size() == 2); + // + // } @After public void clear() throws IOException { diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/test/domain/testPlan/Test_TestResultSave.java b/Bench4Q-Master/src/test/java/org/bench4q/master/test/domain/testPlan/Test_TestResultSave.java index a1027741..a5fe1061 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/test/domain/testPlan/Test_TestResultSave.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/test/domain/testPlan/Test_TestResultSave.java @@ -101,9 +101,7 @@ public class Test_TestResultSave extends TestBase_MakeUpTestPlan { testPlanFromRepo); assertEquals(TestPlanStatus.InRunning, testPlan.run()); testPlanScript = getOneTestPlanScript(testPlan); - List resultList = new ArrayList<>(); - resultList.addAll(testPlanScript.doAfterRun()); this.getTestResultSave().update(testPlan, resultList); testPlanFromRepo = this.getTestPlanRepository().getTestPlanBy( 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 new file mode 100644 index 00000000..ccfdfad7 --- /dev/null +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/test/factory/Test_PluginEntityFactory.java @@ -0,0 +1,63 @@ +package org.bench4q.master.test.factory; + +import static org.junit.Assert.*; + +import java.io.File; +import java.io.IOException; +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.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; +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_PluginEntityFactory { + + private PluginEntityFactory pluginEntityFactory; + + public PluginEntityFactory getPluginEntityFactory() { + return pluginEntityFactory; + } + + @Autowired + public void setPluginEntityFactory(PluginEntityFactory pluginEntityFactory) { + this.pluginEntityFactory = pluginEntityFactory; + } + + @Test + public void test_createPluginFormString() throws IOException { + String fileSeparator = System.getProperty("file.separator"); + String filePath = System.getProperty("user.dir") + fileSeparator + + "pluginUI" + fileSeparator + "ui.xml"; + File file = new File(filePath); + String uiContent = FileUtils.readFileToString(file); + PluginUI pluginUI = pluginEntityFactory + .createPluginUIWithOutId(uiContent); + assertNotNull(pluginUI); + assertNotNull(pluginUI.getBehaviorInfos()); + assertNotNull(pluginUI.getPluginInfo()); + PluginInfo pluginInfo = pluginUI.getPluginInfo(); + assertNotNull(pluginInfo.getPluginParamInfos()); + assertEquals(pluginInfo.getPluginParamInfos().size(), 7); + Set pluginParamInfos = pluginInfo + .getPluginParamInfos(); + FieldType fieldType = null; + for (PluginParamInfo pluginParamInfo : pluginParamInfos) { + if (pluginParamInfo.getType() instanceof FieldType) + fieldType = (FieldType) pluginParamInfo.getType(); + } + assertTrue(fieldType.getSize() == 7); + BehaviorInfo behaviorInfo=pluginUI.getBehaviorInfos().iterator().next(); + assertNull(behaviorInfo.getParams()); + } +} diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/test/repository/Test_PluginRepository.java b/Bench4Q-Master/src/test/java/org/bench4q/master/test/repository/Test_PluginRepository.java index 7c39a4f3..24b84e97 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/test/repository/Test_PluginRepository.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/test/repository/Test_PluginRepository.java @@ -2,17 +2,10 @@ package org.bench4q.master.test.repository; import static org.junit.Assert.*; -import java.util.List; - -import org.bench4q.master.domain.entity.plugin.Method; -import org.bench4q.master.domain.entity.plugin.MethodParam; -import org.bench4q.master.domain.entity.plugin.ParamType; -import org.bench4q.master.domain.entity.plugin.Plugin; -import org.bench4q.master.domain.factory.PluginFactory; +import org.bench4q.master.domain.entity.plugin.PluginUI; +import org.bench4q.master.domain.factory.PluginEntityFactory; import org.bench4q.master.domain.repository.PluginRepository; import org.bench4q.master.exception.Bench4QException; -import org.bench4q.share.models.master.plugin.ParamTypeEnum; -import org.bench4q.share.models.master.plugin.PluginModel; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -20,15 +13,14 @@ 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 TestHelper.Test_PlunginHelper; +import TestHelper.Test_PluginHelper; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:service-test-context.xml" }) public class Test_PluginRepository { private PluginRepository pluginRepository; private String pluginName; - private PluginFactory pluginFactory; + private PluginEntityFactory pluginEntityFactory; public PluginRepository getPluginRepository() { return pluginRepository; @@ -39,79 +31,70 @@ public class Test_PluginRepository { this.pluginRepository = pluginRepository; } - public PluginFactory getPluginFactory() { - return pluginFactory; + public PluginEntityFactory getPluginEntityFactory() { + return pluginEntityFactory; } @Autowired - public void setPluginFactory(PluginFactory pluginFactory) { - this.pluginFactory = pluginFactory; + public void setPluginEntityFactory(PluginEntityFactory pluginEntityFactory) { + this.pluginEntityFactory = pluginEntityFactory; } @Before public void setUp() throws Bench4QException { - pluginName = addPlugin(); + this.pluginName = addPlugin("ui.xml"); } @Test public void testGetPlugin() { - assertNotNull(this.getPluginRepository().getPlugin(pluginName)); + assertNotNull(pluginName); + assertNotNull(this.getPluginRepository().getPluginUI(pluginName)); } @Test - public void TestLoadMethodParam() { - Plugin plugin = this.getPluginRepository().getPlugin(pluginName); - MethodParam methodParam = plugin.getPluginMethods().iterator().next() - .getMethodParams().iterator().next(); - - System.out.println(methodParam.getParamType().getClass()); - } - - @Test - public void testGetMethodList() throws Bench4QException { - Plugin plugin = this.getPluginRepository().getPlugin(pluginName); - assertNotNull(plugin); - assertEquals(1, plugin.getPluginMethods().size()); - } - - @Test - public void testLoadPlugin() throws Bench4QException { - + public void testLoadPlugins() throws Bench4QException { int countBeforeInsert = this.getPluginRepository().loadPlugins().size(); - String insertPlugin = addPlugin(); + String name = addPlugin("test.xml"); + assertEquals(countBeforeInsert + 1, this.getPluginRepository() .loadPlugins().size()); - this.getPluginRepository().detach(insertPlugin); + assertTrue(this.getPluginRepository().detach(name)); + } + + @Test + public void testLoadBehaviores() { + assertEquals(2, + this.getPluginRepository().loadBehaviorInfos(this.pluginName) + .size()); + } + + @Test + public void testGetPluginUI() { + assertNotNull(this.getPluginRepository().getPluginUI(pluginName)); } @Test - public void testGetParamTypeByType() throws Bench4QException { - ParamType paramType = this.getPluginRepository().getParamTypeByType( - ParamTypeEnum.Field); - assertNotNull(paramType); - assertEquals(paramType.getType(), ParamTypeEnum.Field); - + public void testDeletePlugin() { + String name = addPlugin("ui.xml"); + assertTrue(this.getPluginRepository().detach(name)); } - @Test - public void testLoadMethodInPlugin(){ - Plugin plugin=this.getPluginRepository().getPlugin(this.pluginName); - List methods=this.getPluginRepository().loadMethodsInPlugin(plugin); - assertNotNull(methods); - assertTrue(methods.size()>0); - - } @After public void clear() throws Bench4QException { this.getPluginRepository().detach(pluginName); } - private String addPlugin() throws Bench4QException { - PluginModel pluginModel = Test_PlunginHelper.createOnePlugin(); - this.getPluginRepository().attatch( - this.getPluginFactory().createPluginEntity(pluginModel)); - return pluginModel.getName(); + private String addPlugin(String fileName) { + try { + PluginUI pluginUI = Test_PluginHelper.createPluginUI(fileName); + boolean add = this.getPluginRepository().attatch(pluginUI); + System.out.println(add); + return pluginUI.getPluginInfo().getName(); + } catch (Exception e) { + e.printStackTrace(); + return null; + } } } 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 26bc9887..54c91cc6 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 @@ -1,127 +1,109 @@ package org.bench4q.master.test.service; -import static org.junit.Assert.*; -import java.io.File; -import java.io.IOException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.UUID; -import javax.xml.bind.JAXBException; -import org.apache.commons.io.FileUtils; -import org.bench4q.master.domain.service.PluginService; -import org.bench4q.master.exception.Bench4QException; -import org.bench4q.share.helper.MarshalHelper; -import org.bench4q.share.models.master.plugin.PluginModel; -import org.junit.After; -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 TestHelper.Test_PlunginHelper; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:service-test-context.xml" }) public class Test_PluginService { - private PluginService pluginService; - private String nameForPlugin; +// private PluginService pluginService; +// private String nameForPlugin; +// +// public PluginService getPluginService() { +// return pluginService; +// } +// +// @Autowired +// public void setPluginService(PluginService pluginService) { +// this.pluginService = pluginService; +// } +// +// @Before +// public void setUp() throws Bench4QException { +// nameForPlugin = addPlugin(); +// } - public PluginService getPluginService() { - return pluginService; - } +// @Test +// public void testPluginModel() throws JAXBException, IOException { +// File file = new File( +// buildSavePath() +// + System.getProperty("file.separator") +// + new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss") +// .format(new Date()) + "plugin.xml"); +// FileUtils.writeStringToFile( +// file, +// MarshalHelper.marshal(PluginModel.class, +// Test_PlunginHelper.createOnePlugin())); +// +// } +// +// @Test +// public void testLoadMethodNameList() throws Bench4QException { +// assertTrue(this.getPluginService().getPluginNameList().size() > 0); +// int methodCount = this.getPluginService() +// .getMethodNameInPlugin(nameForPlugin).size(); +// assertEquals(2, methodCount); +// } - @Autowired - public void setPluginService(PluginService pluginService) { - this.pluginService = pluginService; - } +// @Test +// public void testLoadPluginNameList() throws Bench4QException { +// int pluginCountBefore = this.getPluginService().getPluginNameList() +// .size(); +// String pluginName = addPlugin(); +// System.out.println(this.getPluginService().getPluginNameList().size() +// - pluginCountBefore); +// Assert.assertTrue(this.getPluginService().getPluginNameList().size() == (pluginCountBefore + 1)); +// +// Assert.assertTrue(this.getPluginService().deletePlugin(pluginName)); +// } - @Before - public void setUp() throws Bench4QException { - nameForPlugin = addPlugin(); - } +// @Test +// public void getMethodParam() throws Bench4QException { +// String methodName = this.getPluginService() +// .getMethodNameInPlugin(nameForPlugin).get(0); +// assertTrue(this.getPluginService() +// .getMethodParamModelsInPlugin(nameForPlugin, methodName).size() == 2); +// } - @Test - public void testPluginModel() throws JAXBException, IOException { - File file = new File( - buildSavePath() - + System.getProperty("file.separator") - + new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss") - .format(new Date()) + "plugin.xml"); - FileUtils.writeStringToFile( - file, - MarshalHelper.marshal(PluginModel.class, - Test_PlunginHelper.createOnePlugin())); +// @Test +// public void testDeletePlugin() throws Bench4QException { +// String pluginName = addPlugin(); +// Assert.assertTrue(this.getPluginService().deletePlugin(pluginName)); +// +// } - } +// @Test +// public void testGetMethodInPlugin() { +// assertTrue(this.getPluginService().getMethodsInPlugin(nameForPlugin) +// .size() > 0); +// } +// +// private String addPlugin() throws Bench4QException { +// PluginModel plugin = Test_PlunginHelper.createOnePlugin(); +// plugin.setName("test" + UUID.randomUUID()); +// Assert.assertTrue(this.getPluginService().addPlugin(plugin)); +// return plugin.getName(); +// } - @Test - public void testLoadMethodNameList() throws Bench4QException { - assertTrue(this.getPluginService().getPluginNameList().size() > 0); - int methodCount = this.getPluginService() - .getMethodNameInPlugin(nameForPlugin).size(); - assertEquals(2, methodCount); - } - - @Test - public void testLoadPluginNameList() throws Bench4QException { - int pluginCountBefore = this.getPluginService().getPluginNameList() - .size(); - String pluginName = addPlugin(); - System.out.println(this.getPluginService().getPluginNameList().size() - - pluginCountBefore); - Assert.assertTrue(this.getPluginService().getPluginNameList().size() == (pluginCountBefore + 1)); - - Assert.assertTrue(this.getPluginService().deletePlugin(pluginName)); - } - - @Test - public void getMethodParam() throws Bench4QException { - String methodName = this.getPluginService() - .getMethodNameInPlugin(nameForPlugin).get(0); - assertTrue(this.getPluginService() - .getMethodParamModelsInPlugin(nameForPlugin, methodName).size() == 2); - } - - @Test - public void testDeletePlugin() throws Bench4QException { - String pluginName = addPlugin(); - Assert.assertTrue(this.getPluginService().deletePlugin(pluginName)); - - } - - @Test - public void testGetMethodInPlugin() { - assertTrue(this.getPluginService().getMethodsInPlugin(nameForPlugin) - .size() > 0); - } - - private String addPlugin() throws Bench4QException { - PluginModel plugin = Test_PlunginHelper.createOnePlugin(); - plugin.setName("test" + UUID.randomUUID()); - Assert.assertTrue(this.getPluginService().addPlugin(plugin)); - return plugin.getName(); - } - - @After - public void clear() throws Bench4QException { - this.getPluginService().deletePlugin(nameForPlugin); - } - - private String buildSavePath() { - String dirString = "GUI" + System.getProperty("file.separator") - + System.getProperty("file.separator"); - File dirFile = new File(dirString); - if (!dirFile.exists()) { - dirFile.mkdirs(); - } - return dirString; - } +// @After +// public void clear() throws Bench4QException { +// this.getPluginService().deletePlugin(nameForPlugin); +// } +// +// private String buildSavePath() { +// String dirString = "GUI" + System.getProperty("file.separator") +// + System.getProperty("file.separator"); +// File dirFile = new File(dirString); +// if (!dirFile.exists()) { +// dirFile.mkdirs(); +// } +// return dirString; +// } }