changeset 807:40a0874688b0

HttpMessageValueExtractorResolver bugfix, HttpScopeModificationFilterTest.testSetGlobalParamOperation_Extractors
author Devel 2
date Mon, 08 Jan 2018 09:38:08 +0100
parents 763539ab7343
children 5937f6f7c231
files stress-tester/src/main/java/com/passus/st/filter/HttpMessageValueExtractorResolver.java stress-tester/src/test/java/com/passus/st/client/http/filter/HttpScopeModificationFilterTest.java
diffstat 2 files changed, 46 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/filter/HttpMessageValueExtractorResolver.java	Thu Jan 04 16:22:08 2018 +0100
+++ b/stress-tester/src/main/java/com/passus/st/filter/HttpMessageValueExtractorResolver.java	Mon Jan 08 09:38:08 2018 +0100
@@ -18,9 +18,14 @@
         HttpMessageHeaderValueExtractor.Operation operation = HttpMessageHeaderValueExtractor.createForFunction(fieldName);
         if (operation != null) {
             return new HttpMessageHeaderValueExtractor(operation, valueExtractor);
-        } else {
-            return new HttpMessageValueExtractor(fieldName, valueExtractor);
         }
+
+        operation = HttpMessageHeaderValueExtractor.createForShortForm(fieldName);
+        if (operation != null) {
+            return new HttpMessageHeaderValueExtractor(operation, valueExtractor);
+        }
+
+        return new HttpMessageValueExtractor(fieldName, valueExtractor);
     }
 
 }
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpScopeModificationFilterTest.java	Thu Jan 04 16:22:08 2018 +0100
+++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpScopeModificationFilterTest.java	Mon Jan 08 09:38:08 2018 +0100
@@ -2,6 +2,7 @@
 
 import com.passus.config.validation.Errors;
 import com.passus.filter.UnmutableValueExtractor;
+import com.passus.net.MimeTypes;
 import com.passus.net.http.HttpRequest;
 import com.passus.net.http.HttpRequestBuilder;
 import com.passus.st.AppUtils;
@@ -160,6 +161,43 @@
         assertEquals("newParamValue", scopes.getGlobal().get("paramName"));
     }
 
+    private HttpScopeModificationFilter processConfig(String cfg) throws Exception {
+        Errors errors = new Errors();
+        List<HttpFilter> filters = HttpFiltersConfigurator.getFilters(cfg, errors, null);
+
+        assertEquals(0, errors.getErrorCount());
+        assertEquals(1, filters.size());
+        assertTrue(filters.get(0) instanceof HttpScopeModificationFilter);
+
+        return (HttpScopeModificationFilter) filters.get(0);
+    }
+
+    @Test
+    public void testSetGlobalParamOperation_Extractors() throws Exception {
+        String filterConfig = "filters:\n"
+                + "    - type: modifyScope\n"
+                + "      operations:\n"
+                + "        setGlobalParam: \n"
+                + "           NewGlobalParam1: '@req.uri'\n"
+                + "        setGlobalParam: \n"
+                + "           NewGlobalParam2: '@req.content@json:$.node'\n";
+
+        HttpScopeModificationFilter filter = processConfig(filterConfig);
+        List<Operation> operations = filter.getOperations();
+        assertEquals(2, operations.size());
+
+        HttpFlowContext mockContext = createMockContext();
+        HttpScopes scopes = mockContext.scopes();
+
+        HttpRequest req = HttpRequestBuilder
+                .post("http://test.com/test")
+                .content("{node:\"value\"}", MimeTypes.APPLICATION_JSON)
+                .build();
+        filter.filterOutbound(req, null, mockContext);
+        assertEquals(req.getUri(), scopes.getGlobal().get("NewGlobalParam1"));
+        assertEquals("value", scopes.getGlobal().get("NewGlobalParam2"));
+    }
+
     @Test
     public void testConfiguration() throws Exception {
         String filterConfig = "filters:\n"
@@ -178,14 +216,7 @@
                 + "        setGlobalParam: \n"
                 + "           NewGlobalParam2: NewGlobalParamValue2\n";
 
-        Errors errors = new Errors();
-        List<HttpFilter> filters = HttpFiltersConfigurator.getFilters(filterConfig, errors, null);
-
-        assertEquals(0, errors.getErrorCount());
-        assertEquals(1, filters.size());
-        assertTrue(filters.get(0) instanceof HttpScopeModificationFilter);
-
-        HttpScopeModificationFilter filter = (HttpScopeModificationFilter) filters.get(0);
+        HttpScopeModificationFilter filter = processConfig(filterConfig);
         List<Operation> operations = filter.getOperations();
         assertEquals(7, operations.size());
         assertTrue(operations.get(0) instanceof RemoveSessionOperation);