changeset 881:209eea24eef2

VarsConfigurator produces 'accelerated' extractors
author Devel 1
date Mon, 05 Feb 2018 12:54:19 +0100
parents a900c4082ff7
children d993a93b541b
files stress-tester/src/main/java/com/passus/st/vars/VarsConfigurator.java stress-tester/src/test/java/com/passus/st/vars/VarsConfiguratorTest.java
diffstat 2 files changed, 17 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/vars/VarsConfigurator.java	Mon Feb 05 11:16:22 2018 +0100
+++ b/stress-tester/src/main/java/com/passus/st/vars/VarsConfigurator.java	Mon Feb 05 12:54:19 2018 +0100
@@ -10,8 +10,8 @@
 import com.passus.config.validation.Errors;
 import com.passus.config.validation.ObjectError;
 import com.passus.filter.ValueExtractor;
-import com.passus.filter.ValueExtractorParser;
 import com.passus.filter.config.ExpressionNodeTransformer;
+import com.passus.st.filter.Transformers;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -22,8 +22,7 @@
  */
 public class VarsConfigurator {
 
-    private static final ValueExtractorParser PARSER = ValueExtractorParser.DEFAULT;
-    private static final ExpressionNodeTransformer EXPR_TRANS = new ExpressionNodeTransformer(PARSER);
+    private static final ExpressionNodeTransformer EXPR_TRANS = Transformers.EXPRESSION;
 
     public static Map<String, ValueExtractor> getGlobalVars(Configuration cfg) throws ConversionException {
         CMapNode root = (CMapNode) cfg.getRootNode();
--- a/stress-tester/src/test/java/com/passus/st/vars/VarsConfiguratorTest.java	Mon Feb 05 11:16:22 2018 +0100
+++ b/stress-tester/src/test/java/com/passus/st/vars/VarsConfiguratorTest.java	Mon Feb 05 12:54:19 2018 +0100
@@ -2,9 +2,14 @@
 
 import com.passus.config.Configuration;
 import com.passus.config.YamlConfigurationReader;
+import com.passus.filter.BeanValueExtractor;
 import com.passus.filter.MvelValueExtractor;
 import com.passus.filter.UnmutableValueExtractor;
 import com.passus.filter.ValueExtractor;
+import com.passus.net.http.HttpRequest;
+import com.passus.net.http.HttpRequestBuilder;
+import com.passus.st.client.http.filter.HttpMessageWrapper;
+import com.passus.st.filter.HttpMessageWrapperDynamicExtractor;
 import static com.passus.st.vars.VarsConfigurator.getGlobalVars;
 import java.util.Map;
 import static org.testng.AssertJUnit.*;
@@ -20,12 +25,13 @@
     public void testGetGlobalVars_map() throws Exception {
         String varsFile = "globalVars:\n"
                 + "    var1: \"value1\"\n"
-                + "    var2: {$expr: \"return 'value2'\"\n}";
+                + "    var2: {$expr: \"return 'value2'\"}\n"
+                + "    var3: '@req.url'\n";
 
         Configuration cfg = YamlConfigurationReader.readFromString(varsFile);
         Map<String, ValueExtractor> vars = getGlobalVars(cfg);
 
-        assertEquals(2, vars.size());
+        assertEquals(3, vars.size());
 
         ValueExtractor uve = vars.get("var1");
         assertTrue(uve instanceof UnmutableValueExtractor);
@@ -34,6 +40,13 @@
         ValueExtractor mve = vars.get("var2");
         assertTrue(mve instanceof MvelValueExtractor);
         assertEquals("value2", mve.extract(null));
+
+        ValueExtractor ve = vars.get("var3");
+        HttpRequest request = HttpRequestBuilder.get("http://example.com/path").build();
+        HttpMessageWrapper wrapper = new HttpMessageWrapper(request, null, null);
+        assertEquals("http://example.com/path", ve.extract(wrapper).toString());
+        assertTrue(ve instanceof HttpMessageWrapperDynamicExtractor);
+//        assertTrue(ve instanceof BeanValueExtractor || ve instanceof HttpMessageWrapperDynamicExtractor);
     }
 
 }