Mercurial > stress-tester
changeset 645:588ad36681a1
refactoring
author | Devel 1 |
---|---|
date | Wed, 08 Nov 2017 11:08:43 +0100 |
parents | 68dea2ebc0bd |
children | cbf6caefb2f6 |
files | stress-tester/src/test/java/com/passus/st/client/http/filter/HttpFilterTestUtils.java stress-tester/src/test/java/com/passus/st/client/http/filter/HttpLogoutFilterTest.java stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMatchFilterTest.java stress-tester/src/test/java/com/passus/st/client/http/filter/HttpZoneFilterTest.java |
diffstat | 4 files changed, 19 insertions(+), 50 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpFilterTestUtils.java Wed Nov 08 11:07:10 2017 +0100 +++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpFilterTestUtils.java Wed Nov 08 11:08:43 2017 +0100 @@ -9,8 +9,10 @@ import static com.passus.st.client.http.HttpConsts.ZONE_DEFAULT; import com.passus.st.client.http.HttpFlowContext; import com.passus.st.client.http.HttpScopes; +import com.passus.st.filter.Transformers; import java.util.List; import java.util.Map; +import java.util.function.Predicate; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -27,6 +29,15 @@ return mockContext; } + protected static HttpMessagePredicate createPredicate(String config) { + try { + Predicate predicate = Transformers.PREDICATE.transform(config); + return new HttpMessagePredicate(predicate); + } catch (Exception e) { + throw new RuntimeException(e.getMessage(), e); + } + } + protected static void tagMessages(HttpMessage... messages) { for (HttpMessage message : messages) { message.setTag(TAG_SESSION_ID, "sid1");
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpLogoutFilterTest.java Wed Nov 08 11:07:10 2017 +0100 +++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpLogoutFilterTest.java Wed Nov 08 11:08:43 2017 +0100 @@ -1,7 +1,6 @@ package com.passus.st.client.http.filter; import com.passus.config.validation.Errors; -import com.passus.filter.config.PredicateNodeTransformer; import com.passus.net.http.HttpRequest; import com.passus.net.http.HttpRequestBuilder; import com.passus.net.http.HttpResponse; @@ -11,9 +10,7 @@ import static com.passus.st.client.http.HttpConsts.TAG_SESSION_ID; import com.passus.st.client.http.HttpFlowContext; import com.passus.st.client.http.HttpScopes; -import com.passus.st.filter.Transformers; import java.util.List; -import java.util.function.Predicate; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.testng.AssertJUnit.assertEquals; @@ -29,8 +26,6 @@ */ public class HttpLogoutFilterTest { - private static final PredicateNodeTransformer TRANSFORMER = Transformers.PREDICATE; - @BeforeClass public static void beforeClass() { AppUtils.registerAll(); @@ -41,18 +36,9 @@ AppUtils.unregisterAll(); } - private HttpMessagePredicate predicate(String config) { - try { - Predicate predicate = TRANSFORMER.transform(config); - return new HttpMessagePredicate(predicate); - } catch (Exception e) { - throw new RuntimeException(e.getMessage(), e); - } - } - @Test public void testFilter_InvalidateSession() { - HttpMessagePredicate predicate = predicate("{\"req.uri\": \"/logout\"}"); + HttpMessagePredicate predicate = HttpFilterTestUtils.createPredicate("{req.uri: \"/logout\"}"); HttpRequest req = HttpRequestBuilder.get("http://test.com/logout").build(); HttpResponse resp = HttpResponseBuilder.ok().build(); HttpScopes scopes = new HttpScopes(); @@ -74,7 +60,7 @@ @Test public void testFilter_NotInvalidateSession() { - HttpMessagePredicate predicate = predicate("{\"req.uri\": \"/logout\"}"); + HttpMessagePredicate predicate = HttpFilterTestUtils.createPredicate("{req.uri: \"/logout\"}"); HttpRequest req = HttpRequestBuilder.get("http://test.com/logout").build(); HttpResponse resp = HttpResponseBuilder.ok().build(); HttpScopes scopes = new HttpScopes();
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMatchFilterTest.java Wed Nov 08 11:07:10 2017 +0100 +++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMatchFilterTest.java Wed Nov 08 11:08:43 2017 +0100 @@ -1,24 +1,21 @@ package com.passus.st.client.http.filter; import com.passus.config.validation.Errors; +import com.passus.net.http.HttpMessage; import com.passus.net.http.HttpRequest; import com.passus.net.http.HttpRequestBuilder; -import java.util.ArrayList; -import java.util.List; -import org.testng.annotations.Test; -import com.passus.filter.config.PredicateNodeTransformer; -import com.passus.net.http.HttpMessage; import com.passus.net.http.HttpResponse; import com.passus.net.http.HttpResponseBuilder; import com.passus.net.http.HttpStatus; import com.passus.st.AppUtils; -import com.passus.st.filter.Transformers; +import java.util.ArrayList; import java.util.Arrays; -import java.util.function.Predicate; +import java.util.List; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertTrue; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; /** * @@ -26,8 +23,6 @@ */ public class HttpMatchFilterTest { - private static final PredicateNodeTransformer TRANSFORMER = Transformers.PREDICATE; - private final List<HttpRequest> requests = Arrays.asList( HttpRequestBuilder.get("http://test.com/test").header("Header", "TheValue").build(), HttpRequestBuilder.get("http://test2.com/test2").build() @@ -39,17 +34,8 @@ HttpResponseBuilder.status(HttpStatus.ACCEPTED).build() ); - private HttpMessagePredicate predicate(String config) { - try { - Predicate predicate = TRANSFORMER.transform(config); - return new HttpMessagePredicate(predicate); - } catch (Exception e) { - throw new RuntimeException(e.getMessage(), e); - } - } - private <T extends HttpMessage> List<T> filter(List<T> messages, String config) { - HttpMessagePredicate predicate = predicate(config); + HttpMessagePredicate predicate = HttpFilterTestUtils.createPredicate(config); return filter(messages, predicate); }
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpZoneFilterTest.java Wed Nov 08 11:07:10 2017 +0100 +++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpZoneFilterTest.java Wed Nov 08 11:08:43 2017 +0100 @@ -1,7 +1,6 @@ package com.passus.st.client.http.filter; import com.passus.config.validation.Errors; -import com.passus.filter.config.PredicateNodeTransformer; import com.passus.net.http.HttpRequest; import com.passus.net.http.HttpRequestBuilder; import com.passus.net.http.HttpResponse; @@ -9,9 +8,7 @@ import com.passus.st.AppUtils; import static com.passus.st.client.http.HttpConsts.TAG_ZONE; import com.passus.st.client.http.filter.HttpZoneFilter.Rule; -import com.passus.st.filter.Transformers; import java.util.List; -import java.util.function.Predicate; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertTrue; import org.testng.annotations.AfterClass; @@ -24,8 +21,6 @@ */ public class HttpZoneFilterTest { - private final PredicateNodeTransformer nodeTransformer = Transformers.PREDICATE; - @BeforeClass public static void beforeClass() { AppUtils.registerAll(); @@ -36,15 +31,6 @@ AppUtils.unregisterAll(); } - private HttpMessagePredicate predicate(String config) { - try { - Predicate predicate = nodeTransformer.transform(config); - return new HttpMessagePredicate(predicate); - } catch (Exception e) { - throw new RuntimeException(e.getMessage(), e); - } - } - @Test public void testFilter() { HttpRequest req = HttpRequestBuilder.get("http://test.com/test").build(); @@ -52,7 +38,7 @@ HttpResponse respIn = HttpResponseBuilder.ok().build(); HttpZoneFilter filter = new HttpZoneFilter(); - filter.addRule(new Rule("testZone", predicate("{req.url: {$contains: \"test\"}}"))); + filter.addRule(new Rule("testZone", HttpFilterTestUtils.createPredicate("{req.url: {$contains: \"test\"}}"))); filter.filterOutbound(req, respOut, null); filter.filterInbound(req, respIn, null);