changeset 882:d993a93b541b

minor
author Devel 1
date Mon, 05 Feb 2018 12:57:12 +0100
parents 209eea24eef2
children 9cc298ac7305
files stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFiltersNodeDefinitionCreator.java stress-tester/src/main/java/com/passus/st/filter/HttpMessageWrapperDynamicExtractor.java stress-tester/src/test/java/com/passus/st/client/http/filter/HttpVarsFilterTest.java
diffstat 3 files changed, 29 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFiltersNodeDefinitionCreator.java	Mon Feb 05 12:54:19 2018 +0100
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFiltersNodeDefinitionCreator.java	Mon Feb 05 12:57:12 2018 +0100
@@ -1,10 +1,8 @@
 package com.passus.st.client.http.filter;
 
-import static com.passus.config.schema.ConfigurationSchemaBuilder.*;
 import com.passus.config.schema.DynaKeyValueVaryListNodeDefinition;
 import com.passus.config.schema.NodeDefinition;
 import com.passus.config.schema.NodeDefinitionCreator;
-import static com.passus.config.schema.ConfigurationSchemaBuilder.*;
 
 /**
  *
--- a/stress-tester/src/main/java/com/passus/st/filter/HttpMessageWrapperDynamicExtractor.java	Mon Feb 05 12:54:19 2018 +0100
+++ b/stress-tester/src/main/java/com/passus/st/filter/HttpMessageWrapperDynamicExtractor.java	Mon Feb 05 12:57:12 2018 +0100
@@ -105,4 +105,9 @@
         return Objects.equals(fieldName, other.fieldName) && Objects.equals(fallbackExtractor, other.fallbackExtractor);
     }
 
+    @Override
+    public String toString() {
+        return "dynamic{" + fieldName + '}';
+    }
+
 }
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpVarsFilterTest.java	Mon Feb 05 12:54:19 2018 +0100
+++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpVarsFilterTest.java	Mon Feb 05 12:57:12 2018 +0100
@@ -13,6 +13,7 @@
 import com.passus.net.http.HttpMethod;
 import com.passus.net.http.HttpRequest;
 import com.passus.net.http.HttpRequestBuilder;
+import com.passus.st.filter.Transformers;
 import com.passus.st.utils.TestHttpUtils;
 import java.io.IOException;
 import java.nio.charset.Charset;
@@ -30,6 +31,7 @@
     private static final Charset UTF_8 = Charset.forName("UTF-8");
 
     private final Map<String, ValueExtractor> appVars = map(
+            e("var0", expr("req.url")),
             e("var1", val("value1")),
             e("name", val("X")),
             e("type", val("x"))
@@ -39,6 +41,10 @@
         return new UnmutableValueExtractor(o);
     }
 
+    private static ValueExtractor expr(String expr) {
+        return Transformers.VALUE_EXTRACTOR_RESOLVER.resolveValueExtractor(expr);
+    }
+
     private static String content(HttpDataContainer container, Charset ch) throws IOException {
         return DataSourceUtils.toString(container.getContent(), ch);
     }
@@ -139,7 +145,7 @@
     }
 
     @Test
-    public void testPut() throws IOException {
+    public void testPut_contentRefsMsg() throws IOException {
         String content = "{\"abc\": \"{@appVars.var1}\", \"def\": \"{@req.url}\"}";
         String expected = "{\"abc\": \"value1\", \"def\": \"http://test.com\"}";
 
@@ -156,6 +162,23 @@
     }
 
     @Test
+    public void testPut_varRefsMsg() throws IOException {
+        String content = "{\"abc\": \"{@appVars.var1}\", \"def\": \"{@appVars.var0}\"}";
+        String expected = "{\"abc\": \"value1\", \"def\": \"http://test.com\"}";
+
+        HttpRequestBuilder builder = new HttpRequestBuilder("http://test.com", HttpMethod.PUT);
+        builder.content(content, "application/json");
+        HttpRequest request = builder.build();
+
+        HttpVarsFilter filter = new HttpVarsFilter(appVars);
+        filter.filterOutbound(request, null, null);
+
+        int contentLength = (int) HttpMessageHelper.get().getContentLength(request);
+        assertEquals(expected, content(request, UTF_8));
+        assertEquals(expected.length(), contentLength);
+    }
+
+    @Test
     public void testPutDeflate() throws IOException {
         String json = "{\"abc\": \"{@appVars.var1}\"}";
         byte[] plain = json.getBytes(); //18