diff --git a/src/main/java/org/bench4q/master/domain/entity/plugin/MethodParam.java b/src/main/java/org/bench4q/master/domain/entity/plugin/MethodParam.java index 99042b73..0a0d308c 100644 --- a/src/main/java/org/bench4q/master/domain/entity/plugin/MethodParam.java +++ b/src/main/java/org/bench4q/master/domain/entity/plugin/MethodParam.java @@ -10,6 +10,7 @@ import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; +import javax.persistence.OneToOne; import javax.persistence.Table; @Entity @@ -63,7 +64,7 @@ public class MethodParam { public void setLable(String lable) { this.lable = lable; } - @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER) + @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER) @JoinColumn(name = "paramTypeId",nullable = false) public ParamType getParamType() { return paramType; diff --git a/src/main/java/org/bench4q/master/domain/entity/plugin/ParamType.java b/src/main/java/org/bench4q/master/domain/entity/plugin/ParamType.java index 4842464d..685e7a78 100644 --- a/src/main/java/org/bench4q/master/domain/entity/plugin/ParamType.java +++ b/src/main/java/org/bench4q/master/domain/entity/plugin/ParamType.java @@ -59,5 +59,4 @@ public class ParamType { } - } diff --git a/src/test/java/TestHelper/TestPlunginHelper.java b/src/test/java/TestHelper/TestPlunginHelper.java new file mode 100644 index 00000000..4130c5d2 --- /dev/null +++ b/src/test/java/TestHelper/TestPlunginHelper.java @@ -0,0 +1,59 @@ +package TestHelper; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +import org.bench4q.share.models.master.plugin.FieldModel; +import org.bench4q.share.models.master.plugin.MethodModel; +import org.bench4q.share.models.master.plugin.MethodParamModel; +import org.bench4q.share.models.master.plugin.MultiFieldModel; +import org.bench4q.share.models.master.plugin.ParamTypeModel; +import org.bench4q.share.models.master.plugin.ParamTypeString; +import org.bench4q.share.models.master.plugin.PluginModel; + +public class TestPlunginHelper { + + public static PluginModel createOnePlugin() { + PluginModel plugin = new PluginModel(); + MethodModel method = new MethodModel(); + MethodParamModel methodParamModel = new MethodParamModel(); + methodParamModel.setLable("input url"); + methodParamModel.setName("url"); + methodParamModel.setParamTypeModel(generateUrlParamTypeModel()); + + MethodParamModel methodParamsParamModel = new MethodParamModel(); + methodParamsParamModel.setName("queryparams"); + methodParamsParamModel.setLable("key=value"); + methodParamsParamModel.setParamTypeModel(generateParamsParamTypeModel()); + Set methodParams = new HashSet(); + methodParams.add(methodParamModel); + 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 ParamTypeModel generateUrlParamTypeModel() { + FieldModel paramPropertyUrl = new FieldModel(); + paramPropertyUrl.setType(ParamTypeString.FIELD); + paramPropertyUrl.setSize(20); + return paramPropertyUrl; + } + + private static ParamTypeModel generateParamsParamTypeModel() { + MultiFieldModel multiFieldModel = new MultiFieldModel(); + multiFieldModel.setSize(20); + multiFieldModel.setType(ParamTypeString.MULTIFIELD); + return multiFieldModel; + } + + +} diff --git a/src/test/java/org/bench4q/master/test/controller/PluginControllerTest.java b/src/test/java/org/bench4q/master/test/controller/PluginControllerTest.java index 3cb653ad..7a056fdb 100644 --- a/src/test/java/org/bench4q/master/test/controller/PluginControllerTest.java +++ b/src/test/java/org/bench4q/master/test/controller/PluginControllerTest.java @@ -1,21 +1,11 @@ package org.bench4q.master.test.controller; import java.io.IOException; -import java.util.HashSet; -import java.util.Set; -import java.util.UUID; import javax.xml.bind.JAXBException; import org.bench4q.share.communication.HttpRequester.HttpResponse; import org.bench4q.share.helper.MarshalHelper; -import org.bench4q.share.models.master.plugin.FieldModel; -import org.bench4q.share.models.master.plugin.MethodModel; -import org.bench4q.share.models.master.plugin.MethodParamModel; -import org.bench4q.share.models.master.plugin.MultiFieldModel; -import org.bench4q.share.models.master.plugin.ParamTypeModel; -import org.bench4q.share.models.master.plugin.ParamTypeString; -import org.bench4q.share.models.master.plugin.PluginModel; import org.bench4q.share.models.master.plugin.PluginResponseModel; import org.junit.Assert; import org.junit.Test; @@ -58,45 +48,4 @@ public class PluginControllerTest extends TestBase { Assert.assertTrue(pluginResponseModel.isSuccess()); } - public PluginModel createOnePlugin() { - PluginModel plugin = new PluginModel(); - MethodModel method = new MethodModel(); - MethodParamModel methodParamModel = new MethodParamModel(); - methodParamModel.setLable("input url"); - methodParamModel.setName("url"); - methodParamModel.setParamTypeModel(generateUrlParamTypeModel()); - - MethodParamModel methodParamsParamModel = new MethodParamModel(); - methodParamsParamModel.setName("queryparams"); - methodParamsParamModel.setLable("key=value"); - methodParamsParamModel.setParamTypeModel(generateParamsParamTypeModel()); - Set methodParams = new HashSet(); - methodParams.add(methodParamModel); - 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 ParamTypeModel generateUrlParamTypeModel() { - FieldModel paramPropertyUrl = new FieldModel(); - paramPropertyUrl.setType(ParamTypeString.FIELD); - paramPropertyUrl.setSize(20); - return paramPropertyUrl; - } - - private ParamTypeModel generateParamsParamTypeModel() { - MultiFieldModel multiFieldModel = new MultiFieldModel(); - multiFieldModel.setSize(20); - multiFieldModel.setType(ParamTypeString.MULTIFIELD); - return multiFieldModel; - } - } diff --git a/src/test/java/org/bench4q/master/test/service/Test_PluginService.java b/src/test/java/org/bench4q/master/test/service/Test_PluginService.java index b92afb91..ede3d325 100644 --- a/src/test/java/org/bench4q/master/test/service/Test_PluginService.java +++ b/src/test/java/org/bench4q/master/test/service/Test_PluginService.java @@ -4,10 +4,7 @@ import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; -import java.util.HashSet; import java.util.List; -import java.util.Set; -import java.util.UUID; import javax.xml.bind.JAXBException; @@ -15,12 +12,6 @@ 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.FieldModel; -import org.bench4q.share.models.master.plugin.MethodModel; -import org.bench4q.share.models.master.plugin.MethodParamModel; -import org.bench4q.share.models.master.plugin.MultiFieldModel; -import org.bench4q.share.models.master.plugin.ParamTypeModel; -import org.bench4q.share.models.master.plugin.ParamTypeString; import org.bench4q.share.models.master.plugin.PluginModel; import org.junit.Assert; import org.junit.Before; @@ -30,6 +21,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import TestHelper.TestPlunginHelper; + @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:service-test-context.xml" }) public class Test_PluginService { @@ -58,19 +51,19 @@ public class Test_PluginService { + new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss") .format(new Date()) + "plugin.xml"); FileUtils.writeStringToFile(file, - MarshalHelper.marshal(PluginModel.class, createOnePlugin())); + MarshalHelper.marshal(PluginModel.class,TestPlunginHelper. createOnePlugin())); } @Test public void testAddPlugin() throws JAXBException, Bench4QException { - Assert.assertTrue(this.getPluginService().addPlugin(createOnePlugin())); + Assert.assertTrue(this.getPluginService().addPlugin(TestPlunginHelper.createOnePlugin())); } @Test public void testDeletePlugin() throws Bench4QException { - PluginModel plugin = createOnePlugin(); + PluginModel plugin =TestPlunginHelper. createOnePlugin(); plugin.setName("ppp"); Assert.assertTrue(this.getPluginService().addPlugin(plugin)); Assert.assertTrue(this.getPluginService() @@ -80,19 +73,19 @@ public class Test_PluginService { @Test public void testLoadPluginNameList() throws Bench4QException { - PluginModel plugin = createOnePlugin(); + PluginModel plugin = TestPlunginHelper.createOnePlugin(); plugin.setName("ppp"); Assert.assertTrue(this.getPluginService().addPlugin(plugin)); List pluginNameList = this.getPluginService() .getPluginNameList(); - Assert.assertTrue(pluginNameList.size() >0); + Assert.assertTrue(pluginNameList.size() > 0); Assert.assertTrue(this.getPluginService() .deletePlugin(plugin.getName())); } @Test public void testGetMethodNameList() throws Bench4QException { - PluginModel plugin = createOnePlugin(); + PluginModel plugin = TestPlunginHelper.createOnePlugin(); plugin.setName("ppp"); Assert.assertTrue(this.getPluginService().addPlugin(plugin)); List methodNameList = this.getPluginService() @@ -102,49 +95,6 @@ public class Test_PluginService { .deletePlugin(plugin.getName())); } - public PluginModel createOnePlugin() { - PluginModel plugin = new PluginModel(); - MethodModel method = new MethodModel(); - MethodParamModel methodParamModel = new MethodParamModel(); - methodParamModel.setLable("input url"); - methodParamModel.setName("url"); - methodParamModel.setParamTypeModel(generateUrlParamTypeModel()); - - MethodParamModel methodParamsParamModel = new MethodParamModel(); - methodParamsParamModel.setName("queryparams"); - methodParamsParamModel.setLable("key=value"); - methodParamsParamModel.setParamTypeModel(generateParamsParamTypeModel()); - Set methodParams = new HashSet(); - methodParams.add(methodParamModel); - 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 ParamTypeModel generateUrlParamTypeModel() { - FieldModel paramPropertyUrl = new FieldModel(); - paramPropertyUrl.setType(ParamTypeString.FIELD); - paramPropertyUrl.setSize(20); - return paramPropertyUrl; - } - - private ParamTypeModel generateParamsParamTypeModel() { - MultiFieldModel multiFieldModel = new MultiFieldModel(); - multiFieldModel.setSize(20); - multiFieldModel.setType(ParamTypeString.MULTIFIELD); - return multiFieldModel; - } - - - private String buildSavePath() { String dirString = "GUI" + System.getProperty("file.separator") + System.getProperty("file.separator");