change the Serialization of paramTypeModel

This commit is contained in:
fanfuxiaoran 2014-04-18 18:16:31 +08:00
parent 6f31b2a49c
commit 97c4a31855
12 changed files with 278 additions and 142 deletions

View File

@ -4,6 +4,9 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import javax.xml.bind.JAXBException;
import org.apache.log4j.Logger;
import org.bench4q.master.domain.entity.plugin.BehaviorInfo; import org.bench4q.master.domain.entity.plugin.BehaviorInfo;
import org.bench4q.master.domain.entity.plugin.CheckBoxType; import org.bench4q.master.domain.entity.plugin.CheckBoxType;
import org.bench4q.master.domain.entity.plugin.ChoiceType; import org.bench4q.master.domain.entity.plugin.ChoiceType;
@ -16,6 +19,8 @@ import org.bench4q.master.domain.entity.plugin.PluginInfo;
import org.bench4q.master.domain.entity.plugin.PluginUI; import org.bench4q.master.domain.entity.plugin.PluginUI;
import org.bench4q.master.domain.entity.plugin.RadioButtonType; import org.bench4q.master.domain.entity.plugin.RadioButtonType;
import org.bench4q.master.domain.entity.plugin.TableType; import org.bench4q.master.domain.entity.plugin.TableType;
import org.bench4q.master.exception.ExceptionLog;
import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.master.plugin.BehaviorInfoModel; import org.bench4q.share.models.master.plugin.BehaviorInfoModel;
import org.bench4q.share.models.master.plugin.CheckBoxModel; import org.bench4q.share.models.master.plugin.CheckBoxModel;
import org.bench4q.share.models.master.plugin.ChoiceModel; import org.bench4q.share.models.master.plugin.ChoiceModel;
@ -23,16 +28,30 @@ import org.bench4q.share.models.master.plugin.ComboModel;
import org.bench4q.share.models.master.plugin.FieldModel; import org.bench4q.share.models.master.plugin.FieldModel;
import org.bench4q.share.models.master.plugin.NFieldModel; import org.bench4q.share.models.master.plugin.NFieldModel;
import org.bench4q.share.models.master.plugin.ParamInfoModel; import org.bench4q.share.models.master.plugin.ParamInfoModel;
import org.bench4q.share.models.master.plugin.ParamTypeModel; import org.bench4q.share.models.master.plugin.ParamTypeClassAndContnet;
import org.bench4q.share.models.master.plugin.PluginInfoModel; import org.bench4q.share.models.master.plugin.PluginInfoModel;
import org.bench4q.share.models.master.plugin.PluginUIModel; import org.bench4q.share.models.master.plugin.PluginUIModel;
import org.bench4q.share.models.master.plugin.RadioButtonModel; import org.bench4q.share.models.master.plugin.RadioButtonModel;
import org.bench4q.share.models.master.plugin.TableModel; import org.bench4q.share.models.master.plugin.TableModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component
public class PluginDomainFactory { public class PluginDomainFactory {
private ParamTypeClassAndContentFactory paramTypeClassAndContentFactory;
private Logger logger = Logger.getLogger(PluginDomainFactory.class);
public ParamTypeClassAndContentFactory getParamTypeClassAndContentFactory() {
return paramTypeClassAndContentFactory;
}
@Autowired
public void setParamTypeClassAndContentFactory(
ParamTypeClassAndContentFactory paramTypeClassAndContentFactory) {
this.paramTypeClassAndContentFactory = paramTypeClassAndContentFactory;
}
public PluginUIModel createPluginUIModelwithOutBehaviors(PluginUI pluginUI) { public PluginUIModel createPluginUIModelwithOutBehaviors(PluginUI pluginUI) {
PluginUIModel pluginUIModel = new PluginUIModel(); PluginUIModel pluginUIModel = new PluginUIModel();
pluginUIModel.setPluginInfoModel(createPluginInfoModel(pluginUI pluginUIModel.setPluginInfoModel(createPluginInfoModel(pluginUI
@ -49,6 +68,46 @@ public class PluginDomainFactory {
return pluginInfoModel; return pluginInfoModel;
} }
private ParamInfoModel createParamInfoModel(ParamInfo paramInfo) {
ParamInfoModel paramInfoModel = new ParamInfoModel();
paramInfoModel.setLable(paramInfo.getLable());
paramInfoModel.setName(paramInfo.getName());
try {
paramInfoModel
.setParamTypeClassAndContnet(paramTypeClassAndContentFactory
.createParamTypeClassAndContnet(paramInfo));
paramInfoModel.setType(getParamTypeByParamClass(paramInfoModel
.getParamTypeClassAndContnet().getParamTypeClass()
.toString()));
} catch (JAXBException e) {
// TODO Auto-generated catch block
logger.info(ExceptionLog.getStackTrace(e));
return null;
}
return paramInfoModel;
}
private String getParamTypeByParamClass(String paramTypeClass) {
return paramTypeClass = paramTypeClass.substring(
paramTypeClass.lastIndexOf(".") + 1, paramTypeClass.length());
}
private List<ParamInfoModel> createParamInfoModels(
Set<? extends ParamInfo> paramInfos) {
List<ParamInfoModel> paramInfoModels = new LinkedList<ParamInfoModel>();
for (ParamInfo paramInfo : paramInfos) {
ParamInfoModel paramInfoModel = createParamInfoModel(paramInfo);
if (paramInfo == null) {
return null;
}
paramInfoModels.add(paramInfoModel);
}
return paramInfoModels;
}
public List<BehaviorInfoModel> createBehaviorInfoModels( public List<BehaviorInfoModel> createBehaviorInfoModels(
Set<BehaviorInfo> behaviorInfos) { Set<BehaviorInfo> behaviorInfos) {
List<BehaviorInfoModel> behaviorInfoModels = new LinkedList<BehaviorInfoModel>(); List<BehaviorInfoModel> behaviorInfoModels = new LinkedList<BehaviorInfoModel>();
@ -67,112 +126,87 @@ public class PluginDomainFactory {
} }
private List<ParamInfoModel<? extends ParamTypeModel>> createParamInfoModels(
Set<? extends ParamInfo> paramInfos) {
List<ParamInfoModel<? extends ParamTypeModel>> paramInfoModels = new LinkedList<ParamInfoModel<? extends ParamTypeModel>>();
ParamInfoFacoty paramInfoFacoty =new ParamInfoFacoty();
for (ParamInfo paramInfo : paramInfos) {
paramInfoModels
.add(paramInfoFacoty.createParamTypeModel(paramInfo));
}
return paramInfoModels;
}
} }
class ParamInfoFacoty { @Component
class ParamTypeClassAndContentFactory {
public ParamInfoModel<? extends ParamTypeModel> createParamTypeModel( public ParamTypeClassAndContnet createParamTypeClassAndContnet(
ParamInfo paramInfo) { ParamInfo paramInfo) throws JAXBException {
ParamType paramType = paramInfo.getType(); ParamType paramType = paramInfo.getType();
if (paramType instanceof FieldType) if (paramType instanceof FieldType) {
return createFieldModel((FieldType) paramType, paramInfo); String content = MarshalHelper.marshal(FieldModel.class,
else if (paramType instanceof NFieldType) createFieldModel((FieldType) paramType));
return createNFieldModel((NFieldType) paramType, paramInfo); return new ParamTypeClassAndContnet(FieldModel.class, content);
else if (paramType instanceof TableType) }
return createTableModel((TableType) paramType, paramInfo);
else if (paramType instanceof CheckBoxType) else if (paramType instanceof NFieldType) {
return createCheckBoxModel((CheckBoxType) paramType, paramInfo); String content = MarshalHelper.marshal(NFieldModel.class,
else if (paramType instanceof ComboType) createNFieldModel((NFieldType) paramType));
return createComboModel((ComboType) paramType, paramInfo); return new ParamTypeClassAndContnet(NFieldModel.class, content);
else if (paramType instanceof RadioButtonType) } else if (paramType instanceof TableType) {
return createRadioButton((RadioButtonType) paramType, paramInfo); String content = MarshalHelper.marshal(TableModel.class,
else createTableModel((TableType) paramType));
return new ParamTypeClassAndContnet(TableModel.class, content);
} else if (paramType instanceof CheckBoxType) {
String content = MarshalHelper.marshal(CheckBoxModel.class,
createCheckBoxModel((CheckBoxType) paramType));
return new ParamTypeClassAndContnet(CheckBoxModel.class, content);
} else if (paramType instanceof ComboType) {
String content = MarshalHelper.marshal(ComboModel.class,
createComboModel((ComboType) paramType));
return new ParamTypeClassAndContnet(ComboModel.class, content);
} else if (paramType instanceof RadioButtonType) {
String content = MarshalHelper.marshal(RadioButtonModel.class,
createRadioButton((RadioButtonType) paramType));
return new ParamTypeClassAndContnet(RadioButtonModel.class, content);
} else
return null; return null;
} }
private ParamInfoModel<FieldModel> createFieldModel(FieldType fieldType, private FieldModel createFieldModel(FieldType fieldType) {
ParamInfo paramInfo) {
ParamInfoModel<FieldModel> paramInfoModel = new ParamInfoModel<>();
FieldModel fieldModel = new FieldModel(); FieldModel fieldModel = new FieldModel();
fieldModel.setSize(fieldType.getSize()); fieldModel.setSize(fieldType.getSize());
fieldModel.setText(fieldType.getText()); fieldModel.setText(fieldType.getText());
paramInfoModel.setLable(paramInfo.getLable());
paramInfo.setName(paramInfo.getName()); return fieldModel;
return paramInfoModel;
} }
private ParamInfoModel<NFieldModel> createNFieldModel( private NFieldModel createNFieldModel(NFieldType nFieldType) {
NFieldType nFieldType, ParamInfo paramInfo) {
ParamInfoModel<NFieldModel> paramInfoModel = new ParamInfoModel<NFieldModel>();
paramInfoModel.setName(paramInfo.getName());
paramInfoModel.setLable(paramInfo.getLable());
NFieldModel nFieldModel = new NFieldModel(); NFieldModel nFieldModel = new NFieldModel();
nFieldModel.setSize(nFieldType.getSize()); nFieldModel.setSize(nFieldType.getSize());
nFieldModel.setText(nFieldType.getText()); nFieldModel.setText(nFieldType.getText());
paramInfoModel.setParamTypeModel(nFieldModel); return nFieldModel;
return paramInfoModel;
} }
private ParamInfoModel<TableModel> createTableModel(TableType tableType, private TableModel createTableModel(TableType tableType) {
ParamInfo paramInfo) {
ParamInfoModel<TableModel> paramInfoModel = new ParamInfoModel<TableModel>();
paramInfoModel.setName(paramInfo.getName());
paramInfoModel.setLable(paramInfo.getLable());
TableModel tableModel = new TableModel(); TableModel tableModel = new TableModel();
tableModel.setCols(tableType.getCols()); tableModel.setCols(tableType.getCols());
paramInfoModel.setParamTypeModel(tableModel); return tableModel;
return paramInfoModel;
} }
private ParamInfoModel<CheckBoxModel> createCheckBoxModel( private CheckBoxModel createCheckBoxModel(CheckBoxType checkBoxType) {
CheckBoxType checkBoxType, ParamInfo paramInfo) {
ParamInfoModel<CheckBoxModel> paramInfoModel = new ParamInfoModel<CheckBoxModel>();
paramInfoModel.setName(paramInfo.getName());
paramInfoModel.setLable(paramInfo.getLable());
CheckBoxModel checkBoxModel = new CheckBoxModel(); CheckBoxModel checkBoxModel = new CheckBoxModel();
checkBoxModel.setChoiceModels(createChoiceModels(checkBoxType checkBoxModel.setChoiceModels(createChoiceModels(checkBoxType
.getChoiceList())); .getChoiceList()));
paramInfo.setType(checkBoxType); return checkBoxModel;
return paramInfoModel;
} }
private ParamInfoModel<ComboModel> createComboModel(ComboType comboType, private ComboModel createComboModel(ComboType comboType) {
ParamInfo paramInfo) {
ParamInfoModel<ComboModel> paramInfoModel = new ParamInfoModel<ComboModel>();
paramInfoModel.setName(paramInfo.getName());
paramInfoModel.setLable(paramInfo.getLable());
ComboModel comboModel = new ComboModel(); ComboModel comboModel = new ComboModel();
comboModel comboModel
.setChoiceModels(createChoiceModels(comboType.getChoiceList())); .setChoiceModels(createChoiceModels(comboType.getChoiceList()));
paramInfoModel.setParamTypeModel(comboModel); return comboModel;
return paramInfoModel;
} }
private ParamInfoModel<RadioButtonModel> createRadioButton( private RadioButtonModel createRadioButton(RadioButtonType radioButtonType) {
RadioButtonType radioButtonType, ParamInfo paramInfo) {
ParamInfoModel<RadioButtonModel> paramInfoModel = new ParamInfoModel<RadioButtonModel>();
paramInfoModel.setLable(paramInfo.getLable());
paramInfoModel.setName(paramInfo.getName());
RadioButtonModel radioButtonModel = new RadioButtonModel(); RadioButtonModel radioButtonModel = new RadioButtonModel();
radioButtonModel.setChoiceModels(createChoiceModels(radioButtonType radioButtonModel.setChoiceModels(createChoiceModels(radioButtonType
.getChoices())); .getChoices()));
paramInfoModel.setParamTypeModel(radioButtonModel); return radioButtonModel;
return paramInfoModel;
} }

View File

@ -141,7 +141,7 @@ public class PluginEntityFactory {
if (XmlParseHelper.getAttribute(element, "name") == null) if (XmlParseHelper.getAttribute(element, "name") == null)
return null; return null;
PluginParamInfo pluginParamInfo = new PluginParamInfo(); PluginParamInfo pluginParamInfo = new PluginParamInfo();
pluginParamInfo.setLable(XmlParseHelper.getAttribute(element, "lable")); pluginParamInfo.setLable(XmlParseHelper.getAttribute(element, "label"));
pluginParamInfo.setName(XmlParseHelper.getAttribute(element, "name")); pluginParamInfo.setName(XmlParseHelper.getAttribute(element, "name"));
ParamTypeFactory paramTypeFactory = new ParamTypeFactory(); ParamTypeFactory paramTypeFactory = new ParamTypeFactory();
pluginParamInfo.setType(paramTypeFactory pluginParamInfo.setType(paramTypeFactory

View File

@ -23,7 +23,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:service-test-context.xml" }) @ContextConfiguration(locations = { "classpath:service-test-context.xml" })
public class PluginControllerTest extends TestBase { public class PluginControllerTest extends TestBase {
@ -69,7 +68,7 @@ public class PluginControllerTest extends TestBase {
@Test @Test
public void testAddPlugin() throws JAXBException, IOException { public void testAddPlugin() throws JAXBException, IOException {
this.test_PluginHelper.clearPlugin(pluginName); this.getPluginService().deletePlugin(pluginName);
this.setAccessTocken(this.login()); this.setAccessTocken(this.login());
String url = URLSTRING + "/addPlugin"; String url = URLSTRING + "/addPlugin";
File file = new File(Test_PluginHelper.filePath(fileName)); File file = new File(Test_PluginHelper.filePath(fileName));
@ -81,16 +80,15 @@ public class PluginControllerTest extends TestBase {
httpResponse.getContent()); httpResponse.getContent());
Assert.assertNotNull(pluginResponseModel); Assert.assertNotNull(pluginResponseModel);
Assert.assertTrue(pluginResponseModel.isSuccess()); Assert.assertTrue(pluginResponseModel.isSuccess());
this.test_PluginHelper.clearPlugin(pluginName); this.getPluginService().deletePlugin(pluginName);
} }
@Test @Test
public void testLoadPluginNameList() throws JAXBException, IOException { public void testLoadPluginNameList() throws JAXBException, IOException {
this.test_PluginHelper.clearPlugin(pluginName); this.getPluginService().deletePlugin(pluginName);
String url = URLSTRING + "/loadPluginNameList"; String url = URLSTRING + "/loadPluginNameList";
int insertBefore = test_PluginHelper.getPluginRepository() int insertBefore = this.getPluginService().loadPluginUIs().size();
.loadPlugins().size(); this.test_PluginHelper.addPlugin("ui.xml", pluginService, pluginName);
test_PluginHelper.addPlugin(fileName);
HttpResponse httpResponse = this.httpRequester.sendPost(url, null, HttpResponse httpResponse = this.httpRequester.sendPost(url, null,
makeAccessTockenMap(this.getAccessTocken())); makeAccessTockenMap(this.getAccessTocken()));
PluginResponseModel pluginResponseModel = (PluginResponseModel) MarshalHelper PluginResponseModel pluginResponseModel = (PluginResponseModel) MarshalHelper
@ -101,15 +99,15 @@ public class PluginControllerTest extends TestBase {
Assert.assertTrue(pluginResponseModel.getPluginList().size() > 0); Assert.assertTrue(pluginResponseModel.getPluginList().size() > 0);
assertEquals(insertBefore + 1, pluginResponseModel.getPluginList() assertEquals(insertBefore + 1, pluginResponseModel.getPluginList()
.size()); .size());
test_PluginHelper.clearPlugin(pluginName); this.getPluginService().deletePlugin(pluginName);
} }
@Test @Test
public void testLoadPluginList() throws IOException, JAXBException { public void testLoadPluginList() throws IOException, JAXBException {
this.getTest_PluginHelper().clearPlugin(pluginName); this.getPluginService().deletePlugin(pluginName);
int insertBefore = test_PluginHelper.getPluginRepository() int insertBefore = this.getPluginService().loadPluginUIs().size();
.loadPlugins().size(); this.getTest_PluginHelper().addPlugin(fileName,
this.getTest_PluginHelper().addPlugin(fileName); this.getPluginService(), pluginName);
String url = URLSTRING + "/loadPluginList"; String url = URLSTRING + "/loadPluginList";
HttpResponse httpResponse = this.httpRequester.sendPost(url, null, HttpResponse httpResponse = this.httpRequester.sendPost(url, null,
makeAccessTockenMap(this.getAccessTocken())); makeAccessTockenMap(this.getAccessTocken()));
@ -119,13 +117,14 @@ public class PluginControllerTest extends TestBase {
assertNotNull(pluginResponseModel); assertNotNull(pluginResponseModel);
assertEquals(insertBefore + 1, pluginResponseModel.getPluginUIModels() assertEquals(insertBefore + 1, pluginResponseModel.getPluginUIModels()
.size()); .size());
this.getTest_PluginHelper().clearPlugin(pluginName); this.getPluginService().deletePlugin(pluginName);
} }
@Test @Test
public void testDeletePlugin() throws IOException { public void testDeletePlugin() throws IOException {
this.getTest_PluginHelper().clearPlugin(pluginName); this.getPluginService().deletePlugin(pluginName);
this.getTest_PluginHelper().addPlugin(fileName); this.getTest_PluginHelper().addPlugin(fileName,
this.getPluginService(), pluginName);
String url = URLSTRING + "/deletePlugin" + "/" + this.pluginName; String url = URLSTRING + "/deletePlugin" + "/" + this.pluginName;
HttpResponse httpResponse = this.httpRequester.sendPost(url, null, HttpResponse httpResponse = this.httpRequester.sendPost(url, null,
makeAccessTockenMap(this.getAccessTocken())); makeAccessTockenMap(this.getAccessTocken()));
@ -139,7 +138,8 @@ public class PluginControllerTest extends TestBase {
@Test @Test
public void testGetBehaviors() throws IOException { public void testGetBehaviors() throws IOException {
this.getTest_PluginHelper().addPlugin(fileName); this.getTest_PluginHelper().addPlugin(fileName,
this.getPluginService(), pluginName);
String url = URLSTRING + "/loadBehaviors/" + this.pluginName; String url = URLSTRING + "/loadBehaviors/" + this.pluginName;
HttpResponse httpResponse = this.httpRequester.sendPost(url, null, HttpResponse httpResponse = this.httpRequester.sendPost(url, null,
makeAccessTockenMap(this.getAccessTocken())); makeAccessTockenMap(this.getAccessTocken()));
@ -153,7 +153,8 @@ public class PluginControllerTest extends TestBase {
@Test @Test
public void testGetParamType() throws IOException, JAXBException { public void testGetParamType() throws IOException, JAXBException {
this.getTest_PluginHelper().addPlugin(fileName); this.getTest_PluginHelper().addPlugin(fileName,
this.getPluginService(), pluginName);
String url = URLSTRING + "/loadPluginList"; String url = URLSTRING + "/loadPluginList";
Map<String, String> properties = makeAccessTockenMap(this Map<String, String> properties = makeAccessTockenMap(this
.getAccessTocken()); .getAccessTocken());
@ -161,19 +162,20 @@ public class PluginControllerTest extends TestBase {
HttpResponse httpResponse = this.httpRequester.sendPost(url, null, HttpResponse httpResponse = this.httpRequester.sendPost(url, null,
properties); properties);
System.out.println(httpResponse.getContent()); System.out.println(httpResponse.getContent());
// Gson gson = new Gson(); // Gson gson = new Gson();
// PluginResponseModel pluginResponseModel = gson.fromJson( // PluginResponseModel pluginResponseModel = gson.fromJson(
// httpResponse.getContent(), PluginResponseModel.class); // httpResponse.getContent(), PluginResponseModel.class);
// assertNotNull(pluginResponseModel); // assertNotNull(pluginResponseModel);
// PluginInfoModel pluginInfoModel = pluginResponseModel // PluginInfoModel pluginInfoModel = pluginResponseModel
// .getPluginUIModels().get(0).getPluginInfoModel(); // .getPluginUIModels().get(0).getPluginInfoModel();
// int count = 0; // int count = 0;
// for (@SuppressWarnings("rawtypes") // for (@SuppressWarnings("rawtypes")
// ParamInfoModel paramInfoModel : pluginInfoModel.getParamInfoModels()) { // ParamInfoModel paramInfoModel : pluginInfoModel.getParamInfoModels())
// if (paramInfoModel.getParamTypeModel() instanceof FieldModel) // {
// count++; // if (paramInfoModel.getParamTypeModel() instanceof FieldModel)
// } // count++;
// assertEquals(this.fieldParamCount, count); // }
// assertEquals(this.fieldParamCount, count);
} }

View File

@ -2,13 +2,17 @@ package org.bench4q.master.test.factory;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.util.List;
import java.util.Set; import java.util.Set;
import javax.xml.bind.JAXBException;
import org.apache.log4j.Logger;
import org.bench4q.master.domain.entity.plugin.BehaviorInfo; import org.bench4q.master.domain.entity.plugin.BehaviorInfo;
import org.bench4q.master.domain.entity.plugin.PluginUI; import org.bench4q.master.domain.entity.plugin.PluginUI;
import org.bench4q.master.domain.factory.PluginDomainFactory; import org.bench4q.master.domain.factory.PluginDomainFactory;
import org.bench4q.master.domain.repository.PluginRepository; import org.bench4q.master.domain.repository.PluginRepository;
import org.bench4q.master.test.testHelper.Test_PluginHelper; import org.bench4q.master.test.testHelper.Test_PluginHelper;
import org.bench4q.share.models.master.plugin.ParamInfoModel;
import org.bench4q.share.models.master.plugin.PluginUIModel; import org.bench4q.share.models.master.plugin.PluginUIModel;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
@ -18,12 +22,14 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:service-test-context.xml" }) @ContextConfiguration(locations = { "classpath:service-test-context.xml" })
public class Test_PluginDomainFactory extends Test_PluginHelper { public class Test_PluginDomainFactory extends Test_PluginHelper {
private PluginDomainFactory pluginDomainFactory; private PluginDomainFactory pluginDomainFactory;
private PluginRepository pluginRepository; private PluginRepository pluginRepository;
private String pluginName; private String pluginName;
private Logger logger = Logger.getLogger(Test_PluginDomainFactory.class);
public PluginDomainFactory getPluginDomainFactory() { public PluginDomainFactory getPluginDomainFactory() {
return pluginDomainFactory; return pluginDomainFactory;
@ -45,7 +51,7 @@ public class Test_PluginDomainFactory extends Test_PluginHelper {
@Before @Before
public void setUp() { public void setUp() {
this.pluginName = addPlugin("ui.xml"); this.pluginName = addPlugin("ui.xml", pluginRepository);
} }
@After @After
@ -57,6 +63,7 @@ public class Test_PluginDomainFactory extends Test_PluginHelper {
public void test_createPluginUIModel() { public void test_createPluginUIModel() {
assertNotNull(pluginName); assertNotNull(pluginName);
PluginUI pluginUI = this.getPluginRepository().getPluginUI(pluginName); PluginUI pluginUI = this.getPluginRepository().getPluginUI(pluginName);
PluginUIModel pluginUIModel = this.getPluginDomainFactory() PluginUIModel pluginUIModel = this.getPluginDomainFactory()
.createPluginUIModelwithOutBehaviors(pluginUI); .createPluginUIModelwithOutBehaviors(pluginUI);
assertNotNull(pluginUIModel); assertNotNull(pluginUIModel);
@ -66,6 +73,29 @@ public class Test_PluginDomainFactory extends Test_PluginHelper {
} }
@Test
public void test_createParamInfoModel() throws JAXBException {
assertNotNull(pluginName);
PluginUI pluginUI = this.getPluginRepository().getPluginUI(pluginName);
PluginUIModel pluginUIModel = this.getPluginDomainFactory()
.createPluginUIModelwithOutBehaviors(pluginUI);
assertNotNull(pluginUIModel);
List<ParamInfoModel> paramInfoModels = pluginUIModel
.getPluginInfoModel().getParamInfoModels();
int count = 0;
for (ParamInfoModel paramInfoModel : paramInfoModels) {
if (paramInfoModel.getParamTypeClassAndContnet()
.getParamTypeClass().toString().contains("CheckBoxModel")) {
logger.info( paramInfoModel
.getParamTypeClassAndContnet().getParamTypeClass());
count++;
}
}
System.out.println(count);
}
@Test @Test
public void test_CreateBehaviorModels() { public void test_CreateBehaviorModels() {
assertNotNull(pluginName); assertNotNull(pluginName);

View File

@ -2,6 +2,8 @@ package org.bench4q.master.test.repository;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import javax.xml.bind.JAXBException;
import org.bench4q.master.domain.factory.PluginEntityFactory; import org.bench4q.master.domain.factory.PluginEntityFactory;
import org.bench4q.master.domain.repository.PluginRepository; import org.bench4q.master.domain.repository.PluginRepository;
import org.bench4q.master.exception.Bench4QException; import org.bench4q.master.exception.Bench4QException;
@ -14,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:service-test-context.xml" }) @ContextConfiguration(locations = { "classpath:service-test-context.xml" })
public class Test_PluginRepository extends Test_PluginHelper { public class Test_PluginRepository extends Test_PluginHelper {
@ -41,7 +44,7 @@ public class Test_PluginRepository extends Test_PluginHelper {
@Before @Before
public void setUp() throws Bench4QException { public void setUp() throws Bench4QException {
this.pluginName = addPlugin("ui.xml"); this.pluginName = addPlugin("ui.xml", this.pluginRepository);
} }
@Test @Test
@ -51,10 +54,11 @@ public class Test_PluginRepository extends Test_PluginHelper {
} }
@Test @Test
public void testLoadPlugins() throws Bench4QException { public void testLoadPlugins() throws Bench4QException, JAXBException {
this.clearPlugin(pluginName, this.pluginRepository);
int countBeforeInsert = this.getPluginRepository().loadPlugins().size(); int countBeforeInsert = this.getPluginRepository().loadPlugins().size();
String name = addPlugin("test.xml"); System.out.println(countBeforeInsert);
String name = addPlugin("ui.xml", this.pluginRepository);
assertEquals(countBeforeInsert + 1, this.getPluginRepository() assertEquals(countBeforeInsert + 1, this.getPluginRepository()
.loadPlugins().size()); .loadPlugins().size());
assertTrue(this.getPluginRepository().detach(name)); assertTrue(this.getPluginRepository().detach(name));
@ -75,7 +79,7 @@ public class Test_PluginRepository extends Test_PluginHelper {
@Test @Test
public void testDeletePlugin() { public void testDeletePlugin() {
String name = addPlugin("ui.xml"); String name = addPlugin("ui.xml", this.pluginRepository);
assertTrue(this.getPluginRepository().detach(name)); assertTrue(this.getPluginRepository().detach(name));
} }

View File

@ -6,6 +6,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.bench4q.master.domain.repository.PluginRepository;
import org.bench4q.master.domain.service.PluginService; import org.bench4q.master.domain.service.PluginService;
import org.bench4q.master.test.testHelper.Test_PluginHelper; import org.bench4q.master.test.testHelper.Test_PluginHelper;
import org.junit.After; import org.junit.After;
@ -22,6 +23,8 @@ public class Test_PluginService extends Test_PluginHelper {
private PluginService pluginService; private PluginService pluginService;
private String pluginName; private String pluginName;
private PluginRepository pluginRepository;
public PluginService getPluginService() { public PluginService getPluginService() {
return pluginService; return pluginService;
} }
@ -31,6 +34,15 @@ public class Test_PluginService extends Test_PluginHelper {
this.pluginService = pluginService; this.pluginService = pluginService;
} }
public PluginRepository getPluginRepository() {
return pluginRepository;
}
@Autowired
public void setPluginRepository(PluginRepository pluginRepository) {
this.pluginRepository = pluginRepository;
}
@Before @Before
public void setUp() { public void setUp() {
this.pluginName = "CsvProvider"; this.pluginName = "CsvProvider";

View File

@ -7,24 +7,11 @@ import org.apache.commons.io.FileUtils;
import org.bench4q.master.domain.entity.plugin.PluginUI; import org.bench4q.master.domain.entity.plugin.PluginUI;
import org.bench4q.master.domain.factory.PluginEntityFactory; import org.bench4q.master.domain.factory.PluginEntityFactory;
import org.bench4q.master.domain.repository.PluginRepository; import org.bench4q.master.domain.repository.PluginRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.bench4q.master.domain.service.PluginService;
import org.springframework.stereotype.Component;
@Component public class Test_PluginHelper {
public class Test_PluginHelper {
private PluginRepository pluginRepository; public static String filePath(String fileName) {
public PluginRepository getPluginRepository() {
return pluginRepository;
}
@Autowired
public void setPluginRepository(PluginRepository pluginRepository) {
this.pluginRepository = pluginRepository;
}
public static String filePath(String fileName) {
String fileSeparator = System.getProperty("file.separator"); String fileSeparator = System.getProperty("file.separator");
String filePath = System.getProperty("user.dir") + fileSeparator String filePath = System.getProperty("user.dir") + fileSeparator
@ -32,7 +19,7 @@ public class Test_PluginHelper {
return filePath; return filePath;
} }
public PluginUI createPluginUI(String fileName) throws IOException { public PluginUI createPluginUI(String fileName) throws IOException {
PluginEntityFactory pluginEntityFactory = new PluginEntityFactory(); PluginEntityFactory pluginEntityFactory = new PluginEntityFactory();
String filePath = filePath(fileName); String filePath = filePath(fileName);
File file = new File(filePath); File file = new File(filePath);
@ -42,10 +29,10 @@ public class Test_PluginHelper {
return pluginUI; return pluginUI;
} }
public String addPlugin(String fileName) { public String addPlugin(String fileName, PluginRepository pluginRepository) {
try { try {
PluginUI pluginUI = createPluginUI(fileName); PluginUI pluginUI = createPluginUI(fileName);
this.pluginRepository.attatch(pluginUI); pluginRepository.attatch(pluginUI);
return pluginUI.getPluginInfo().getName(); return pluginUI.getPluginInfo().getName();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -54,8 +41,22 @@ public class Test_PluginHelper {
} }
public void clearPlugin(String pluginName) { public String addPlugin(String fileName, PluginService pluginService,
this.getPluginRepository().detach(pluginName); String pluginName) {
try {
String pluginUI = FileUtils.readFileToString(new File(
filePath(fileName)));
pluginService.addPlugin(pluginUI);
return pluginName;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public void clearPlugin(String pluginName, PluginRepository pluginRepository) {
pluginRepository.detach(pluginName);
} }
} }

View File

@ -8,7 +8,7 @@
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"> http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">
<context:component-scan <context:component-scan
base-package="org.bench4q.master.test.testHelper,org.bench4q.master.domain,org.bench4q.master.infrastructure,org.bench4q.master.report, org.bench4q.master.helper, org.bench4q.master.testplan, org.bench4q.share, org.bench4q.master.domain.factory, org.bench4q.master.domain.repository" /> base-package="org.bench4q.master.domain,org.bench4q.master.infrastructure,org.bench4q.master.report, org.bench4q.master.helper, org.bench4q.master.testplan, org.bench4q.share, org.bench4q.master.domain.factory, org.bench4q.master.domain.repository" />
<mvc:annotation-driven /> <mvc:annotation-driven />
<task:annotation-driven /> <task:annotation-driven />
</beans> </beans>

View File

@ -10,19 +10,19 @@ import com.sun.xml.internal.txw2.annotation.XmlElement;
@XmlRootElement @XmlRootElement
public class BehaviorInfoModel { public class BehaviorInfoModel {
private List<ParamInfoModel<? extends ParamTypeModel>> paramInfoModels; private List<ParamInfoModel> paramInfoModels;
private String behaviorType; private String behaviorType;
private String name; private String name;
@XmlElementWrapper @XmlElementWrapper
@XmlElement @XmlElement
public List<ParamInfoModel<? extends ParamTypeModel>> getParamInfoModels() { public List<ParamInfoModel> getParamInfoModels() {
return paramInfoModels; return paramInfoModels;
} }
public void setParamInfoModels( public void setParamInfoModels(
List<ParamInfoModel<? extends ParamTypeModel>> paramInfoModels) { List<ParamInfoModel> paramInfoModels) {
this.paramInfoModels = paramInfoModels; this.paramInfoModels = paramInfoModels;
} }

View File

@ -1,16 +1,17 @@
package org.bench4q.share.models.master.plugin; package org.bench4q.share.models.master.plugin;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import com.sun.xml.internal.txw2.annotation.XmlElement; import com.sun.xml.internal.txw2.annotation.XmlElement;
@XmlRootElement @XmlRootElement
public class ParamInfoModel<T extends ParamTypeModel> { public class ParamInfoModel {
private String name; private String name;
private String lable; private String lable;
private String type;
private T paramTypeModel; private ParamTypeClassAndContnet paramTypeClassAndContnet;
@XmlElement @XmlElement
public String getName() { public String getName() {
@ -31,12 +32,23 @@ public class ParamInfoModel<T extends ParamTypeModel> {
} }
@XmlElement @XmlElement
public T getParamTypeModel() { public ParamTypeClassAndContnet getParamTypeClassAndContnet() {
return paramTypeModel; return paramTypeClassAndContnet;
} }
public void setParamTypeModel(T paramTypeModel) { public void setParamTypeClassAndContnet(
this.paramTypeModel = paramTypeModel; ParamTypeClassAndContnet paramTypeClassAndContnet) {
this.paramTypeClassAndContnet = paramTypeClassAndContnet;
} }
@XmlElement
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
} }

View File

@ -0,0 +1,40 @@
package org.bench4q.share.models.master.plugin;
import javax.xml.bind.annotation.XmlRootElement;
import com.sun.xml.internal.txw2.annotation.XmlElement;
@XmlRootElement
public class ParamTypeClassAndContnet {
private Class<?> paramTypeClass;
private String content;
public ParamTypeClassAndContnet() {
}
public ParamTypeClassAndContnet(Class<?> paramTyClass, String content) {
this.paramTypeClass = paramTyClass;
this.content = content;
}
@XmlElement
public Class<?> getParamTypeClass() {
return paramTypeClass;
}
public void setParamTypeClass(Class<?> paramTypeClass) {
this.paramTypeClass = paramTypeClass;
}
@XmlElement
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}

View File

@ -11,7 +11,7 @@ import com.sun.xml.internal.txw2.annotation.XmlElement;
public class PluginInfoModel { public class PluginInfoModel {
private String name; private String name;
private List<ParamInfoModel<? extends ParamTypeModel>> paramInfoModels; private List<ParamInfoModel> paramInfoModels;
@XmlElement @XmlElement
public String getName() { public String getName() {
@ -24,13 +24,14 @@ public class PluginInfoModel {
@XmlElementWrapper @XmlElementWrapper
@XmlElement @XmlElement
public List<ParamInfoModel<? extends ParamTypeModel>> getParamInfoModels() { public List<ParamInfoModel> getParamInfoModels() {
return paramInfoModels; return paramInfoModels;
} }
public void setParamInfoModels( public void setParamInfoModels(
List<ParamInfoModel<? extends ParamTypeModel>> paramInfoModels) { List<ParamInfoModel> paramInfoModels) {
this.paramInfoModels = paramInfoModels; this.paramInfoModels = paramInfoModels;
} }
} }