Mercurial > stress-tester
changeset 899:dc4a6b3fe009
LookupsDomainConfigurator.getLookups
author | Devel 1 |
---|---|
date | Tue, 10 Apr 2018 13:47:02 +0200 |
parents | c603bf293bd7 |
children | 8cb5192c4b62 |
files | 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/test/java/com/passus/st/lookup/LookupsDomainConfiguratorTest.java |
diffstat | 3 files changed, 42 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFiltersConfigurator.java Tue Apr 10 13:47:02 2018 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFiltersConfigurator.java Tue Apr 10 13:47:02 2018 +0200 @@ -2,8 +2,6 @@ import com.passus.commons.annotations.Plugin; import com.passus.config.*; -import com.passus.config.schema.ConfigurationSchema; -import com.passus.config.schema.ConfigurationSchemaImpl; import com.passus.config.schema.NodeDefinition; import com.passus.config.validation.Errors; import com.passus.st.plugin.PluginConstants; @@ -21,11 +19,9 @@ public static final String DOMAIN = "httpFilters"; - private static final ConfigurationSchema SCHEMA = new ConfigurationSchemaImpl(new HttpFiltersNodeDefinitionCreator().create()); + private static final HttpFiltersNodeDefinitionCreator CREATOR = new HttpFiltersNodeDefinitionCreator(); - private final HttpFiltersNodeDefinitionCreator nodeDefinitionCreator = new HttpFiltersNodeDefinitionCreator(); - - private final NodeDefinition nodeDef = nodeDefinitionCreator.create(); + private final NodeDefinition nodeDef = CREATOR.create(); @Override public String getDomain() { @@ -43,28 +39,8 @@ } public static List<HttpFilter> getFilters(Configuration config, Errors errors, ConfigurationContext context) { - if (!config.containsKey(DOMAIN)) { - return null; - } - - HttpFiltersNodeDefinitionCreator nodeDefinitionCreator = new HttpFiltersNodeDefinitionCreator(); - NodeDefinition nodeDef = nodeDefinitionCreator.create(); - CCompositeNode rootNode = config.subConfiguration(DOMAIN).getRootNode(); - nodeDef.validate(rootNode, errors, context); - if (errors.hasError()) { - return null; - } - - nodeDef.transform(rootNode, errors, context); - if (errors.hasError()) { - return null; - } - - try { - return (List<HttpFilter>) config.get(DOMAIN); - } catch (Exception e) { - throw new RuntimeException(e.getMessage(), e); - } + NodeDefinition nodeDef = CREATOR.create(); + return ConfigurationUtils.getDomainObjects(config, errors, context, DOMAIN, nodeDef); } @Override
--- a/stress-tester/src/main/java/com/passus/st/lookup/LookupsDomainConfigurator.java Tue Apr 10 13:47:02 2018 +0200 +++ b/stress-tester/src/main/java/com/passus/st/lookup/LookupsDomainConfigurator.java Tue Apr 10 13:47:02 2018 +0200 @@ -8,6 +8,8 @@ import com.passus.st.plugin.PluginConstants; import com.passus.st.utils.ConfigurationContextConsts; +import java.io.File; +import java.io.IOException; import java.util.List; @Plugin(name = LookupsDomainConfigurator.DOMAIN, category = PluginConstants.CATEGORY_DOMAIN_CONFIGURATOR) @@ -15,15 +17,30 @@ public static final String DOMAIN = "lookups"; - private final LookupsNodeDefinitionCreator creator = new LookupsNodeDefinitionCreator(); + private static final LookupsNodeDefinitionCreator CREATOR = new LookupsNodeDefinitionCreator(); - private final NodeDefinition nodeDef = creator.create(); + private final NodeDefinition nodeDef = CREATOR.create(); @Override public String getDomain() { return DOMAIN; } + public static List<Lookup> getLookups(File configFile, Errors errors, ConfigurationContext context) throws IOException, NodeException { + Configuration config = YamlConfigurationReader.readFromFile(configFile); + return getLookups(config, errors, context); + } + + public static List<Lookup> getLookups(String configStr, Errors errors, ConfigurationContext context) throws IOException, NodeException { + Configuration config = YamlConfigurationReader.readFromString(configStr); + return getLookups(config, errors, context); + } + + public static List<Lookup> getLookups(Configuration config, Errors errors, ConfigurationContext context) { + NodeDefinition nodeDef = CREATOR.create(); + return ConfigurationUtils.getDomainObjects(config, errors, context, DOMAIN, nodeDef); + } + @Override public void validate(Configuration config, Errors errors, ConfigurationContext context) { CCompositeNode rootNode = config.getRootNode();
--- a/stress-tester/src/test/java/com/passus/st/lookup/LookupsDomainConfiguratorTest.java Tue Apr 10 13:47:02 2018 +0200 +++ b/stress-tester/src/test/java/com/passus/st/lookup/LookupsDomainConfiguratorTest.java Tue Apr 10 13:47:02 2018 +0200 @@ -16,22 +16,33 @@ public class LookupsDomainConfiguratorTest { + private final String lookupsConfig = "lookups:\n" + + " - type: csvFile\n" + + " fileName: 'c:\\test.csv'\n"; + @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(); + ConfigurationContext context = ConfigurationContext.create(); - 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 + + @Test + public void testConfigureStatic() throws Exception { + Configuration config = readFromString(lookupsConfig); + Errors errors = new Errors(); + ConfigurationContext context = ConfigurationContext.create(); + + List<Lookup> lookups = LookupsDomainConfigurator.getLookups(config, errors, context); + assertFalse(errors.hasError()); + assertTrue(lookups.get(0) instanceof CsvFileLookup); + } +}