changeset 448:a9323277e4d4

HttpMessageModficationFilter predicate bugfix
author Devel 2
date Mon, 31 Jul 2017 12:12:23 +0200
parents b94661105617
children dbc7a42e5db3
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, 44 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilter.java	Mon Jul 31 11:43:07 2017 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilter.java	Mon Jul 31 12:12:23 2017 +0200
@@ -314,7 +314,7 @@
 
     private MessageType messageType = MessageType.Request;
 
-    private Predicate predicate;
+    private HttpMessagePredicate predicate;
 
     public Direction getDirection() {
         return direction;
@@ -325,11 +325,11 @@
         this.direction = direction;
     }
 
-    public Predicate getPredicate() {
+    public HttpMessagePredicate getPredicate() {
         return predicate;
     }
 
-    public void setPredicate(Predicate predicate) {
+    public void setPredicate(HttpMessagePredicate predicate) {
         this.predicate = predicate;
     }
 
@@ -369,7 +369,7 @@
             }
         }
 
-        predicate = (Predicate) config.get("applyIf");
+        predicate = (HttpMessagePredicate) config.get("applyIf");
     }
 
     List<Operation> getOutOps() {
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTest.java	Mon Jul 31 11:43:07 2017 +0200
+++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTest.java	Mon Jul 31 12:12:23 2017 +0200
@@ -6,10 +6,14 @@
 import com.passus.net.http.HttpParameters;
 import com.passus.net.http.HttpRequest;
 import com.passus.net.http.HttpRequestBuilder;
+import com.passus.st.AppUtils;
 import com.passus.st.client.http.filter.HttpMessageModificationFilter.*;
 import java.util.Arrays;
 import java.util.List;
 import static org.testng.AssertJUnit.*;
+import org.testng.TestNG;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
 /**
@@ -20,6 +24,16 @@
 
     private final HttpMessageHelper helper = HttpMessageHelper.NOT_STRICT;
 
+    @BeforeClass
+    public static void beforeClass() {
+        AppUtils.registerAll();
+    }
+
+    @AfterClass
+    public static void afterClass() {
+        AppUtils.unregisterAll();
+    }
+
     @Test
     public void testFilterOutbound() throws Exception {
         HttpRequest req = HttpRequestBuilder.post("http://test.com/path/test", "param1=value1&param2=value2&param3=value3")
@@ -97,4 +111,30 @@
         assertEquals("Header1Value3a", headers.get("Header3").toString());
 
     }
+
+    @Test
+    public void testConfigure_ApplyIf() throws Exception {
+        HttpRequest req = HttpRequestBuilder.post("http://test.com/path/test")
+                .header("Header1", "Header1Value1")
+                .build();
+
+        String filterConfig = "filters:\n"
+                + "    - type: modifyMessage\n"
+                + "      applyIf:\n"
+                + "        \"req.uri\": /path/test\n"
+                + "      operations:\n"
+                + "        $removeHeader: Header1\n";
+
+        Errors errors = new Errors();
+        List<HttpFilter> filters = HttpFiltersConfigurator.getFilters(filterConfig, errors);
+
+        assertEquals(0, errors.getErrorCount());
+        assertEquals(1, filters.size());
+        assertTrue(filters.get(0) instanceof HttpMessageModificationFilter);
+
+        HttpMessageModificationFilter filter = (HttpMessageModificationFilter) filters.get(0);
+        filter.filterOutbound(req, null, null);
+
+        assertFalse(req.getHeaders().contains("Header1"));
+    }
 }