changeset 492:f7ad421d783b

HttpMessageModificationFilter understands $httpSession
author Devel 1
date Fri, 11 Aug 2017 12:33:48 +0200
parents b838d00420df
children 5be5e6e2288c
files stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFilterMessageWrapper.java stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFilterRequestWrapper.java stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTransformer.java stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageWrapper.java stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTest.java
diffstat 5 files changed, 29 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFilterMessageWrapper.java	Fri Aug 11 10:32:25 2017 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFilterMessageWrapper.java	Fri Aug 11 12:33:48 2017 +0200
@@ -9,6 +9,7 @@
 /**
  *
  * @author Mirosław Hawrot
+ * @param <T> HttpMessage
  */
 public abstract class HttpFilterMessageWrapper<T extends HttpMessage> {
 
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFilterRequestWrapper.java	Fri Aug 11 10:32:25 2017 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFilterRequestWrapper.java	Fri Aug 11 12:33:48 2017 +0200
@@ -3,6 +3,7 @@
 import com.passus.data.ByteString;
 import com.passus.net.http.HttpRequest;
 import com.passus.net.http.URL;
+import static com.passus.st.client.http.HttpConsts.TAG_SESSION_ID;
 
 /**
  *
@@ -28,5 +29,8 @@
         return message.getUri();
     }
 
-    
+    public String getSessionId() {
+        return (String) message.getTag(TAG_SESSION_ID);
+    }
+
 }
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTransformer.java	Fri Aug 11 10:32:25 2017 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTransformer.java	Fri Aug 11 12:33:48 2017 +0200
@@ -6,17 +6,15 @@
 import com.passus.config.CTupleNode;
 import com.passus.config.CValueNode;
 import com.passus.config.NodeType;
+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.HttpMessageModificationFilter.*;
+import static com.passus.st.validation.NodeValidationUtils.validateType;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
-import com.passus.config.schema.NodeTransformer;
-import com.passus.config.validation.Errors;
-import com.passus.filter.MvelValueExtractor;
-import com.passus.filter.ValueExtractor;
-import com.passus.filter.ValueExtractorParser;
-import com.passus.filter.config.ExpressionNodeTransformer;
-import static com.passus.st.validation.NodeValidationUtils.validateType;
 
 /**
  *
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageWrapper.java	Fri Aug 11 10:32:25 2017 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageWrapper.java	Fri Aug 11 12:33:48 2017 +0200
@@ -3,6 +3,7 @@
 import com.passus.net.http.HttpMessage;
 import com.passus.net.http.HttpRequest;
 import com.passus.net.http.HttpResponse;
+import com.passus.st.ParametersBag;
 import com.passus.st.client.http.HttpFlowContext;
 import com.passus.st.client.http.HttpScopes;
 import com.passus.st.emitter.SessionInfo;
@@ -61,6 +62,15 @@
         return null;
     }
 
+    public ParametersBag getHttpSession() {
+        String sessionId = req.getSessionId();
+        HttpScopes scopes = getScopes();
+        if (scopes != null && sessionId != null) {
+            return scopes.getSession(sessionId);
+        }
+        return null;
+    }
+
     private HttpFilterMessageWrapper createWrapper(HttpMessage message) {
         if (message == null) {
             return null;
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTest.java	Fri Aug 11 10:32:25 2017 +0200
+++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTest.java	Fri Aug 11 12:33:48 2017 +0200
@@ -7,6 +7,7 @@
 import com.passus.net.http.HttpRequest;
 import com.passus.net.http.HttpRequestBuilder;
 import com.passus.st.AppUtils;
+import static com.passus.st.client.http.HttpConsts.TAG_SESSION_ID;
 import com.passus.st.client.http.HttpFlowContext;
 import com.passus.st.client.http.HttpScopes;
 import com.passus.st.client.http.filter.HttpMessageModificationFilter.AddCookieOperation;
@@ -105,7 +106,9 @@
                 + "        $setHeader: \n"
                 + "            Header3: Header1Value3a\n"
                 + "        $setHeader: \n"
-                + "            Header6: \"$scopes.getSession('testId').get('testParam')\"\n";
+                + "            Header6: \"$scopes.getSession('testId').get('testParam')\"\n"
+                + "        $setHeader: \n"
+                + "            Header7: \"$httpSession.get('testParam')\"\n";
 
         Errors errors = new Errors();
         List<HttpFilter> filters = HttpFiltersConfigurator.getFilters(filterConfig, errors);
@@ -119,13 +122,13 @@
                 .header("Header2", "Header1Value2")
                 .header("Header3", "Header1Value3")
                 .header("Cookie", "myCookie1=myValue1;myCookie2=myValue2;myCookie3=myValue3")
+                .tag(TAG_SESSION_ID, "sessionId")
                 .build();
 
         HttpMessageModificationFilter filter = (HttpMessageModificationFilter) filters.get(0);
         HttpFlowContext mockContext = HttpFilterTestUtils.createMockContext();
-        final HttpScopes scopes = new HttpScopes();
-        scopes.createSession("testId").set("testParam", "exprValue");
-        when(mockContext.scopes()).thenReturn(scopes);
+        mockContext.scopes().createSession("testId").set("testParam", "exprValue");
+        mockContext.scopes().createSession("sessionId").set("testParam", "sessionValue");
         filter.filterOutbound(req, null, mockContext);
 
         HttpHeaders headers = req.getHeaders();
@@ -134,6 +137,7 @@
         assertEquals("HeaderValue5", headers.get("Header5").toString());
         assertEquals("Header1Value3a", headers.get("Header3").toString());
         assertEquals("exprValue", headers.get("Header6").toString());
+        assertEquals("sessionValue", headers.get("Header7").toString());
 
     }