chang the methodParam and ParamType relation to be one to one

This commit is contained in:
fanfuxiaoran 2014-03-13 13:32:46 +08:00
parent 45878116db
commit c249e6143f
5 changed files with 69 additions and 111 deletions

View File

@ -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;

View File

@ -59,5 +59,4 @@ public class ParamType {
}
}

View File

@ -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<MethodParamModel> methodParams = new HashSet<MethodParamModel>();
methodParams.add(methodParamModel);
methodParams.add(methodParamsParamModel);
method.setName("get");
method.setMethodParams(methodParams);
Set<MethodModel> methods = new HashSet<MethodModel>();
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;
}
}

View File

@ -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<MethodParamModel> methodParams = new HashSet<MethodParamModel>();
methodParams.add(methodParamModel);
methodParams.add(methodParamsParamModel);
method.setName("get");
method.setMethodParams(methodParams);
Set<MethodModel> methods = new HashSet<MethodModel>();
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;
}
}

View File

@ -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<String> 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<String> 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<MethodParamModel> methodParams = new HashSet<MethodParamModel>();
methodParams.add(methodParamModel);
methodParams.add(methodParamsParamModel);
method.setName("get");
method.setMethodParams(methodParams);
Set<MethodModel> methods = new HashSet<MethodModel>();
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");