changeset 488:878dc1253eef

refactoring
author Devel 1
date Thu, 10 Aug 2017 10:16:49 +0200
parents c58400b7591e
children 0f7e221f9099
files stress-tester/src/main/java/com/passus/st/client/http/filter/HttpScopeModificationFilter.java
diffstat 1 files changed, 43 insertions(+), 67 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpScopeModificationFilter.java	Wed Aug 09 16:27:29 2017 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpScopeModificationFilter.java	Thu Aug 10 10:16:49 2017 +0200
@@ -71,65 +71,6 @@
 
     }
 
-    public static class SetSessionParamOperation extends Operation {
-
-        protected final boolean autocreate;
-
-        protected final String paramName;
-
-        protected final ValueExtractor valueExtractor;
-
-        protected final boolean checkValueExists;
-
-        public SetSessionParamOperation(String paramName, ValueExtractor valueExtractor) {
-            this(paramName, valueExtractor, true);
-        }
-
-        public SetSessionParamOperation(String paramName, ValueExtractor valueExtractor, boolean checkValueExists) {
-            this(paramName, valueExtractor, checkValueExists, true);
-        }
-
-        public SetSessionParamOperation(String paramName, ValueExtractor valueExtractor, boolean checkValueExists, boolean autocreate) {
-            Assert.notNull(paramName, "paramName");
-            Assert.notNull(valueExtractor, "valueExtractor");
-
-            this.paramName = paramName;
-            this.valueExtractor = valueExtractor;
-            this.checkValueExists = checkValueExists;
-            this.autocreate = autocreate;
-        }
-
-        public boolean isAutocreate() {
-            return autocreate;
-        }
-
-        public String getParamName() {
-            return paramName;
-        }
-
-        public ValueExtractor getValueExtractor() {
-            return valueExtractor;
-        }
-
-        public boolean isCheckValueExists() {
-            return checkValueExists;
-        }
-
-        @Override
-        public void process(HttpRequest req, HttpResponse resp, HttpFlowContext context) {
-            ParametersBag params = context.scopes().getSession(req, autocreate);
-            if (params != null) {
-                if (checkValueExists && params.contains(paramName)) {
-                    return;
-                }
-
-                Object value = HttpFiltersUtils.extractValue(valueExtractor, req, resp, context);
-                params.set(paramName, value);
-            }
-        }
-
-    }
-
     public static class RemoveGlobalParamOperation extends Operation {
 
         private final String paramName;
@@ -151,19 +92,13 @@
 
     }
 
-    public static class SetGlobalParamOperation extends Operation {
+    public static abstract class SetScopeParamOperation extends Operation {
 
         protected final String paramName;
-
         protected final ValueExtractor valueExtractor;
-
         protected final boolean checkValueExists;
 
-        public SetGlobalParamOperation(String paramName, ValueExtractor valueExtractor) {
-            this(paramName, valueExtractor, true);
-        }
-
-        public SetGlobalParamOperation(String paramName, ValueExtractor valueExtractor, boolean checkValueExists) {
+        public SetScopeParamOperation(String paramName, ValueExtractor valueExtractor, boolean checkValueExists) {
             Assert.notNull(paramName, "paramName");
             Assert.notNull(valueExtractor, "valueExtractor");
 
@@ -183,6 +118,47 @@
         public boolean isCheckValueExists() {
             return checkValueExists;
         }
+        
+
+    }
+
+    public static class SetSessionParamOperation extends SetScopeParamOperation {
+
+        protected final boolean autocreate;
+
+        public SetSessionParamOperation(String paramName, ValueExtractor valueExtractor, boolean checkValueExists) {
+            this(paramName, valueExtractor, checkValueExists, true);
+        }
+
+        public SetSessionParamOperation(String paramName, ValueExtractor valueExtractor, boolean checkValueExists, boolean autocreate) {
+            super(paramName, valueExtractor, checkValueExists);
+            this.autocreate = autocreate;
+        }
+
+        public boolean isAutocreate() {
+            return autocreate;
+        }
+
+        @Override
+        public void process(HttpRequest req, HttpResponse resp, HttpFlowContext context) {
+            ParametersBag params = context.scopes().getSession(req, autocreate);
+            if (params != null) {
+                if (checkValueExists && params.contains(paramName)) {
+                    return;
+                }
+
+                Object value = HttpFiltersUtils.extractValue(valueExtractor, req, resp, context);
+                params.set(paramName, value);
+            }
+        }
+
+    }
+
+    public static class SetGlobalParamOperation extends SetScopeParamOperation {
+
+        public SetGlobalParamOperation(String paramName, ValueExtractor valueExtractor, boolean checkValueExists) {
+            super(paramName, valueExtractor, checkValueExists);
+        }
 
         @Override
         public void process(HttpRequest req, HttpResponse resp, HttpFlowContext context) {