From 3b57cc690f829c1c531ee1a72f94b259a6c5db78 Mon Sep 17 00:00:00 2001 From: fanfuxiaoran <495538672@qq.com> Date: Thu, 17 Apr 2014 11:38:27 +0800 Subject: [PATCH] add behavior to behavior --- Bench4Q-Master/pluginUI/ui.xml | 4 +- .../bench4q/master/api/PluginController.java | 4 +- .../master/domain/entity/TestPlan.java | 2 +- .../domain/entity/plugin/BehaviorInfo.java | 10 ++ .../domain/factory/PluginEntityFactory.java | 88 ++++++---- .../domain/repository/PluginRepository.java | 11 ++ .../java/TestHelper/Test_PluginHelper.java | 24 ++- .../test/controller/PluginControllerTest.java | 90 +++------- .../factory/Test_PluginDomainFactory.java | 2 +- .../factory/Test_PluginEntityFactory.java | 11 +- .../repository/Test_PluginRepository.java | 6 +- .../test/service/Test_PluginService.java | 162 ++++++++---------- .../test/resources/service-test-context.xml | 2 +- .../master/plugin/BehaviorInfoModel.java | 13 +- 14 files changed, 219 insertions(+), 210 deletions(-) diff --git a/Bench4Q-Master/pluginUI/ui.xml b/Bench4Q-Master/pluginUI/ui.xml index fb73c343..f7c8d87a 100644 --- a/Bench4Q-Master/pluginUI/ui.xml +++ b/Bench4Q-Master/pluginUI/ui.xml @@ -36,7 +36,7 @@ - + - + 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 79b3c6a8..bb8d75d1 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 @@ -31,7 +31,7 @@ public class PluginController extends BaseController { this.pluginService = pluginService; } - @RequestMapping(value = "loadPluginUI", method = { RequestMethod.GET, + @RequestMapping(value = "/loadPluginUI", method = { RequestMethod.GET, RequestMethod.POST }) @ResponseBody public PluginResponseModel loadPluginUIModels() throws Bench4QException { @@ -73,7 +73,7 @@ public class PluginController extends BaseController { return pluginResponseModel; } - @RequestMapping(value = "loadBehaviors/{pluginName}", method = { + @RequestMapping(value = "/loadBehaviors/{pluginName}", method = { RequestMethod.GET, RequestMethod.POST }) @ResponseBody public PluginResponseModel getMethods( diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/TestPlan.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/TestPlan.java index f2ef3353..e7d1b0b9 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/TestPlan.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/TestPlan.java @@ -219,7 +219,7 @@ public class TestPlan implements IAggregate { } public List collectResult() { - List resultList = new LinkedList<>(); + List resultList = new LinkedList(); for (TestPlanScript testPlanScript : getTestPlanScripts()) { List testPlanScriptResults = testPlanScript .doAfterRun(); diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/BehaviorInfo.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/BehaviorInfo.java index d9e81af0..a00a5bd1 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/BehaviorInfo.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/plugin/BehaviorInfo.java @@ -19,6 +19,7 @@ import javax.persistence.Table; public class BehaviorInfo { private int id; private String name; + private String behavoirType; private Set params; private PluginUI pluginUI; @@ -42,6 +43,15 @@ public class BehaviorInfo { this.name = name; } + @Column(name = "behavoirType") + public String getBehavoirType() { + return behavoirType; + } + + public void setBehavoirType(String behavoirType) { + this.behavoirType = behavoirType; + } + @OneToMany(mappedBy = "behaviorInfo", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER) public Set getParams() { return params; 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 index 090a4d68..51fae39b 100644 --- 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 @@ -35,37 +35,16 @@ public class PluginEntityFactory { public PluginUI createPluginUIWithOutId(String pluginUIContent) { Element root = getDocument(pluginUIContent).getRootElement(); PluginUI pluginUI = new PluginUI(); + String[] behaviorNames = { "behavior", "timer", "control" }; pluginUI.setPluginInfo(createPluginInfoWithOutId(XmlParseHelper .getOneChildElementByName(root, "plugin"))); + pluginUI.setBehaviorInfos(createBehaviorInfosWithOutId( - XmlParseHelper.getChildElementsByName(root, "behavior"), - pluginUI)); + XmlParseHelper.getChildElements(root, behaviorNames), pluginUI)); pluginUI.setCreateDateTime(new Date()); 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(); @@ -78,6 +57,7 @@ public class PluginEntityFactory { private BehaviorInfo createBehaviorInfoWithOutId(Element element, PluginUI pluginUI) { BehaviorInfo behaviorInfo = new BehaviorInfo(); + behaviorInfo.setBehavoirType(element.getName()); behaviorInfo.setName(XmlParseHelper.getAttribute(element, "name")); behaviorInfo.setPluginUI(pluginUI); behaviorInfo.setParams(createBehaviorParamInfos( @@ -99,20 +79,6 @@ public class PluginEntityFactory { 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) @@ -133,6 +99,42 @@ public class PluginEntityFactory { return behaviorParamInfo; } + 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 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 PluginParamInfo createPluginParamInfoWithOutId(Element element, PluginInfo pluginInfo) { if (XmlParseHelper.getAttribute(element, "name") == null) @@ -297,4 +299,14 @@ class XmlParseHelper { return elements; } + + public static List getChildElements(Element element, + String[] elementNames) { + List elements = new LinkedList(); + for (String elementName : elementNames) { + elements.addAll(getChildElementsByName(element, elementName)); + } + return elements; + } + } 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 ed13cf08..c1775032 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 @@ -2,6 +2,7 @@ package org.bench4q.master.domain.repository; import java.util.List; 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; @@ -138,4 +139,14 @@ public class PluginRepository extends AbstractRepositoty { .add(Restrictions.eq("name", pluginName)).uniqueResult(); } + public boolean clearPlugins() { + + List pluginUIs = this.loadPlugins(); + for (PluginUI pluginUI : pluginUIs) { + if (!this.detach(pluginUI.getPluginInfo().getName())) + return false; + } + return true; + } + } diff --git a/Bench4Q-Master/src/test/java/TestHelper/Test_PluginHelper.java b/Bench4Q-Master/src/test/java/TestHelper/Test_PluginHelper.java index a3e8bfd9..3e49ee1c 100644 --- a/Bench4Q-Master/src/test/java/TestHelper/Test_PluginHelper.java +++ b/Bench4Q-Master/src/test/java/TestHelper/Test_PluginHelper.java @@ -8,8 +8,10 @@ import org.bench4q.master.domain.entity.plugin.PluginUI; import org.bench4q.master.domain.factory.PluginEntityFactory; import org.bench4q.master.domain.repository.PluginRepository; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; -public class Test_PluginHelper { +@Component +public class Test_PluginHelper { private PluginRepository pluginRepository; @@ -22,11 +24,17 @@ public class Test_PluginHelper { this.pluginRepository = pluginRepository; } - public static PluginUI createPluginUI(String fileName) throws IOException { - PluginEntityFactory pluginEntityFactory = new PluginEntityFactory(); + public static String filePath(String fileName) { + String fileSeparator = System.getProperty("file.separator"); String filePath = System.getProperty("user.dir") + fileSeparator + "pluginUI" + fileSeparator + fileName; + return filePath; + } + + public PluginUI createPluginUI(String fileName) throws IOException { + PluginEntityFactory pluginEntityFactory = new PluginEntityFactory(); + String filePath = filePath(fileName); File file = new File(filePath); String uiContent = FileUtils.readFileToString(file); PluginUI pluginUI = pluginEntityFactory @@ -34,11 +42,10 @@ public class Test_PluginHelper { return pluginUI; } - protected String addPlugin(String fileName, - PluginRepository pluginRepository) { + public String addPlugin(String fileName) { try { PluginUI pluginUI = createPluginUI(fileName); - pluginRepository.attatch(pluginUI); + this.pluginRepository.attatch(pluginUI); return pluginUI.getPluginInfo().getName(); } catch (Exception e) { e.printStackTrace(); @@ -46,4 +53,9 @@ public class Test_PluginHelper { } } + + public void clearPlugin(String pluginName) { + this.getPluginRepository().detach(pluginName); + + } } 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 d6307318..c7565b14 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 @@ -2,12 +2,14 @@ package org.bench4q.master.test.controller; import static org.junit.Assert.*; +import java.io.File; import java.io.IOException; import javax.xml.bind.JAXBException; +import org.apache.commons.io.FileUtils; import org.apache.log4j.Logger; -import org.bench4q.master.domain.entity.plugin.PluginUI; +import org.bench4q.master.domain.service.PluginService; import org.bench4q.share.communication.HttpRequester.HttpResponse; import org.bench4q.share.helper.MarshalHelper; import org.bench4q.share.models.master.plugin.PluginResponseModel; @@ -15,34 +17,50 @@ 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_PluginHelper; - +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = { "classpath:service-test-context.xml" }) public class PluginControllerTest extends TestBase { private final String URLSTRING = BASE_URL + "/plugin"; + private PluginService pluginService; private String pluginName; - public String getURLSTRING() { return URLSTRING; } + + public PluginService getPluginService() { + return pluginService; + } + +@Autowired + + public void setPluginService(PluginService pluginService) { + this.pluginService = pluginService; + } + @Before public void setUp() throws IOException, JAXBException { - testAddPlugin(); + this.pluginName="CsvProvider"; + this.getPluginService().deletePlugin(pluginName); } @Test public void testAddPlugin() throws JAXBException, IOException { this.setAccessTocken(this.login()); String url = URLSTRING + "/addPlugin"; - PluginUI pluginGUI = Test_PluginHelper.createPluginUI("ui.xml"); - pluginName = pluginGUI.getPluginInfo().getName(); - String pluginContentString = MarshalHelper.marshal(PluginUI.class, - pluginGUI); + File file=new File(Test_PluginHelper.filePath("ui.xml")); + String pluginContent=FileUtils.readFileToString(file); HttpResponse httpResponse = this.httpRequester.sendPutXml(url, - pluginContentString, + pluginContent, makeAccessTockenMap(this.getAccessTocken())); + System.out.println(httpResponse.getContent()); PluginResponseModel pluginResponseModel = (PluginResponseModel) MarshalHelper .tryUnmarshal(PluginResponseModel.class, httpResponse.getContent()); @@ -54,29 +72,6 @@ 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 testLoadPluginList() throws JAXBException, IOException { @@ -91,20 +86,6 @@ 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 testDeletePlugin() throws IOException, JAXBException { @@ -125,23 +106,6 @@ 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); - // - // } @After public void clear() throws IOException { diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/test/factory/Test_PluginDomainFactory.java b/Bench4Q-Master/src/test/java/org/bench4q/master/test/factory/Test_PluginDomainFactory.java index 0e5c962f..9c8c27a8 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/test/factory/Test_PluginDomainFactory.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/test/factory/Test_PluginDomainFactory.java @@ -45,7 +45,7 @@ public class Test_PluginDomainFactory extends Test_PluginHelper { @Before public void setUp() { - this.pluginName = addPlugin("ui.xml", this.getPluginRepository()); + this.pluginName = addPlugin("ui.xml"); } @After 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 index ccfdfad7..3d2c812a 100644 --- 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 @@ -41,6 +41,7 @@ public class Test_PluginEntityFactory { + "pluginUI" + fileSeparator + "ui.xml"; File file = new File(filePath); String uiContent = FileUtils.readFileToString(file); + assertNotNull(uiContent); PluginUI pluginUI = pluginEntityFactory .createPluginUIWithOutId(uiContent); assertNotNull(pluginUI); @@ -57,7 +58,13 @@ public class Test_PluginEntityFactory { fieldType = (FieldType) pluginParamInfo.getType(); } assertTrue(fieldType.getSize() == 7); - BehaviorInfo behaviorInfo=pluginUI.getBehaviorInfos().iterator().next(); - assertNull(behaviorInfo.getParams()); + assertEquals(2, pluginUI.getBehaviorInfos().size()); + int timerCount=0; + for( BehaviorInfo behaviorInfo:pluginUI.getBehaviorInfos()){ + if(behaviorInfo.getBehavoirType().equals("timer")) + timerCount++; + } + assertEquals(1, timerCount); + } } 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 1caee09f..62f2c83d 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 @@ -41,7 +41,7 @@ public class Test_PluginRepository extends Test_PluginHelper { @Before public void setUp() throws Bench4QException { - this.pluginName = addPlugin("ui.xml", this.getPluginRepository()); + this.pluginName = addPlugin("ui.xml"); } @Test @@ -53,7 +53,7 @@ public class Test_PluginRepository extends Test_PluginHelper { @Test public void testLoadPlugins() throws Bench4QException { int countBeforeInsert = this.getPluginRepository().loadPlugins().size(); - String name = addPlugin("test.xml", this.getPluginRepository()); + String name = addPlugin("test.xml"); assertEquals(countBeforeInsert + 1, this.getPluginRepository() .loadPlugins().size()); @@ -75,7 +75,7 @@ public class Test_PluginRepository extends Test_PluginHelper { @Test public void testDeletePlugin() { - String name = addPlugin("ui.xml", this.getPluginRepository()); + String name = addPlugin("ui.xml"); assertTrue(this.getPluginRepository().detach(name)); } 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 54c91cc6..8d2ad286 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,109 +1,91 @@ package org.bench4q.master.test.service; +import static org.junit.Assert.*; - - +import java.io.File; +import java.io.IOException; +import org.apache.commons.io.FileUtils; +import org.bench4q.master.domain.service.PluginService; +import org.junit.After; +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_PluginHelper; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:service-test-context.xml" }) -public class Test_PluginService { +public class Test_PluginService extends Test_PluginHelper { + private PluginService pluginService; + private String pluginName; -// 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() { + this.pluginName = "CsvProvider"; + this.getPluginRepository().detach(pluginName); + } -// @Test -// public void getMethodParam() throws Bench4QException { -// String methodName = this.getPluginService() -// .getMethodNameInPlugin(nameForPlugin).get(0); -// assertTrue(this.getPluginService() -// .getMethodParamModelsInPlugin(nameForPlugin, methodName).size() == 2); -// } + @After + public void clear() { -// @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 test_addPlugin() { -// @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; -// } + File file = new File(filePath("ui.xml")); + String pluginContent; + try { + pluginContent = FileUtils.readFileToString(file); + assertTrue(this.getPluginService().addPlugin(pluginContent)); + assertFalse(this.getPluginService().addPlugin(pluginContent)); + assertTure(this.getPluginService().deletePlugin(pluginName)); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void test_loadPlugins() { + int insertBefore = this.getPluginService().loadPluginUIs().size(); + addPluginByString(); + assertEquals(insertBefore + 1, this.getPluginService().loadPluginUIs() + .size()); + this.getPluginService().deletePlugin(pluginName); + } + + @Test + public void test_loadBehaviors(){ + addPluginByString(); + assertEquals(2,this.getPluginService().loadBehaviorInfoModels(pluginName).size()); + } + private void assertTure(boolean deletePlugin) { + // TODO Auto-generated method stub + + } + + private void addPluginByString() { + File file = new File(filePath("ui.xml")); + String pluginContent; + try { + pluginContent = FileUtils.readFileToString(file); + this.getPluginService().addPlugin(pluginContent); + } catch (Exception e) { + e.printStackTrace(); + } + } } diff --git a/Bench4Q-Master/src/test/resources/service-test-context.xml b/Bench4Q-Master/src/test/resources/service-test-context.xml index d03ce758..27d433c3 100644 --- a/Bench4Q-Master/src/test/resources/service-test-context.xml +++ b/Bench4Q-Master/src/test/resources/service-test-context.xml @@ -8,7 +8,7 @@ http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"> + 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" /> diff --git a/Bench4Q-Share/src/main/java/org/bench4q/share/models/master/plugin/BehaviorInfoModel.java b/Bench4Q-Share/src/main/java/org/bench4q/share/models/master/plugin/BehaviorInfoModel.java index 00565956..b2fd41ac 100644 --- a/Bench4Q-Share/src/main/java/org/bench4q/share/models/master/plugin/BehaviorInfoModel.java +++ b/Bench4Q-Share/src/main/java/org/bench4q/share/models/master/plugin/BehaviorInfoModel.java @@ -13,6 +13,7 @@ public class BehaviorInfoModel { @SuppressWarnings("rawtypes") private List paramInfoModels; + private String behaviorType; private String name; @SuppressWarnings("rawtypes") @@ -22,7 +23,8 @@ public class BehaviorInfoModel { return paramInfoModels; } - public void setParamInfoModels(@SuppressWarnings("rawtypes") List paramInfoModels) { + public void setParamInfoModels( + @SuppressWarnings("rawtypes") List paramInfoModels) { this.paramInfoModels = paramInfoModels; } @@ -35,4 +37,13 @@ public class BehaviorInfoModel { this.name = name; } + @XmlElement + public String getBehaviorType() { + return behaviorType; + } + + public void setBehaviorType(String behaviorType) { + this.behaviorType = behaviorType; + } + }