changeset 571:7dcd63785b44

HttpSequenceFilterTest - testing more features
author Devel 1
date Tue, 26 Sep 2017 16:37:30 +0200
parents 1304d9e5a8cd
children b9420fb384f2
files stress-tester/src/test/java/com/passus/st/client/http/filter/HttpSequenceFilterTest.java stress-tester/src/test/resources/com/passus/st/client/http/filter/sequence.yml
diffstat 2 files changed, 17 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpSequenceFilterTest.java	Tue Sep 26 16:15:22 2017 +0200
+++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpSequenceFilterTest.java	Tue Sep 26 16:37:30 2017 +0200
@@ -62,14 +62,15 @@
         TestHttpSequenceListener listener = new TestHttpSequenceListener();
 
         SequenceItem[] seqItems = {
-            item("{\"req.uri\": \"/res1\", \"resp.getCookie('id')\": \"123\"}", 0),
-            item("{\"req.getHeader('xyz')\": \"abc\"}", 1),};
+            item("{\"req.uri\": \"/res1\", \"resp.getCookie('id')\": {$neq: \"0\"}}", 0),
+            item("{\"req.getHeader('xyz')\": \"abc\", \"req.getCookie('id')\": \"$_i0.resp.getCookie('id')\"}", 1, "last"),};
 
         Map<String, ValueExtractor> values = new HashMap<>();
         values.put("code", value("$_i0.resp.status.code"));
         values.put("xhost", value("$_i0.req.url.host"));
         values.put("header", value("$_i1.req.getHeader('xyz')"));
-        values.put("cookie", value("$_i1.req.getCookie('id')"));
+        values.put("cookie", value("$last.req.getCookie('id')"));
+        values.put("seqName", value("example sequence"));
 
         HttpSequenceFilter filter = new HttpSequenceFilter().instanceForWorker(0);
         filter.setListener(listener);
@@ -85,6 +86,7 @@
         assertEquals("example.com", extracted.get("xhost").toString());
         assertEquals("abc", extracted.get("header").toString());
         assertEquals("123", extracted.get("cookie").toString());
+        assertEquals("example sequence", extracted.get("seqName").toString());
     }
 
     private static SequenceItem item(String predicateString, int num) throws Exception {
@@ -92,6 +94,13 @@
         return new SequenceItem(predicate, num);
     }
 
+    private static SequenceItem item(String predicateString, int num, String alias) throws Exception {
+        Predicate predicate = TRANSFORMER.transform(predicateString);
+        SequenceItem si = new SequenceItem(predicate, num);
+        si.setAlias(alias);
+        return si;
+    }
+
     private static ValueExtractor value(String s) throws ParseException {
         return ValueExtractorParser.DEFAULT.parse(s);
     }
@@ -118,7 +127,7 @@
         AndPredicate p0 = (AndPredicate) seqItems[0].getPredicate();
         assertEquals(2, p0.getSubPredicates().size());
         ComparisonPredicate sp1 = (ComparisonPredicate) p0.getSubPredicates().get(1);
-        assertEquals(ComparisonOperator.EQUAL, sp1.getOperator());
+        assertEquals(ComparisonOperator.NOT_EQUAL, sp1.getOperator());
         assertEquals("resp.getCookie('id')", sp1.getFieldName());
         UnmutableValueExtractor uve = (UnmutableValueExtractor) sp1.getPattern();
         assertEquals(123, uve.extract(null));
@@ -128,7 +137,7 @@
         ValueExtractor extractor = values.get("header");
         assertTrue(extractor instanceof BeanValueExtractor);
         BeanValueExtractor bve = (BeanValueExtractor) extractor;
-        assertEquals("_i1.req.getHeader('xyz')", bve.getFieldName());
+        assertEquals("last.req.getHeader('xyz')", bve.getFieldName());
     }
 
     private static void assertSeqItemValue(SequenceItem item, int num, long time, String alias) {
--- a/stress-tester/src/test/resources/com/passus/st/client/http/filter/sequence.yml	Tue Sep 26 16:15:22 2017 +0200
+++ b/stress-tester/src/test/resources/com/passus/st/client/http/filter/sequence.yml	Tue Sep 26 16:37:30 2017 +0200
@@ -1,13 +1,13 @@
 filters:
   - type: sequence
     sequence:
-      - match: {"req.uri": "/res1", "resp.getCookie('id')": "123"}
-      - match: {"req.getHeader('xyz')": "abc"}
+      - match: {req.uri: "/res1", resp.getCookie('id'): {$neq: "123"}}
+      - match: {req.getHeader('xyz'): "abc"}
         mustOccur: true
         time: 20000
         alias: last
     values:
         code: $_i0.resp.status.code
         xhost: $_i0.req.url.host
-        header: $_i1.req.getHeader('xyz')
+        header: $last.req.getHeader('xyz')
         cookie: $_i1.req.getCookie('id')