Mercurial > stress-tester
changeset 913:d1158607d5f0
refactoring
author | Devel 1 |
---|---|
date | Mon, 23 Apr 2018 21:58:06 +0200 |
parents | f3957e7bf48c |
children | afa17add2f3f |
files | stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTransformer.java stress-tester/src/main/java/com/passus/st/client/http/filter/HttpScopeModificationFilterTransformer.java stress-tester/src/main/java/com/passus/st/filter/Transformers.java |
diffstat | 3 files changed, 28 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTransformer.java Thu Apr 19 12:02:09 2018 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTransformer.java Mon Apr 23 21:58:06 2018 +0200 @@ -5,18 +5,15 @@ import com.passus.config.validation.Errors; import com.passus.filter.ValueExtractor; import com.passus.filter.config.ExpressionNodeTransformer; -import com.passus.lookup.Lookup; import com.passus.lookup.filter.LookupValueExtractorTransformer; import com.passus.st.client.http.extractor.ContentExtractorUtils; import com.passus.st.client.http.extractor.ContentReplacer; import com.passus.st.client.http.filter.HttpMessageModificationFilter.*; import com.passus.st.filter.Transformers; -import com.passus.st.utils.ConfigurationContextConsts; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Map; import static com.passus.st.validation.NodeValidationUtils.validateType; @@ -26,7 +23,7 @@ public class HttpMessageModificationFilterTransformer implements NodeTransformer { private static Operation createNameOperation(CTupleNode tuple, - Errors errors, Class<? extends Operation> clazz) { + Errors errors, Class<? extends Operation> clazz) { if (validateType(tuple.getNode(), NodeType.VALUE, errors)) { CValueNode valNode = (CValueNode) tuple.getNode(); try { @@ -42,8 +39,8 @@ } private static ValueExtractor createValueExtractor(CNode node, Errors errors, - ExpressionNodeTransformer expressionNodeTransformer, - LookupValueExtractorTransformer lookupValueTransformer) { + ExpressionNodeTransformer expressionNodeTransformer, + LookupValueExtractorTransformer lookupValueTransformer) { NodeType type = node.getType(); ValueExtractor valueExtractor = null; if (type == NodeType.VALUE) { @@ -71,9 +68,9 @@ CNode valNode = tupleNode.getNode(); try { valueExtractor = (ValueExtractor) lookupValueTransformer.transform(valNode); - } catch(NodeConversionException e) { + } catch (NodeConversionException e) { errors.reject(valNode, "Invalid lookup definition. " + e.getMessage()); - } catch(Exception e) { + } catch (Exception e) { errors.reject(valNode, "Invalid lookup definition."); } } @@ -85,9 +82,9 @@ } private static AbstractNameValueOperation createNameValueOperation(CTupleNode nodeTuple, - Errors errors, Class<? extends AbstractNameValueOperation> clazz, - ExpressionNodeTransformer expressionNodeTransformer, - LookupValueExtractorTransformer lookupValueTransformer) { + Errors errors, Class<? extends AbstractNameValueOperation> clazz, + ExpressionNodeTransformer expressionNodeTransformer, + LookupValueExtractorTransformer lookupValueTransformer) { AbstractNameValueOperation op = null; if (validateType(nodeTuple.getNode(), NodeType.MAP, errors)) { @@ -132,9 +129,9 @@ } private static AddParamOperation createAddParamOperation(CTupleNode nodeTuple, - Errors errors, Class<? extends AddParamOperation> clazz, - ExpressionNodeTransformer expressionNodeTransformer, - LookupValueExtractorTransformer lookupValueTransformer) { + Errors errors, Class<? extends AddParamOperation> clazz, + ExpressionNodeTransformer expressionNodeTransformer, + LookupValueExtractorTransformer lookupValueTransformer) { AddParamOperation op = null; if (validateType(nodeTuple.getNode(), NodeType.MAP, errors)) { @@ -188,10 +185,8 @@ operations = new ArrayList<>(tuples.size()); } - Map<String, ValueExtractor> vars = (Map<String, ValueExtractor>) context.get(ConfigurationContextConsts.APP_VARS); - List<Lookup> lookups = context.get(ConfigurationContextConsts.LOOKUPS, Collections.EMPTY_LIST); - final ExpressionNodeTransformer expressionNodeTransformer = Transformers.expressionNodeTransformer(vars); - final LookupValueExtractorTransformer lookupValueTransformer = new LookupValueExtractorTransformer(lookups); + final ExpressionNodeTransformer expressionNodeTransformer = Transformers.expressionNodeTransformer(context); + final LookupValueExtractorTransformer lookupValueTransformer = Transformers.lookupNodeTransformer(context); for (CTupleNode tuple : tuples) { String opName = tuple.getName();
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpScopeModificationFilterTransformer.java Thu Apr 19 12:02:09 2018 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpScopeModificationFilterTransformer.java Mon Apr 23 21:58:06 2018 +0200 @@ -19,12 +19,10 @@ import com.passus.st.client.http.filter.HttpScopeModificationFilter.SetGlobalParamOperation; import com.passus.st.client.http.filter.HttpScopeModificationFilter.SetSessionParamOperation; import com.passus.st.filter.Transformers; -import com.passus.st.utils.ConfigurationContextConsts; import static com.passus.st.validation.NodeValidationUtils.validateType; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Map; /** * @@ -114,8 +112,7 @@ operations = new ArrayList<>(); } - Map<String, ValueExtractor> vars = (Map<String, ValueExtractor>) context.get(ConfigurationContextConsts.APP_VARS); - final ExpressionNodeTransformer transformer = Transformers.expressionNodeTransformer(vars); + final ExpressionNodeTransformer transformer = Transformers.expressionNodeTransformer(context); for (CTupleNode tuple : tuples) { String opName = tuple.getName();
--- a/stress-tester/src/main/java/com/passus/st/filter/Transformers.java Thu Apr 19 12:02:09 2018 +0200 +++ b/stress-tester/src/main/java/com/passus/st/filter/Transformers.java Mon Apr 23 21:58:06 2018 +0200 @@ -1,11 +1,17 @@ package com.passus.st.filter; +import com.passus.config.ConfigurationContext; import com.passus.filter.ValueExtractor; import com.passus.filter.ValueExtractorParser; import com.passus.filter.config.ExpressionNodeTransformer; import com.passus.filter.config.PredicateNodeTransformer; import com.passus.filter.config.ValueExtractorResolver; +import com.passus.lookup.Lookup; +import com.passus.lookup.filter.LookupValueExtractorTransformer; +import com.passus.st.utils.ConfigurationContextConsts; import com.passus.st.vars.VarsExtractorResolver; +import java.util.Collections; +import java.util.List; import java.util.Map; /** @@ -20,7 +26,8 @@ public static final ExpressionNodeTransformer EXPRESSION = new ExpressionNodeTransformer(new ValueExtractorParser(VALUE_EXTRACTOR_RESOLVER)); - public static ExpressionNodeTransformer expressionNodeTransformer(Map<String, ValueExtractor> vars) { + public static ExpressionNodeTransformer expressionNodeTransformer(ConfigurationContext context) { + Map<String, ValueExtractor> vars = (Map<String, ValueExtractor>) context.get(ConfigurationContextConsts.APP_VARS); if (vars != null && !vars.isEmpty()) { VarsExtractorResolver varsResolver = new VarsExtractorResolver(vars); ValueExtractorParser parser = new ValueExtractorParser(varsResolver); @@ -29,4 +36,10 @@ return Transformers.EXPRESSION; } } + + public static LookupValueExtractorTransformer lookupNodeTransformer(ConfigurationContext context) { + List<Lookup> lookups = context.get(ConfigurationContextConsts.LOOKUPS, Collections.EMPTY_LIST); + return new LookupValueExtractorTransformer(lookups); + } + }