Mercurial > stress-tester
changeset 927:4d8642593e5c
ST-132
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilter.java Fri Apr 27 13:34:15 2018 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilter.java Fri Apr 27 15:02:35 2018 +0200 @@ -132,7 +132,6 @@ NodeDefinition fieldValExtractorNodeDef = FieldValueExtractorTransformerNodeDefCreator.createNodeDef(); NodeDefinition paramNodeDef = new HeaderOperationNodeDefinition( mixedDef( - valueDef(), listDef(valueDef()), fieldValExtractorNodeDef ) @@ -140,7 +139,6 @@ HeaderOperationNodeDefinition headerNodeDef = new HeaderOperationNodeDefinition( mixedDef( - valueDef(), fieldValExtractorNodeDef ) ).addParam(tupleDef("*escape", valueDefBool()).setRequired(false));
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpScopeModificationFilter.java Fri Apr 27 13:34:15 2018 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpScopeModificationFilter.java Fri Apr 27 15:02:35 2018 +0200 @@ -5,12 +5,6 @@ import com.passus.config.Configuration; import com.passus.config.ConfigurationContext; import com.passus.config.annotations.NodeDefinitionCreate; -import static com.passus.config.schema.ConfigurationSchemaBuilder.enumDef; -import static com.passus.config.schema.ConfigurationSchemaBuilder.mapDef; -import static com.passus.config.schema.ConfigurationSchemaBuilder.nullValueDef; -import static com.passus.config.schema.ConfigurationSchemaBuilder.tupleDef; -import static com.passus.config.schema.ConfigurationSchemaBuilder.valueDef; -import static com.passus.config.schema.ConfigurationSchemaBuilder.valueDefBool; import com.passus.config.schema.KeyNameVaryListNodeDefinition; import com.passus.config.schema.NodeDefinition; import com.passus.config.schema.NodeDefinitionCreator; @@ -19,14 +13,17 @@ import com.passus.net.http.HttpResponse; import com.passus.st.ParametersBag; import com.passus.st.client.http.HttpFlowContext; +import com.passus.st.config.FieldValueExtractorTransformerNodeDefCreator; import com.passus.st.config.HeaderOperationNodeDefinition; import com.passus.st.plugin.PluginConstants; + import java.util.ArrayList; import java.util.Collections; import java.util.List; +import static com.passus.config.schema.ConfigurationSchemaBuilder.*; + /** - * * @author Mirosław Hawrot */ @NodeDefinitionCreate(HttpScopeModificationFilter.HttpScopeModificationFilterNodeDefCreator.class) @@ -276,13 +273,16 @@ @Override public NodeDefinition create() { + NodeDefinition fieldValExtractorNodeDef = FieldValueExtractorTransformerNodeDefCreator.createNodeDef(); HeaderOperationNodeDefinition setSessionDef = new HeaderOperationNodeDefinition( - valueDef() + fieldValExtractorNodeDef ); - setSessionDef.addParam(tupleDef("*autocreate", valueDefBool()).setRequired(false)); + setSessionDef.addParam( + tupleDef("*autocreate", valueDefBool()).setRequired(false) + ); HeaderOperationNodeDefinition setGlobalDef = new HeaderOperationNodeDefinition( - valueDef() + fieldValExtractorNodeDef ); KeyNameVaryListNodeDefinition operationsDef = new KeyNameVaryListNodeDefinition()
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpScopeModificationFilterTransformer.java Fri Apr 27 13:34:15 2018 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpScopeModificationFilterTransformer.java Fri Apr 27 15:02:35 2018 +0200 @@ -1,38 +1,28 @@ package com.passus.st.client.http.filter; -import com.passus.config.CMapNode; -import com.passus.config.CNode; -import com.passus.config.CTupleNode; -import com.passus.config.CValueNode; -import com.passus.config.ConfigurationContext; -import com.passus.config.ConfigurationUtils; -import static com.passus.config.ConfigurationUtils.extractBoolean; -import com.passus.config.NodeType; +import com.passus.config.*; import com.passus.config.schema.NodeTransformer; import com.passus.config.validation.Errors; import com.passus.filter.ValueExtractor; -import com.passus.filter.config.ExpressionNodeTransformer; -import com.passus.st.client.http.filter.HttpScopeModificationFilter.Operation; -import com.passus.st.client.http.filter.HttpScopeModificationFilter.RemoveGlobalParamOperation; -import com.passus.st.client.http.filter.HttpScopeModificationFilter.RemoveSessionOperation; -import com.passus.st.client.http.filter.HttpScopeModificationFilter.RemoveSessionParamOperation; -import com.passus.st.client.http.filter.HttpScopeModificationFilter.SetGlobalParamOperation; -import com.passus.st.client.http.filter.HttpScopeModificationFilter.SetSessionParamOperation; +import com.passus.filter.config.ValueExtractorTransformer; +import com.passus.st.client.http.filter.HttpScopeModificationFilter.*; import com.passus.st.filter.Transformers; -import static com.passus.st.validation.NodeValidationUtils.validateType; + import java.util.ArrayList; import java.util.Collections; import java.util.List; +import static com.passus.config.ConfigurationUtils.extractBoolean; +import static com.passus.st.validation.NodeValidationUtils.validateType; + /** - * * @author Mirosław Hawrot */ public class HttpScopeModificationFilterTransformer implements NodeTransformer<CValueNode> { private static SetSessionParamOperation createSetSessionParamOperation( - CTupleNode tuple, Errors errors, boolean checkValueExists, - ExpressionNodeTransformer expressionNodeTransformer) { + CTupleNode tuple, Errors errors, ConfigurationContext context, boolean checkValueExists, + ValueExtractorTransformer valueExtractorTransformer) { if (validateType(tuple.getNode(), NodeType.MAP, errors)) { CMapNode mapNode = (CMapNode) tuple.getNode(); @@ -50,7 +40,11 @@ default: try { paramName = mapTupleNode.getName(); - valueExtractor = expressionNodeTransformer.transform(mapTupleNode.getNode()); + valueExtractor = valueExtractorTransformer.transform(mapTupleNode.getNode(), errors, context); + if (errors.hasError()) { + return null; + } + } catch (Exception e) { errors.reject(mapTupleNode.getNode(), "Invalid expression."); } @@ -68,8 +62,8 @@ } private static SetGlobalParamOperation createSetGlobalParamOperation( - CTupleNode tuple, Errors errors, boolean checkValueExists, - ExpressionNodeTransformer expressionNodeTransformer) { + CTupleNode tuple, Errors errors, ConfigurationContext context, boolean checkValueExists, + ValueExtractorTransformer valueExtractorTransformer) { if (validateType(tuple.getNode(), NodeType.MAP, errors)) { CMapNode mapNode = (CMapNode) tuple.getNode(); @@ -83,11 +77,14 @@ default: try { paramName = mapTupleNode.getName(); - valueExtractor = expressionNodeTransformer.transform(mapTupleNode.getNode()); + valueExtractor = valueExtractorTransformer.transform(mapTupleNode.getNode(), errors, context); + if (errors.hasError()) { + return null; + } + } catch (Exception e) { errors.reject(mapTupleNode.getNode(), "Invalid expression."); } - } } finally { errors.popNestedPath(); @@ -112,7 +109,7 @@ operations = new ArrayList<>(); } - final ExpressionNodeTransformer transformer = Transformers.expressionNodeTransformer(context); + final ValueExtractorTransformer transformer = Transformers.fieldValueExtractorTransformer(context); for (CTupleNode tuple : tuples) { String opName = tuple.getName(); @@ -131,10 +128,10 @@ break; } case "addsessionparam": - op = createSetSessionParamOperation(tuple, errors, true, transformer); + op = createSetSessionParamOperation(tuple, errors, context, true, transformer); break; case "setsessionparam": - op = createSetSessionParamOperation(tuple, errors, false, transformer); + op = createSetSessionParamOperation(tuple, errors, context, false, transformer); break; case "removeglobalparam": { String paramName = ConfigurationUtils.extractString(tuple, errors); @@ -144,16 +141,20 @@ break; } case "addglobalparam": - op = createSetGlobalParamOperation(tuple, errors, true, transformer); + op = createSetGlobalParamOperation(tuple, errors, context, true, transformer); break; case "setglobalparam": - op = createSetGlobalParamOperation(tuple, errors, false, transformer); + op = createSetGlobalParamOperation(tuple, errors, context, false, transformer); break; default: throw new IllegalStateException("Not supported operation '" + opName + "'."); } + if (errors.hasError()) { + return null; + } + if (op != null) { operations.add(op); }
--- a/stress-tester/src/main/java/com/passus/st/config/FieldValueExtractorTransformerNodeDefCreator.java Fri Apr 27 13:34:15 2018 +0200 +++ b/stress-tester/src/main/java/com/passus/st/config/FieldValueExtractorTransformerNodeDefCreator.java Fri Apr 27 15:02:35 2018 +0200 @@ -10,9 +10,12 @@ public static NodeDefinition createNodeDef() { NodeDefinition lookupNodeDef = LookupValueExtractorDefinitionCreator.createNodeDef(); - return mapDef( - tupleDef("$expr", valueDef()).setRequired(false), - tupleDef("$lookup", lookupNodeDef).setRequired(false) + return mixedDef( + valueDef(), + mapDef( + tupleDef("$expr", valueDef()).setRequired(false), + tupleDef("$lookup", lookupNodeDef).setRequired(false) + ) ); }
--- a/stress-tester/src/main/java/com/passus/st/filter/Transformers.java Fri Apr 27 13:34:15 2018 +0200 +++ b/stress-tester/src/main/java/com/passus/st/filter/Transformers.java Fri Apr 27 15:02:35 2018 +0200 @@ -10,6 +10,7 @@ import com.passus.lookup.filter.LookupHelper; import com.passus.lookup.filter.LookupKeyExistsLeftOperatorTransformer; import com.passus.lookup.filter.LookupValueExtractorTransformer; +import com.passus.st.config.FieldValueExtractorTransformer; import com.passus.st.utils.ConfigurationContextConsts; import com.passus.st.vars.VarsExtractorResolver; @@ -28,13 +29,15 @@ public static final ValueExtractorParser VALUE_EXTRACTOR_PARSER = new ValueExtractorParser(VALUE_EXTRACTOR_RESOLVER); - public static final ExpressionNodeTransformer EXPRESSION = new ExpressionNodeTransformer(VALUE_EXTRACTOR_PARSER); + public static final ExpressionNodeTransformer EXPRESSION_NODE_TRANSFORMER = new ExpressionNodeTransformer(VALUE_EXTRACTOR_PARSER); public static final LookupHelper LOOKUP_HELPER = new LookupHelper(VALUE_EXTRACTOR_PARSER); + public static final FieldValueExtractorTransformer FIELD_VALUE_EXTRACTOR_TRANSFORMER = new FieldValueExtractorTransformer(); + public static ExpressionNodeTransformer expressionNodeTransformer(ConfigurationContext context) { - if(context == null) { - return Transformers.EXPRESSION; + if (context == null) { + return Transformers.EXPRESSION_NODE_TRANSFORMER; } Map<String, ValueExtractor> vars = (Map<String, ValueExtractor>) context.get(ConfigurationContextConsts.APP_VARS); @@ -43,10 +46,15 @@ ValueExtractorParser parser = new ValueExtractorParser(varsResolver); return new ExpressionNodeTransformer(parser); } else { - return Transformers.EXPRESSION; + return Transformers.EXPRESSION_NODE_TRANSFORMER; } } + public static FieldValueExtractorTransformer fieldValueExtractorTransformer(ConfigurationContext context) { + //Na przyszlosc + return Transformers.FIELD_VALUE_EXTRACTOR_TRANSFORMER; + } + public static LookupValueExtractorTransformer lookupValueTransformer(ConfigurationContext context) { List<Lookup> lookups; if (context == null) { @@ -69,4 +77,5 @@ return new LookupKeyExistsLeftOperatorTransformer(lookups, LOOKUP_HELPER); } + }
--- a/stress-tester/src/main/java/com/passus/st/vars/VarsConfigurator.java Fri Apr 27 13:34:15 2018 +0200 +++ b/stress-tester/src/main/java/com/passus/st/vars/VarsConfigurator.java Fri Apr 27 15:02:35 2018 +0200 @@ -22,7 +22,7 @@ */ public class VarsConfigurator { - private static final ExpressionNodeTransformer EXPR_TRANS = Transformers.EXPRESSION; + private static final ExpressionNodeTransformer EXPR_TRANS = Transformers.EXPRESSION_NODE_TRANSFORMER; public static Map<String, ValueExtractor> getGlobalVars(Configuration cfg) throws ConversionException { CMapNode root = (CMapNode) cfg.getRootNode();
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpScopeModificationFilterTest.java Fri Apr 27 13:34:15 2018 +0200 +++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpScopeModificationFilterTest.java Fri Apr 27 15:02:35 2018 +0200 @@ -10,22 +10,18 @@ import com.passus.st.client.http.HttpConsts; import com.passus.st.client.http.HttpFlowContext; import com.passus.st.client.http.HttpScopes; -import static com.passus.st.client.http.filter.HttpFilterTestUtils.createMockContext; -import com.passus.st.client.http.filter.HttpScopeModificationFilter.Operation; -import com.passus.st.client.http.filter.HttpScopeModificationFilter.RemoveGlobalParamOperation; -import com.passus.st.client.http.filter.HttpScopeModificationFilter.RemoveSessionOperation; -import com.passus.st.client.http.filter.HttpScopeModificationFilter.RemoveSessionParamOperation; -import com.passus.st.client.http.filter.HttpScopeModificationFilter.SetGlobalParamOperation; -import com.passus.st.client.http.filter.HttpScopeModificationFilter.SetSessionParamOperation; -import java.util.Arrays; -import java.util.List; -import static org.testng.AssertJUnit.*; +import com.passus.st.client.http.filter.HttpScopeModificationFilter.*; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import java.util.Arrays; +import java.util.List; + +import static com.passus.st.client.http.filter.HttpFilterTestUtils.createMockContext; +import static org.testng.AssertJUnit.*; + /** - * * @author Mirosław Hawrot */ public class HttpScopeModificationFilterTest { @@ -197,9 +193,8 @@ Errors errors = new Errors(); ConfigurationContextImpl emptyContext = new ConfigurationContextImpl(); List<HttpFilter> filters = HttpFiltersConfigurator.getFilters(cfg, errors, emptyContext); - errors.getAllErrors().forEach(System.out::println); - assertEquals(0, errors.getErrorCount()); + assertEquals(errors.toString(), 0, errors.getErrorCount()); assertEquals(1, filters.size()); assertTrue(filters.get(0) instanceof HttpScopeModificationFilter); @@ -232,28 +227,7 @@ assertEquals("value", scopes.getGlobal().get("NewGlobalParam2")); } - @Test - public void testConfiguration() throws Exception { - String filterConfig = "httpFilters:\n" - + " - type: modifyScope\n" - + " dir: both\n" - + " operations:\n" - + " removeSession: ~\n" - + " removeSessionParam: ParaName\n" - + " addSessionParam: \n" - + " NewParam1: NewParamValue1\n" - + " setSessionParam: \n" - + " \"*autocreate\": true\n" - + " NewParam2: NewParamValue2\n" - + " removeGlobalParam: GlobalParamName\n" - + " addGlobalParam: \n" - + " NewGlobalParam1: NewGlobalParamValue1\n" - + " setGlobalParam: \n" - + " NewGlobalParam2: NewGlobalParamValue2\n"; - - HttpScopeModificationFilter filter = processConfig(filterConfig); - assertEquals(HttpFilterDirection.BOTH, filter.getDirection()); - List<Operation> operations = filter.getOperations(); + private void assertOperations(List<Operation> operations) { assertEquals(7, operations.size()); assertTrue(operations.get(0) instanceof RemoveSessionOperation); assertTrue(operations.get(1) instanceof RemoveSessionParamOperation); @@ -290,6 +264,55 @@ assertEquals("NewGlobalParam2", setGlobalParamOperation.getParamName()); assertEquals("NewGlobalParamValue2", setGlobalParamOperation.getValueExtractor().extract(null)); assertEquals(false, setGlobalParamOperation.isCheckValueExists()); + } + @Test + public void testConfiguration() throws Exception { + String filterConfig = "httpFilters:\n" + + " - type: modifyScope\n" + + " dir: both\n" + + " operations:\n" + + " removeSession: ~\n" + + " removeSessionParam: ParaName\n" + + " addSessionParam: \n" + + " NewParam1: NewParamValue1\n" + + " setSessionParam: \n" + + " \"*autocreate\": true\n" + + " NewParam2: NewParamValue2\n" + + " removeGlobalParam: GlobalParamName\n" + + " addGlobalParam: \n" + + " NewGlobalParam1: NewGlobalParamValue1\n" + + " setGlobalParam: \n" + + " NewGlobalParam2: NewGlobalParamValue2\n"; + + HttpScopeModificationFilter filter = processConfig(filterConfig); + assertEquals(HttpFilterDirection.BOTH, filter.getDirection()); + List<Operation> operations = filter.getOperations(); + assertOperations(operations); + } + + @Test + public void testConfiguration_expressions() throws Exception { + String filterConfig = "httpFilters:\n" + + " - type: modifyScope\n" + + " dir: both\n" + + " operations:\n" + + " removeSession: ~\n" + + " removeSessionParam: ParaName\n" + + " addSessionParam: \n" + + " NewParam1: {$expr: 'return \"NewParamValue1\"'}\n" + + " setSessionParam: \n" + + " \"*autocreate\": true\n" + + " NewParam2: {$expr: 'return \"NewParamValue2\"'}\n" + + " removeGlobalParam: GlobalParamName\n" + + " addGlobalParam: \n" + + " NewGlobalParam1: {$expr: 'return \"NewGlobalParamValue1\"'}\n" + + " setGlobalParam: \n" + + " NewGlobalParam2: {$expr: 'return \"NewGlobalParamValue2\"'}\n"; + + HttpScopeModificationFilter filter = processConfig(filterConfig); + assertEquals(HttpFilterDirection.BOTH, filter.getDirection()); + List<Operation> operations = filter.getOperations(); + assertOperations(operations); } }