Mercurial > stress-tester
changeset 834:3606eff602c0
modifyScope/modifyMessage - testDirection
author | Devel 1 |
---|---|
date | Mon, 22 Jan 2018 10:13:38 +0100 |
parents | 5935b04ed679 |
children | 32c92e015459 |
files | stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTest.java stress-tester/src/test/java/com/passus/st/client/http/filter/HttpScopeModificationFilterTest.java |
diffstat | 2 files changed, 57 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTest.java Fri Jan 19 14:38:13 2018 +0100 +++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTest.java Mon Jan 22 10:13:38 2018 +0100 @@ -4,7 +4,6 @@ import com.passus.net.MimeTypes; import com.passus.net.http.HttpHeaders; import com.passus.net.http.HttpMessageHelper; -import com.passus.net.http.HttpParameters; import com.passus.net.http.HttpRequest; import com.passus.net.http.HttpRequestBuilder; import com.passus.st.AppUtils; @@ -134,6 +133,29 @@ assertEquals(expectedContent, filteredContent); } + @Test + public void testDirection() { + HttpMessageModificationFilter filterIn = createFilter("in", HttpFilterDirection.IN); + HttpMessageModificationFilter filterOut = createFilter("out", HttpFilterDirection.OUT); + HttpMessageModificationFilter filterBoth = createFilter("both", HttpFilterDirection.BOTH); + List<HttpMessageModificationFilter> filters = Arrays.asList(filterIn, filterOut, filterBoth); + + HttpRequest req1 = HttpRequestBuilder.get("http://example.com").build(); + filters.forEach((HttpMessageModificationFilter f) -> f.filterOutbound(req1, null, null)); + assertEquals("?out=out&both=both", req1.getUri().toString()); + + HttpRequest req2 = HttpRequestBuilder.get("http://example.com").build(); + filters.forEach((HttpMessageModificationFilter f) -> f.filterInbound(req2, null, null)); + assertEquals("?in=in&both=both", req2.getUri().toString()); + } + + private HttpMessageModificationFilter createFilter(String param, HttpFilterDirection dir) { + HttpMessageModificationFilter filter = new HttpMessageModificationFilter(); + filter.addOperation(new SetQueryParameterOperation(param, param)); + filter.setDirection(dir); + return filter; + } + @Test(enabled = true) public void testConfigureAndFilterOutbound() throws Exception { String filterConfig = "filters:\n"
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpScopeModificationFilterTest.java Fri Jan 19 14:38:13 2018 +0100 +++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpScopeModificationFilterTest.java Mon Jan 22 10:13:38 2018 +0100 @@ -16,6 +16,7 @@ import com.passus.st.client.http.filter.HttpScopeModificationFilter.RemoveSessionParamOperation; import com.passus.st.client.http.filter.HttpScopeModificationFilter.SetGlobalParamOperation; import com.passus.st.client.http.filter.HttpScopeModificationFilter.SetSessionParamOperation; +import java.util.Arrays; import java.util.List; import static org.testng.AssertJUnit.*; import org.testng.annotations.AfterClass; @@ -161,9 +162,40 @@ assertEquals("newParamValue", scopes.getGlobal().get("paramName")); } + @Test + public void testDirection() { + HttpFlowContext mockContext = createMockContext(); + HttpScopes scopes = mockContext.scopes(); + HttpRequest req = createRequest(); + + HttpScopeModificationFilter filterIn = createFilter("in", HttpFilterDirection.IN); + HttpScopeModificationFilter filterOut = createFilter("out", HttpFilterDirection.OUT); + HttpScopeModificationFilter filterBoth = createFilter("both", HttpFilterDirection.BOTH); + List<HttpScopeModificationFilter> filters = Arrays.asList(filterIn, filterOut, filterBoth); + + filters.forEach((HttpScopeModificationFilter f) -> f.filterOutbound(req, null, mockContext)); + assertNull(scopes.getGlobal().get("in")); + assertNotNull(scopes.getGlobal().get("out")); + assertNotNull(scopes.getGlobal().get("both")); + + scopes.clear(); + filters.forEach((HttpScopeModificationFilter f) -> f.filterInbound(req, null, mockContext)); + assertNotNull(scopes.getGlobal().get("in")); + assertNull(scopes.getGlobal().get("out")); + assertNotNull(scopes.getGlobal().get("both")); + } + + private HttpScopeModificationFilter createFilter(String paramName, HttpFilterDirection dir) { + HttpScopeModificationFilter filter = new HttpScopeModificationFilter(); + filter.addOperation(new SetGlobalParamOperation(paramName, oldValue, false)); + filter.setDirection(dir); + return filter; + } + private HttpScopeModificationFilter processConfig(String cfg) throws Exception { Errors errors = new Errors(); List<HttpFilter> filters = HttpFiltersConfigurator.getFilters(cfg, errors, null); + errors.getAllErrors().forEach(System.out::println); assertEquals(0, errors.getErrorCount()); assertEquals(1, filters.size()); @@ -202,6 +234,7 @@ public void testConfiguration() throws Exception { String filterConfig = "filters:\n" + " - type: modifyScope\n" + + " dir: both\n" + " operations:\n" + " removeSession: ~\n" + " removeSessionParam: ParaName\n" @@ -217,6 +250,7 @@ + " NewGlobalParam2: NewGlobalParamValue2\n"; HttpScopeModificationFilter filter = processConfig(filterConfig); + assertEquals(HttpFilterDirection.BOTH, filter.getDirection()); List<Operation> operations = filter.getOperations(); assertEquals(7, operations.size()); assertTrue(operations.get(0) instanceof RemoveSessionOperation);