changeset 626:53957b94f932

refactoring
author Devel 1
date Tue, 17 Oct 2017 12:45:50 +0200
parents 96cfb7cf66f3
children 6c8ad9bd2767
files stress-tester-benchmark/src/main/java/com/passus/st/client/http/filter/HttpMessagePredicateBenchmark.java stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFilterMessagePredicateNodeDefinition.java stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTransformer.java stress-tester/src/main/java/com/passus/st/client/http/filter/HttpScopeModificationFilterTransformer.java stress-tester/src/main/java/com/passus/st/client/http/filter/HttpSequenceFilter.java stress-tester/src/main/java/com/passus/st/client/http/filter/HttpZoneFilter.java stress-tester/src/main/java/com/passus/st/filter/Transformers.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/HttpSequenceFilterTest.java stress-tester/src/test/java/com/passus/st/client/http/filter/HttpZoneFilterTest.java
diffstat 11 files changed, 42 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester-benchmark/src/main/java/com/passus/st/client/http/filter/HttpMessagePredicateBenchmark.java	Mon Oct 16 16:41:25 2017 +0200
+++ b/stress-tester-benchmark/src/main/java/com/passus/st/client/http/filter/HttpMessagePredicateBenchmark.java	Tue Oct 17 12:45:50 2017 +0200
@@ -1,6 +1,7 @@
 package com.passus.st.client.http.filter;
 
 import com.passus.filter.config.PredicateNodeTransformer;
+import com.passus.st.filter.Transformers;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Predicate;
 import org.openjdk.jmh.annotations.BenchmarkMode;
