Mercurial > stress-tester
changeset 494:9d398ff524b2
ST-74 HttpMessageModificationFilterTransformer
author | Devel 1 |
---|---|
date | Sat, 12 Aug 2017 18:08:28 +0200 |
parents | 5be5e6e2288c |
children | a9ad9e016d6c |
files | stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTransformer.java stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTransformerTest.java |
diffstat | 2 files changed, 74 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTransformer.java Sat Aug 12 17:05:43 2017 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTransformer.java Sat Aug 12 18:08:28 2017 +0200 @@ -157,10 +157,11 @@ op = createNameOperation(tuple, errors, RemoveQueryParameterOperation.class); break; case "$addqueryparam": - op = createAddParamOperation(tuple, errors, AddQueryParameterOperation.class); + op = createNameValueOperation(tuple, errors, AddQueryParameterOperation.class); break; case "$setqueryparam": - op = createAddParamOperation(tuple, errors, SetQueryParameterOperation.class); + op = createNameValueOperation(tuple, errors, SetQueryParameterOperation.class); + break; default: throw new IllegalStateException("Not supported operation '" + opName + "'."); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTransformerTest.java Sat Aug 12 18:08:28 2017 +0200 @@ -0,0 +1,71 @@ +package com.passus.st.client.http.filter; + +import com.passus.config.CMapNode; +import com.passus.config.CTupleNode; +import com.passus.config.CValueNode; +import com.passus.config.YamlConfigurationReader; +import com.passus.config.validation.Errors; +import com.passus.st.client.http.filter.HttpMessageModificationFilter.*; +import java.util.List; +import static org.testng.AssertJUnit.*; +import org.testng.annotations.Test; + +/** + * + * @author mikolaj.podbielski + */ +public class HttpMessageModificationFilterTransformerTest { + + HttpMessageModificationFilterTransformer transformer = new HttpMessageModificationFilterTransformer(); + + private static CTupleNode read(String content) throws Exception { + CMapNode mapNode = (CMapNode) YamlConfigurationReader.readNodeFromString(content); + return mapNode.getFirstChild(); + } + + @Test + public void testTransform() throws Exception { + String config = "operations:\n" + + " $removeHeader: H1\n" + + " $setHeader:\n" + + " H2: value\n" + + " $addHeader:\n" + + " H3: value\n" + + " $removeCookie: C1\n" + + " $setCookie:\n" + + " C2: value\n" + + " $addCookie:\n" + + " C3: value\n" + + " $removeQueryParam: Q1\n" + + " $setQueryParam:\n" + + " Q2: value\n" + + " $addQueryParam:\n" + + " Q3: value\n" + + " $removePostParam: P1\n" + + " $setPostParam:\n" + + " P2: value\n" + + " $addPostParam:\n" + + " P3: value"; + CTupleNode node = read(config); + + Errors errors = new Errors(); + CValueNode value = transformer.transform(node.getNode(), errors); + List<Operation> operations = (List) value.getValue(); + + assertEquals(0, errors.getErrorCount()); + assertEquals(12, operations.size()); + assertTrue(operations.get(0) instanceof RemoveHeaderOperation); + assertTrue(operations.get(1) instanceof SetHeaderOperation); + assertTrue(operations.get(2) instanceof AddHeaderOperation); + assertTrue(operations.get(3) instanceof RemoveCookieOperation); + assertTrue(operations.get(4) instanceof SetCookieOperation); + assertTrue(operations.get(5) instanceof AddCookieOperation); + assertTrue(operations.get(6) instanceof RemoveQueryParameterOperation); + assertTrue(operations.get(7) instanceof SetQueryParameterOperation); + assertTrue(operations.get(8) instanceof AddQueryParameterOperation); + assertTrue(operations.get(9) instanceof PostDataRemoveParamOperation); + assertTrue(operations.get(10) instanceof PostDataSetParamOperation); + assertTrue(operations.get(11) instanceof PostDataAddParamOperation); + } + +}