changeset 511:9157b42b96a3

minor
author Devel 1
date Fri, 18 Aug 2017 10:02:13 +0200
parents 8d813f86d0c1
children 1f1e517202a3
files stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilter.java stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTest.java
diffstat 2 files changed, 25 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilter.java	Thu Aug 17 15:37:36 2017 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilter.java	Fri Aug 18 10:02:13 2017 +0200
@@ -354,20 +354,8 @@
             this.extractor = extractor;
         }
 
-        protected Object extractValue(HttpRequest req, HttpResponse resp, HttpFlowContext context) {
-            Object value = null;
-            if (extractor instanceof UnmutableValueExtractor) {
-                value = extractor.extract(null);
-            } else {
-                HttpMessageWrapper wrapper = new HttpMessageWrapper(req, resp, context);
-                value = extractor.extract(wrapper);
-            }
-
-            return value;
-        }
-
         protected void doAdd(HttpParameters params, HttpRequest req, HttpResponse resp, HttpFlowContext context) {
-            Object value = extractValue(req, resp, context);
+            Object value = HttpFiltersUtils.extractValue(extractor, req, resp, context);
             try {
                 if (value instanceof CharSequence) {
                     params.add(name, (CharSequence) value);
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTest.java	Thu Aug 17 15:37:36 2017 +0200
+++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTest.java	Fri Aug 18 10:02:13 2017 +0200
@@ -139,6 +139,30 @@
 
     }
 
+    @Test
+    public void testComplexExpression() throws Exception {
+        String filterConfig = "filters:\n"
+                + "    - type: modifyMessage\n"
+                + "      operations:\n"
+                + "        $setQueryParam: \n"
+                + "            v1: {$expr: \"$httpSession.get('testParam2') or 'aaa'\"}\n"
+                + "        $setQueryParam: \n"
+                + "            v2: {$expr: \"$httpSession.get('testParam2') or $httpSession.get('testParam')\"}\n";
+
+        HttpRequest req = HttpRequestBuilder.get("http://test.com/path/test")
+                .tag(TAG_SESSION_ID, "sessionId")
+                .build();
+
+        Errors errors = new Errors();
+        List<HttpFilter> filters = HttpFiltersConfigurator.getFilters(filterConfig, errors);
+
+        HttpMessageModificationFilter filter = (HttpMessageModificationFilter) filters.get(0);
+        HttpFlowContext mockContext = HttpFilterTestUtils.createMockContext();
+        mockContext.scopes().createSession("sessionId").set("testParam", "sessionValue");
+        filter.filterOutbound(req, null, mockContext);
+        assertEquals("/path/test?v1=aaa&v2=sessionValue", req.getUri().toString());
+    }
+
     @Test(enabled = true)
     public void testConfigure_ApplyIf() throws Exception {
         HttpRequest req = HttpRequestBuilder.post("http://test.com/path/test")