@@ -27,7 +28,7 @@
 @Warmup(iterations = 4)
 public class HttpMessagePredicateBenchmark extends AbstractHttpMessagePredicateBenchmark {
 
-    private static final PredicateNodeTransformer TRANSFORMER = new PredicateNodeTransformer();
+    private static final PredicateNodeTransformer TRANSFORMER = Transformers.PREDICATE;
 
     @Override
     public Predicate predicate(String config) {
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFilterMessagePredicateNodeDefinition.java	Mon Oct 16 16:41:25 2017 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFilterMessagePredicateNodeDefinition.java	Tue Oct 17 12:45:50 2017 +0200
@@ -11,6 +11,7 @@
 import com.passus.config.validation.Errors;
 import static com.passus.config.validation.ValidationDefaultMessages.GENERAL_CONVERSION_ERROR;
 import com.passus.filter.config.PredicateNodeTransformer;
+import com.passus.st.filter.Transformers;
 import java.util.Set;
 import java.util.function.Predicate;
 
@@ -20,7 +21,7 @@
  */
 public class HttpFilterMessagePredicateNodeDefinition extends NodeDefinition<HttpFilterMessagePredicateNodeDefinition> {
 
-    private static final PredicateNodeTransformer TRANSFORMER = new PredicateNodeTransformer();
+    private static final PredicateNodeTransformer TRANSFORMER = Transformers.PREDICATE;
 
     private final static Set<Class<? extends CNode>> SUPPORTED = ArrayUtils.asUnmodifiableSet(CListNode.class, CMapNode.class);
 
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTransformer.java	Mon Oct 16 16:41:25 2017 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTransformer.java	Tue Oct 17 12:45:50 2017 +0200
@@ -11,6 +11,7 @@
 import com.passus.filter.ValueExtractor;
 import com.passus.filter.config.ExpressionNodeTransformer;
 import com.passus.st.client.http.filter.HttpMessageModificationFilter.*;
+import com.passus.st.filter.Transformers;
 import static com.passus.st.validation.NodeValidationUtils.validateType;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -22,7 +23,7 @@
  */
 public class HttpMessageModificationFilterTransformer implements NodeTransformer {
 
-    private final ExpressionNodeTransformer exprTransformer = new ExpressionNodeTransformer();
+    private static final ExpressionNodeTransformer TRANSFORMER = Transformers.EXPRESSION;
 
     private Operation createNameOperation(CTupleNode tuple, Errors errors, Class<? extends Operation> clazz) {
         if (validateType(tuple.getNode(), NodeType.VALUE, errors)) {
@@ -44,12 +45,12 @@
             CTupleNode valTupleNode = ((CMapNode) tuple.getNode()).getFirstChild();
             if (valTupleNode != null) {
                 ValueExtractor valueTransformer = null;
-                
+
                 CNode valNode = valTupleNode.getNode();
                 if (valNode.getType() == NodeType.VALUE
                         || valNode.getType() == NodeType.MAP) {
                     try {
-                        valueTransformer = exprTransformer.transform(valNode);
+                        valueTransformer = TRANSFORMER.transform(valNode);
                     } catch (Exception e) {
                         errors.reject("Invalid expression.", valNode);
                         return null;
@@ -58,7 +59,7 @@
                     errors.reject("Invalid node.", valNode);
                     return null;
                 }
-              
+
                 if (valueTransformer != null) {
                     try {
                         return clazz
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpScopeModificationFilterTransformer.java	Mon Oct 16 16:41:25 2017 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpScopeModificationFilterTransformer.java	Tue Oct 17 12:45:50 2017 +0200
@@ -17,6 +17,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 com.passus.st.filter.Transformers;
 import static com.passus.st.validation.NodeValidationUtils.validateType;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -28,7 +29,7 @@
  */
 public class HttpScopeModificationFilterTransformer implements NodeTransformer<CValueNode> {
 
-    private final ExpressionNodeTransformer expressionTransformer = ExpressionNodeTransformer.DEFAULT;
+    private static final ExpressionNodeTransformer TRANSFORMER = Transformers.EXPRESSION;
 
     private SetSessionParamOperation createSetSessionParamOperation(CTupleNode tuple, Errors errors, boolean checkValueExists) {
         if (validateType(tuple.getNode(), NodeType.MAP, errors)) {
@@ -47,7 +48,7 @@
                         default:
                             try {
                                 paramName = mapTupleNode.getName();
-                                valueExtractor = expressionTransformer.transform(mapTupleNode.getNode());
+                                valueExtractor = TRANSFORMER.transform(mapTupleNode.getNode());
                             } catch (Exception e) {
                                 errors.reject(mapTupleNode.getNode(), "Invalid expression.");
                             }
@@ -77,7 +78,7 @@
                         default:
                             try {
                                 paramName = mapTupleNode.getName();
-                                valueExtractor = expressionTransformer.transform(mapTupleNode.getNode());
+                                valueExtractor = TRANSFORMER.transform(mapTupleNode.getNode());
                             } catch (Exception e) {
                                 errors.reject(mapTupleNode.getNode(), "Invalid expression.");
                             }
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpSequenceFilter.java	Mon Oct 16 16:41:25 2017 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpSequenceFilter.java	Tue Oct 17 12:45:50 2017 +0200
@@ -27,6 +27,7 @@
 import com.passus.st.client.http.HttpFlowContext;
 import com.passus.st.client.http.ReporterDestination;
 import com.passus.st.client.http.ReporterRemoteDestination;
+import com.passus.st.filter.Transformers;
 import com.passus.st.plugin.PluginConstants;
 import java.io.Serializable;
 import java.text.ParseException;
@@ -409,7 +410,7 @@
 
     private static class SequencesNodeTransformer implements NodeTransformer<CNode> {
 
-        private static final PredicateNodeTransformer TRANSFORMER = new PredicateNodeTransformer();
+        private static final PredicateNodeTransformer TRANSFORMER = Transformers.PREDICATE;
 
         @Override
         public CNode transform(CNode node, Errors errors) {
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpZoneFilter.java	Mon Oct 16 16:41:25 2017 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpZoneFilter.java	Tue Oct 17 12:45:50 2017 +0200
@@ -22,6 +22,7 @@
 import com.passus.net.http.HttpResponse;
 import static com.passus.st.client.http.HttpConsts.TAG_ZONE;
 import com.passus.st.client.http.HttpFlowContext;
+import com.passus.st.filter.Transformers;
 import com.passus.st.plugin.PluginConstants;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -137,7 +138,7 @@
 
         private final static Set<Class<? extends CNode>> SUPPORTED = ArrayUtils.asUnmodifiableSet(CMapNode.class);
 
-        private static final PredicateNodeTransformer TRANSFORMER = new PredicateNodeTransformer();
+        private static final PredicateNodeTransformer TRANSFORMER = Transformers.PREDICATE;
 
         @Override
         public Set<Class<? extends CNode>> getSupportedNode() {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stress-tester/src/main/java/com/passus/st/filter/Transformers.java	Tue Oct 17 12:45:50 2017 +0200
@@ -0,0 +1,15 @@
+package com.passus.st.filter;
+
+import com.passus.filter.config.ExpressionNodeTransformer;
+import com.passus.filter.config.PredicateNodeTransformer;
+
+/**
+ *
+ * @author mikolaj.podbielski
+ */
+public class Transformers {
+    
+    public static final PredicateNodeTransformer PREDICATE = new PredicateNodeTransformer();
+    
+    public static final ExpressionNodeTransformer EXPRESSION = new ExpressionNodeTransformer();
+}
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpLogoutFilterTest.java	Mon Oct 16 16:41:25 2017 +0200
+++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpLogoutFilterTest.java	Tue Oct 17 12:45:50 2017 +0200
@@ -11,6 +11,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;
@@ -28,7 +29,7 @@
  */
 public class HttpLogoutFilterTest {
 
-    private final PredicateNodeTransformer nodeTransformer = new PredicateNodeTransformer();
+    private static final PredicateNodeTransformer TRANSFORMER = Transformers.PREDICATE;
 
     @BeforeClass
     public static void beforeClass() {
@@ -42,7 +43,7 @@
 
     private HttpMessagePredicate predicate(String config) {
         try {
-            Predicate predicate = nodeTransformer.transform(config);
+            Predicate predicate = TRANSFORMER.transform(config);
             return new HttpMessagePredicate(predicate);
         } catch (Exception e) {
             throw new RuntimeException(e.getMessage(), e);
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMatchFilterTest.java	Mon Oct 16 16:41:25 2017 +0200
+++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMatchFilterTest.java	Tue Oct 17 12:45:50 2017 +0200
@@ -12,6 +12,7 @@
 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.Arrays;
 import java.util.function.Predicate;
 import static org.testng.AssertJUnit.assertEquals;
@@ -25,7 +26,7 @@
  */
 public class HttpMatchFilterTest {
 
-    private final PredicateNodeTransformer nodeTransformer = new PredicateNodeTransformer();
+    private static final PredicateNodeTransformer TRANSFORMER = Transformers.PREDICATE;
 
     private final List<HttpRequest> requests = Arrays.asList(
             HttpRequestBuilder.get("http://test.com/test").header("Header", "TheValue").build(),
@@ -40,7 +41,7 @@
 
     private HttpMessagePredicate predicate(String config) {
         try {
-            Predicate predicate = nodeTransformer.transform(config);
+            Predicate predicate = TRANSFORMER.transform(config);
             return new HttpMessagePredicate(predicate);
         } catch (Exception e) {
             throw new RuntimeException(e.getMessage(), e);
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpSequenceFilterTest.java	Mon Oct 16 16:41:25 2017 +0200
+++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpSequenceFilterTest.java	Tue Oct 17 12:45:50 2017 +0200
@@ -17,6 +17,7 @@
 import com.passus.net.http.HttpResponseBuilder;
 import com.passus.st.AppUtils;
 import com.passus.st.client.http.filter.HttpSequenceFilter.SequenceItem;
+import com.passus.st.filter.Transformers;
 import java.io.File;
 import java.io.Serializable;
 import java.nio.file.Files;
@@ -38,7 +39,7 @@
  */
 public class HttpSequenceFilterTest {
 
-    private static final PredicateNodeTransformer TRANSFORMER = new PredicateNodeTransformer();
+    private static final PredicateNodeTransformer TRANSFORMER = Transformers.PREDICATE;
 
     @BeforeClass
     public static void beforeClass() {
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpZoneFilterTest.java	Mon Oct 16 16:41:25 2017 +0200
+++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpZoneFilterTest.java	Tue Oct 17 12:45:50 2017 +0200
@@ -8,17 +8,14 @@
 import com.passus.net.http.HttpResponseBuilder;
 import com.passus.st.AppUtils;
 import static com.passus.st.client.http.HttpConsts.TAG_ZONE;
-import com.passus.st.client.http.HttpFlowContext;
 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.Assert.*;
 import static org.testng.AssertJUnit.assertEquals;
 import static org.testng.AssertJUnit.assertTrue;
 import org.testng.annotations.AfterClass;
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeClass;
-import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 /**
@@ -27,7 +24,7 @@
  */
 public class HttpZoneFilterTest {
 
-    private final PredicateNodeTransformer nodeTransformer = new PredicateNodeTransformer();
+    private final PredicateNodeTransformer nodeTransformer = Transformers.PREDICATE;
 
     @BeforeClass
     public static void beforeClass() {