change the loadPlugin list to set

This commit is contained in:
fanfuxiaoran 2014-03-13 17:47:31 +08:00
parent c249e6143f
commit a022c51949
10 changed files with 111 additions and 44 deletions

View File

@ -2,7 +2,6 @@ package org.bench4q.master;
import java.io.InputStream;
import java.util.Properties;
import org.apache.log4j.Logger;
/**
@ -21,14 +20,10 @@ public class Main {
try {
MasterServer masterServer = new MasterServer(getPortToServe());
masterServer.start();
} catch (Exception e) {
e.printStackTrace();
return;
}
}
public static int getPortToServe() {

View File

@ -0,0 +1,59 @@
package org.bench4q.master;
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

@ -37,6 +37,8 @@ public class PluginController extends BaseController {
PluginResponseModel pluginResponseModel = new PluginResponseModel();
pluginResponseModel.setPluginList(this.getPluginService()
.getPluginNameList());
pluginResponseModel.setSuccess(true);
return pluginResponseModel;
}
@ -53,6 +55,7 @@ public class PluginController extends BaseController {
PluginResponseModel pluginResponseModel = new PluginResponseModel();
pluginResponseModel.setMethodList(this.getPluginService()
.getMethodNameInPlugin(pluginName));
pluginResponseModel.setSuccess(true);
return pluginResponseModel;
}
@ -70,6 +73,7 @@ public class PluginController extends BaseController {
PluginResponseModel pluginResponseModel = new PluginResponseModel();
pluginResponseModel.setMethosMethodParamModels(this.getPluginService()
.getMethodParamModelsInPlugin(pluginName, methodName));
pluginResponseModel.setSuccess(true);
return pluginResponseModel;
}

View File

@ -43,7 +43,7 @@ public class Method {
}
@ManyToOne
@JoinColumn(name = "pluginId")
@JoinColumn(name = "pluginId",nullable = false)
public Plugin getPlugin() {
return plugin;
}

View File

@ -16,15 +16,11 @@ import javax.persistence.Table;
@Entity
@Table(name = "methodParam")
public class MethodParam {
public static final int FIELD = 1;
public static final int NFIELD = 2;
public static final int TABLE = 3;
public static final int CHECKBOX = 4;
private int id;
private Method method;
private String lable;
private String name;
private ParamType paramType;
/*private ParamType paramType;*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ -64,7 +60,7 @@ public class MethodParam {
public void setLable(String lable) {
this.lable = lable;
}
@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
/* @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
@JoinColumn(name = "paramTypeId",nullable = false)
public ParamType getParamType() {
return paramType;
@ -72,6 +68,6 @@ public class MethodParam {
public void setParamType(ParamType paramType) {
this.paramType = paramType;
}
}*/
}

View File

@ -39,8 +39,7 @@ public class Plugin {
this.name = name;
}
@OneToMany(mappedBy = "plugin", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
@OneToMany(mappedBy = "plugin", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
public Set<Method> getPluginMethods() {
return pluginMethods;
}

View File

@ -59,8 +59,8 @@ public class PluginFactory {
methodParam.setLable(methodParamModel.getLable());
methodParam.setName(methodParamModel.getName());
methodParam.setMethod(method);
methodParam.setParamType(createParamTypeEntity(
methodParamModel.getParamTypeModel(), methodParam));
/*methodParam.setParamType(createParamTypeEntity(
methodParamModel.getParamTypeModel(), methodParam));*/
return methodParam;
}
@ -91,8 +91,8 @@ public class PluginFactory {
MethodParamModel methodParamModel = new MethodParamModel();
methodParamModel.setLable(methodParam.getLable());
methodParamModel.setName(methodParam.getName());
methodParamModel.setParamTypeModel(extractParamTypeModel(methodParam
.getParamType()));
// methodParamModel.setParamTypeModel(extractParamTypeModel(methodParam
// .getParamType()));
return methodParamModel;
}

View File

@ -7,6 +7,7 @@ import org.bench4q.master.exception.Bench4QException;
import org.bench4q.master.exception.ExceptionUtils.EntityUniqueAlReadyExistException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Component;

View File

@ -1,6 +1,7 @@
package org.bench4q.master.domain.service;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@ -17,7 +18,7 @@ import org.springframework.stereotype.Component;
@Component
public class PluginService {
private List<Plugin> plugins;
private Set<Plugin> plugins;
private List<String> pluginNameList;
private PluginRepository pluginRepository;
@ -30,8 +31,14 @@ public class PluginService {
this.pluginRepository = pluginRepository;
}
private List<Plugin> getPlugins() throws Bench4QException {
this.plugins = this.getPluginRepository().loadPlugins();
private Set<Plugin> getPlugins() throws Bench4QException {
List<Plugin> loadPluginList = this.getPluginRepository().loadPlugins();
if (loadPluginList != null) {
this.plugins = new HashSet<Plugin>();
for (Plugin plugin : loadPluginList) {
this.plugins.add(plugin);
}
}
return this.plugins;
}

View File

@ -5,14 +5,14 @@ import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import javax.xml.bind.JAXBException;
import org.apache.commons.io.FileUtils;
import org.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;
@ -20,7 +20,6 @@ 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.TestPlunginHelper;
@RunWith(SpringJUnit4ClassRunner.class)
@ -29,6 +28,8 @@ public class Test_PluginService {
private PluginService pluginService;
private String nameForPlugin;
public PluginService getPluginService() {
return pluginService;
}
@ -39,8 +40,8 @@ public class Test_PluginService {
}
@Before
public void setUp() {
public void setUp() throws Bench4QException {
nameForPlugin = addPlugin();
}
@Test
@ -50,37 +51,37 @@ public class Test_PluginService {
+ System.getProperty("file.separator")
+ new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss")
.format(new Date()) + "plugin.xml");
FileUtils.writeStringToFile(file,
MarshalHelper.marshal(PluginModel.class,TestPlunginHelper. createOnePlugin()));
FileUtils.writeStringToFile(
file,
MarshalHelper.marshal(PluginModel.class,
TestPlunginHelper.createOnePlugin()));
}
@Test
public void testAddPlugin() throws JAXBException, Bench4QException {
public void testLoadPluginList() 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().addPlugin(TestPlunginHelper.createOnePlugin()));
Assert.assertTrue(this.getPluginService().deletePlugin(pluginName));
}
@Test
public void testDeletePlugin() throws Bench4QException {
PluginModel plugin =TestPlunginHelper. createOnePlugin();
plugin.setName("ppp");
Assert.assertTrue(this.getPluginService().addPlugin(plugin));
Assert.assertTrue(this.getPluginService()
.deletePlugin(plugin.getName()));
String pluginName = addPlugin();
Assert.assertTrue(this.getPluginService().deletePlugin(pluginName));
}
@Test
public void testLoadPluginNameList() throws Bench4QException {
private String addPlugin() throws Bench4QException {
PluginModel plugin = TestPlunginHelper.createOnePlugin();
plugin.setName("ppp");
plugin.setName("test" + UUID.randomUUID());
Assert.assertTrue(this.getPluginService().addPlugin(plugin));
List<String> pluginNameList = this.getPluginService()
.getPluginNameList();
Assert.assertTrue(pluginNameList.size() > 0);
Assert.assertTrue(this.getPluginService()
.deletePlugin(plugin.getName()));
return plugin.getName();
}
@Test
@ -95,6 +96,11 @@ public class Test_PluginService {
.deletePlugin(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");