changeset 512:1f1e517202a3

HttpSessionCookieFilter testConfigure
author Devel 1
date Fri, 18 Aug 2017 10:39:13 +0200
parents 9157b42b96a3
children f74d8efe85b9
files stress-tester/src/main/java/com/passus/st/client/http/filter/HttpSessionCookieFilter.java stress-tester/src/test/java/com/passus/st/client/http/filter/HttpSessionCookieFilterTest.java
diffstat 2 files changed, 28 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpSessionCookieFilter.java	Fri Aug 18 10:02:13 2017 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpSessionCookieFilter.java	Fri Aug 18 10:39:13 2017 +0200
@@ -70,6 +70,10 @@
         this.removeInvalidSessionId = removeInvalidSessionId;
     }
 
+    public Set<CharSequence> getCookieNames() {
+        return cookieNames;
+    }
+
     public boolean isRemoveInvalidSessionId() {
         return removeInvalidSessionId;
     }
@@ -103,7 +107,7 @@
     public void configure(Configuration config) {
         cookieNames.clear();
         cookieNames.addAll((Collection) config.get("sessionCookieNames", DEFAULT_COOKIE_NAMES));
-        removeInvalidSessionId = (Boolean) config.get("removeInvalidSessionId", true);
+        removeInvalidSessionId = (Boolean) config.get("removeInvalidSessionId", false);
     }
 
     @Override
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpSessionCookieFilterTest.java	Fri Aug 18 10:02:13 2017 +0200
+++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpSessionCookieFilterTest.java	Fri Aug 18 10:39:13 2017 +0200
@@ -1,5 +1,6 @@
 package com.passus.st.client.http.filter;
 
+import com.passus.config.validation.Errors;
 import com.passus.net.http.HttpCookie;
 import com.passus.net.http.HttpMessageHelper;
 import com.passus.net.http.HttpRequest;
@@ -10,6 +11,9 @@
 import com.passus.st.client.http.HttpFlowContext;
 import static com.passus.st.client.http.filter.HttpFilterTestUtils.createMockContext;
 import static com.passus.st.utils.TestHttpUtils.*;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
 import static org.mockito.Mockito.when;
 import static org.testng.Assert.*;
 import org.testng.annotations.Test;
@@ -245,4 +249,23 @@
         assertEquals(cookie.getValue().toString(), "newSessId");
     }
 
+    @Test
+    public void testConfigure() throws Exception {
+        String filterConfig = "filters:\n"
+                + "    - type: session\n"
+                + "      sessionCookieNames: [aaa, bbb]\n"
+                + "      removeInvalidSessionId: true\n";
+
+        Errors errors = new Errors();
+        List<HttpFilter> filters = HttpFiltersConfigurator.getFilters(filterConfig, errors);
+        HttpFilterTestUtils.printErrors(errors);
+
+        assertEquals(0, errors.getErrorCount());
+        assertEquals(1, filters.size());
+        assertTrue(filters.get(0) instanceof HttpSessionCookieFilter);
+
+        HttpSessionCookieFilter filter = (HttpSessionCookieFilter) filters.get(0);
+        assertTrue(filter.isRemoveInvalidSessionId());
+        assertEquals(filter.getCookieNames(), new HashSet<>(Arrays.asList("aaa", "bbb")));
+    }
 }