changeset 867:af16052b659b

LookupsDomainConfigurator
author Devel 2
date Wed, 24 Jan 2018 15:34:33 +0100
parents 9aa23298c908
children c8844cd52ad4
files stress-tester/pom.xml stress-tester/src/main/java/com/passus/st/CliHelper.java stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFiltersConfigurator.java stress-tester/src/main/java/com/passus/st/lookup/LookupsDomainConfigurator.java stress-tester/src/main/java/com/passus/st/lookup/LookupsNodeDefinitionCreator.java stress-tester/src/main/java/com/passus/st/utils/ConfigurationContextConsts.java stress-tester/src/test/java/com/passus/st/lookup/LookupsDomainConfiguratorTest.java
diffstat 7 files changed, 130 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/pom.xml	Wed Jan 24 14:52:59 2018 +0100
+++ b/stress-tester/pom.xml	Wed Jan 24 15:34:33 2018 +0100
@@ -90,11 +90,13 @@
             <artifactId>passus-net</artifactId>
             <version>1.0-SNAPSHOT</version>
         </dependency>
+
         <dependency>
             <groupId>com.passus</groupId>
             <artifactId>passus-config</artifactId>
             <version>1.0-SNAPSHOT</version>
         </dependency>
+
         <dependency>
             <groupId>com.passus</groupId>
             <artifactId>passus-filter</artifactId>
@@ -102,6 +104,12 @@
         </dependency>
 
         <dependency>
+            <groupId>com.passus</groupId>
+            <artifactId>passus-lookup</artifactId>
+            <version>1.0-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
             <groupId>com.passus.st</groupId>
             <artifactId>stress-tester-reporter</artifactId>
             <version>1.0-SNAPSHOT</version>
--- a/stress-tester/src/main/java/com/passus/st/CliHelper.java	Wed Jan 24 14:52:59 2018 +0100
+++ b/stress-tester/src/main/java/com/passus/st/CliHelper.java	Wed Jan 24 15:34:33 2018 +0100
@@ -33,7 +33,7 @@
 import java.util.Map;
 import org.apache.commons.cli.CommandLine;
 
-import static com.passus.st.utils.ConfigurationContextConsts.HTTP_FILTERS_FILTERS;
+import static com.passus.st.utils.ConfigurationContextConsts.HTTP_FILTERS;
 import static org.apache.commons.io.FileUtils.openInputStream;
 import org.apache.commons.io.IOUtils;
 
@@ -176,7 +176,7 @@
                 System.exit(1);
             }
 
-            return (List<HttpFilter>) context.get(HTTP_FILTERS_FILTERS);
+            return (List<HttpFilter>) context.get(HTTP_FILTERS);
         }
 
         return null;
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFiltersConfigurator.java	Wed Jan 24 14:52:59 2018 +0100
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFiltersConfigurator.java	Wed Jan 24 15:34:33 2018 +0100
@@ -11,7 +11,6 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -26,7 +25,7 @@
 
     private final HttpFiltersNodeDefinitionCreator nodeDefinitionCreator = new HttpFiltersNodeDefinitionCreator();
 
