From 0d29dd37889e56811069f5c520cf19e1aadd77dd Mon Sep 17 00:00:00 2001 From: coderfengyun Date: Wed, 9 Apr 2014 22:59:12 +0800 Subject: [PATCH] refactor and should go on refactor and should go on --- .../parameterization/Parameterization.java | 5 --- ...ePlugin.java => BaseParameterization.java} | 4 +-- .../plugin/basic/csvProvider/CsvProvider.java | 5 ++- .../agent/test/plugin/Test_PluginManager.java | 34 +++++++++++++++++-- 4 files changed, 35 insertions(+), 13 deletions(-) delete mode 100644 Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/Parameterization.java rename Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/{BasePlugin.java => BaseParameterization.java} (85%) diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/Parameterization.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/Parameterization.java deleted file mode 100644 index 5644d447..00000000 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/Parameterization.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.bench4q.agent.parameterization; - -public interface Parameterization { - public String getCurrentValue(); -} diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/BasePlugin.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/BaseParameterization.java similarity index 85% rename from Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/BasePlugin.java rename to Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/BaseParameterization.java index 934e5956..62d46885 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/BasePlugin.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/BaseParameterization.java @@ -4,7 +4,7 @@ import java.util.UUID; import org.bench4q.agent.Main; -public abstract class BasePlugin { +public abstract class BaseParameterization { private UUID testId; protected UUID getTestId() { @@ -15,7 +15,7 @@ public abstract class BasePlugin { this.testId = testId; } - protected BasePlugin(String testId) { + protected BaseParameterization(String testId) { this.setTestId(UUID.fromString(testId)); } diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/csvProvider/CsvProvider.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/csvProvider/CsvProvider.java index 1a3d3ae1..847728bd 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/csvProvider/CsvProvider.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/csvProvider/CsvProvider.java @@ -10,8 +10,7 @@ import java.util.LinkedList; import java.util.List; import java.util.regex.Pattern; -import org.bench4q.agent.parameterization.Parameterization; -import org.bench4q.agent.plugin.BasePlugin; +import org.bench4q.agent.plugin.BaseParameterization; import org.bench4q.agent.plugin.Constructor; import org.bench4q.agent.plugin.Parameter; import org.bench4q.agent.plugin.Plugin; @@ -19,7 +18,7 @@ import org.bench4q.agent.utils.ParameterParser; import org.bench4q.agent.utils.Type.SupportTypes; @Plugin(value = "CsvProvider") -public class CsvProvider extends BasePlugin implements Parameterization { +public class CsvProvider extends BaseParameterization { private static final String ENABLE_CheckBox = "enable"; public static final char DEFAULT_SEPARATOR = ','; diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/Test_PluginManager.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/Test_PluginManager.java index 5885fa1a..13f01908 100644 --- a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/Test_PluginManager.java +++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/Test_PluginManager.java @@ -1,8 +1,10 @@ package org.bench4q.agent.test.plugin; import org.bench4q.agent.helper.ClassHelper; +import org.bench4q.agent.plugin.Plugin; import org.bench4q.agent.plugin.PluginManager; import org.bench4q.agent.plugin.TypeConverter; +import org.bench4q.agent.plugin.basic.http.HttpPlugin; import org.junit.Test; import static org.junit.Assert.*; @@ -12,8 +14,34 @@ public class Test_PluginManager { public void test_getInit() { PluginManager pluginManager = new PluginManager(new ClassHelper(), new TypeConverter()); - assertEquals(5, pluginManager.getPlugins().size()); - assertTrue(pluginManager.getPlugins().containsKey( - "org.bench4q.agent.plugin.basic.http.HttpPlugin")); + assertEquals(6, pluginManager.getPlugins().size()); + assertTrue(pluginManager.getPlugins().containsKey("Http")); + } + + @Test + public void test_InitializePlugin_IN_RightWay() { + PluginManager pluginManager = new PluginManager(new ClassHelper(), + new TypeConverter()); + HttpPlugin httpPlugin = (HttpPlugin) pluginManager.initializePlugin( + pluginManager.getPlugins().get("Http"), null); + assertNotNull(httpPlugin); + } + + @Test + public void test_InitializePlugin_Without_Constructor_Annotation() { + PluginManager pluginManager = new PluginManager(new ClassHelper(), + new TypeConverter()); + pluginManager.getPlugins().put("WithoutConstructorAnnotation", + WithoutConstructorAnnotationPlugin.class); + WithoutConstructorAnnotationPlugin plugin = (WithoutConstructorAnnotationPlugin) pluginManager + .initializePlugin( + pluginManager.getPlugins().get( + "WithoutConstructorAnnotation"), null); + assertNull(plugin); + } + + @Plugin("WithoutConstructorAnnotation") + public static class WithoutConstructorAnnotationPlugin { + } }