-    private final NodeDefinition nodedef = nodeDefinitionCreator.create();
+    private final NodeDefinition nodeDef = nodeDefinitionCreator.create();
 
     @Override
     public String getDomain() {
@@ -71,17 +70,17 @@
     @Override
     public void validate(Configuration config, Errors errors, ConfigurationContext context) {
         CCompositeNode rootNode = config.getRootNode();
-        nodedef.validate(rootNode, errors, context);
+        nodeDef.validate(rootNode, errors, context);
     }
 
     @Override
     public void configure(Configuration config, Errors errors, ConfigurationContext context) {
         CCompositeNode rootNode = config.getRootNode();
-        nodedef.transform(rootNode, errors, context);
+        nodeDef.transform(rootNode, errors, context);
         if (!errors.hasError()) {
             try {
                 List<HttpFilter> filters = ConfigurationUtils.convertToList(config.getRootNode(), HttpFilter.class);
-                context.add(ConfigurationContextConsts.HTTP_FILTERS_FILTERS, filters);
+                context.add(ConfigurationContextConsts.HTTP_FILTERS, filters);
             } catch (Exception e) {
                 throw new RuntimeException(e.getMessage(), e);
             }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stress-tester/src/main/java/com/passus/st/lookup/LookupsDomainConfigurator.java	Wed Jan 24 15:34:33 2018 +0100
@@ -0,0 +1,47 @@
+package com.passus.st.lookup;
+
+import com.passus.commons.annotations.Plugin;
+import com.passus.config.*;
+import com.passus.config.schema.NodeDefinition;
+import com.passus.config.validation.Errors;
+import com.passus.lookup.Lookup;
+import com.passus.st.plugin.PluginConstants;
+import com.passus.st.utils.ConfigurationContextConsts;
+
+import java.util.List;
+
+@Plugin(name = LookupsDomainConfigurator.DOMAIN, category = PluginConstants.CATEGORY_DOMAIN_CONFIGURATOR)
+public class LookupsDomainConfigurator implements DomainConfigurator {
+
+    public static final String DOMAIN = "lookup";
+
+    private final LookupsNodeDefinitionCreator creator = new LookupsNodeDefinitionCreator();
+
+    private final NodeDefinition nodeDef = creator.create();
+
+    @Override
+    public String getDomain() {
+        return DOMAIN;
+    }
+
+    @Override
+    public void validate(Configuration config, Errors errors, ConfigurationContext context) {
+        CCompositeNode rootNode = config.getRootNode();
+        nodeDef.validate(rootNode, errors, context);
+    }
+
+    @Override
+    public void configure(Configuration config, Errors errors, ConfigurationContext context) {
+        CCompositeNode rootNode = config.getRootNode();
+        nodeDef.transform(rootNode, errors, context);
+        if (!errors.hasError()) {
+            try {
+                List<Lookup> lookups = ConfigurationUtils.convertToList(config.getRootNode(), Lookup.class);
+                context.add(ConfigurationContextConsts.LOOKUPS, lookups);
+            } catch (Exception e) {
+                throw new RuntimeException(e.getMessage(), e);
+            }
+
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stress-tester/src/main/java/com/passus/st/lookup/LookupsNodeDefinitionCreator.java	Wed Jan 24 15:34:33 2018 +0100
@@ -0,0 +1,26 @@
+package com.passus.st.lookup;
+
+import com.passus.config.schema.NodeDefinition;
+import com.passus.config.schema.NodeDefinitionCreator;
+import com.passus.lookup.LookupFactory;
+
+import static com.passus.config.schema.ConfigurationSchemaBuilder.dynaKeyValueVaryListDef;
+
+public class LookupsNodeDefinitionCreator implements NodeDefinitionCreator {
+
+    public NodeDefinition createLookupsListDef() {
+        return createLookupsListDef(true);
+    }
+
+    public NodeDefinition createLookupsListDef(boolean transformToObject) {
+        return dynaKeyValueVaryListDef("type", LookupFactory.getInstance())
+                .setTransformToPluginObject(transformToObject);
+    }
+
+    @Override
+    public NodeDefinition create() {
+        return createLookupsListDef();
+    }
+
+
+}
--- a/stress-tester/src/main/java/com/passus/st/utils/ConfigurationContextConsts.java	Wed Jan 24 14:52:59 2018 +0100
+++ b/stress-tester/src/main/java/com/passus/st/utils/ConfigurationContextConsts.java	Wed Jan 24 15:34:33 2018 +0100
@@ -3,6 +3,7 @@
 public class ConfigurationContextConsts {
 
     public static final String EVENT_SOURCE_CACHE = "eventSource.cache";
+
     public static final String EVENT_SOURCE_BUFFER = "eventSource.buffer";
 
     /**
@@ -29,17 +30,19 @@
 
     public static final String METRICS_ACTIVE = "metrics.active";
 
-    public static final String METRICS_COLLECTION_APPENDERS = "metrics.collection_appenders";
+    public static final String METRICS_COLLECTION_APPENDERS = "metrics.collectionAppenders";
 
     public static final String METRICS_COLLECTOR = "metrics.collector";
 
     public static final String REPORTER_DESTINATIONS = "reporter.destinations";
 
-    public static final String REPORTER_DEFAULT_DESTINATION =  "reporter.default_destination";
+    public static final String REPORTER_DEFAULT_DESTINATION = "reporter.defaultDestination";
 
     public static final String PROJECT = "project";
 
-    public static final String HTTP_FILTERS_FILTERS = "httpFilters.filters";
+    public static final String HTTP_FILTERS = "httpFilters";
+
+    public static final String LOOKUPS = "lookups";
 
     private ConfigurationContextConsts() {
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stress-tester/src/test/java/com/passus/st/lookup/LookupsDomainConfiguratorTest.java	Wed Jan 24 15:34:33 2018 +0100
@@ -0,0 +1,37 @@
+package com.passus.st.lookup;
+
+import com.passus.config.Configuration;
+import com.passus.config.ConfigurationContext;
+import com.passus.config.validation.Errors;
+import com.passus.lookup.CsvFileLookup;
+import com.passus.lookup.Lookup;
+import com.passus.st.utils.ConfigurationContextConsts;
+import org.testng.annotations.Test;
+
+import java.util.List;
+
+import static com.passus.config.YamlConfigurationReader.readFromString;
+import static junit.framework.TestCase.assertTrue;
+import static org.testng.AssertJUnit.assertFalse;
+
+public class LookupsDomainConfiguratorTest {
+
+    @Test
+    @SuppressWarnings("unchecked")
+    public void testConfigure() throws Exception {
+        String lookupsConfig = "lookups:\n" +
+                "  - type: csvFile\n" +
+                "    fileName: 'c:\test.csv'\n";
+
+        Configuration config = readFromString(lookupsConfig);
+
+        Errors errors = new Errors();
+        LookupsDomainConfigurator configurator = new LookupsDomainConfigurator();
+        ConfigurationContext context = ConfigurationContext.create();
+        configurator.configure(config.subConfiguration("lookups"), errors, context);
+        assertFalse(errors.hasError());
+
+        List<Lookup> lookups = (List<Lookup>) context.get(ConfigurationContextConsts.LOOKUPS);
+        assertTrue(lookups.get(0) instanceof CsvFileLookup);
+    }
+}
\ No newline at end of file