changeset 948:e98b80c2ae6a

minors
author Devel 2
date Tue, 14 May 2019 08:13:52 +0200
parents 2b30107810b0
children 48f0ecbbf6d8
files stress-tester/src/main/java/com/passus/st/ParametersBag.java stress-tester/src/main/java/com/passus/st/client/http/ReporterFileDestination.java stress-tester/src/main/java/com/passus/st/lookup/LookupsDomainConfigurator.java stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java stress-tester/src/test/java/com/passus/st/ConverterHttpClientTest.java stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTransformerTest.java stress-tester/src/test/java/com/passus/st/client/http/filter/HttpSessionBlockerFilterTest.java
diffstat 7 files changed, 54 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/ParametersBag.java	Mon May 13 12:36:44 2019 +0200
+++ b/stress-tester/src/main/java/com/passus/st/ParametersBag.java	Tue May 14 08:13:52 2019 +0200
@@ -1,16 +1,16 @@
 package com.passus.st;
 
 import com.passus.commons.Assert;
+
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
 
 /**
- *
  * @author Mirosław Hawrot
  */
-public class ParametersBag {
+public final class ParametersBag {
 
     private static final int DEFAULT_CAPACITY = 8;
 
@@ -101,7 +101,7 @@
 
     @Override
     public String toString() {
-        return "ParametersBag{" + "params=" + params + '}';
+        return "ParametersBag{params=" + params + '}';
     }
 
 }
--- a/stress-tester/src/main/java/com/passus/st/client/http/ReporterFileDestination.java	Mon May 13 12:36:44 2019 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/http/ReporterFileDestination.java	Tue May 14 08:13:52 2019 +0200
@@ -45,9 +45,6 @@
 
     private boolean started;
 
-    public ReporterFileDestination() {
-    }
-
     public ReporterFileDestination(String directory) throws IOException {
         this(new File(directory));
     }
--- a/stress-tester/src/main/java/com/passus/st/lookup/LookupsDomainConfigurator.java	Mon May 13 12:36:44 2019 +0200
+++ b/stress-tester/src/main/java/com/passus/st/lookup/LookupsDomainConfigurator.java	Tue May 14 08:13:52 2019 +0200
@@ -67,6 +67,7 @@
     }
 
     @Override
+    @SuppressWarnings("unchecked")
     public void afterConfigurationSet(Errors errors, ConfigurationContext context) {
         List<Lookup> lookups = (List<Lookup>) context.get(ConfigurationContextConsts.LOOKUPS, Collections.EMPTY_LIST);
         lookups.forEach(Lookup::start);
--- a/stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java	Mon May 13 12:36:44 2019 +0200
+++ b/stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java	Tue May 14 08:13:52 2019 +0200
@@ -260,7 +260,7 @@
 
         try {
             pcapThread.join(500);
-        } catch (Exception e) {
+        } catch (Exception ignored) {
         }
 
         sessionAnalyzerThread.deactivate();
@@ -268,7 +268,7 @@
 
         try {
             sessionAnalyzerThread.join(500);
-        } catch (Exception e) {
+        } catch (Exception ignored) {
         }
 
         pcapThread = null;
--- a/stress-tester/src/test/java/com/passus/st/ConverterHttpClientTest.java	Mon May 13 12:36:44 2019 +0200
+++ b/stress-tester/src/test/java/com/passus/st/ConverterHttpClientTest.java	Tue May 14 08:13:52 2019 +0200
@@ -44,7 +44,7 @@
     static NullEventDestination DST = new NullEventDestination();
 
     static {
-        Log4jConfigurationFactory.enableFactory(Level.DEBUG);
+        //Log4jConfigurationFactory.enableFactory(Level.DEBUG);
     }
 
     @BeforeClass
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTransformerTest.java	Mon May 13 12:36:44 2019 +0200
+++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTransformerTest.java	Tue May 14 08:13:52 2019 +0200
@@ -27,7 +27,6 @@
 import static org.testng.AssertJUnit.*;
 
 /**
- *
  * @author mikolaj.podbielski
  */
 public class HttpMessageModificationFilterTransformerTest {
@@ -39,6 +38,15 @@
         return mapNode.getFirstChild();
     }
 
+    private List<Operation> processOperations(String config) throws Exception {
+        CTupleNode node = read(config);
+        Errors errors = new Errors();
+        ConfigurationContextImpl emptyContext = new ConfigurationContextImpl();
+        CValueNode value = transformer.transform(node.getNode(), errors, emptyContext);
+        assertEquals(0, errors.getErrorCount());
+        return (List) value.getValue();
+    }
+
     @Test
     public void testTransform() throws Exception {
         String config = "operations:\n"
@@ -70,32 +78,46 @@
                 + "    post:param2: new\n"
                 + "  setContent:\n"
                 + "    regexp:aaa(.+)bbb: new\n";
-        CTupleNode node = read(config);
 
-        Errors errors = new Errors();
-        ConfigurationContextImpl emptyContext = new ConfigurationContextImpl();
-        CValueNode value = transformer.transform(node.getNode(), errors, emptyContext);
-        HttpFilterTestUtils.printErrors(errors);
-        List<Operation> operations = (List) value.getValue();
-
-        assertEquals(0, errors.getErrorCount());
+        List<Operation> operations = processOperations(config);
         assertEquals(16, 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);
-        assertTrue(operations.get(12) instanceof ContentOperation);
-        assertTrue(operations.get(13) instanceof ContentOperation);
-        assertTrue(operations.get(14) instanceof ContentOperation);
-        assertTrue(operations.get(15) instanceof ContentOperation);
+
+        int i = 0;
+        assertTrue(operations.get(i++) instanceof RemoveHeaderOperation);
+        assertTrue(operations.get(i++) instanceof SetHeaderOperation);
+        assertTrue(operations.get(i++) instanceof AddHeaderOperation);
+        assertTrue(operations.get(i++) instanceof RemoveCookieOperation);
+        assertTrue(operations.get(i++) instanceof SetCookieOperation);
+        assertTrue(operations.get(i++) instanceof AddCookieOperation);
+        assertTrue(operations.get(i++) instanceof RemoveQueryParameterOperation);
+        assertTrue(operations.get(i++) instanceof SetQueryParameterOperation);
+        assertTrue(operations.get(i++) instanceof AddQueryParameterOperation);
+        assertTrue(operations.get(i++) instanceof PostDataRemoveParamOperation);
+        assertTrue(operations.get(i++) instanceof PostDataSetParamOperation);
+        assertTrue(operations.get(i++) instanceof PostDataAddParamOperation);
+        assertTrue(operations.get(i++) instanceof ContentOperation);
+        assertTrue(operations.get(i++) instanceof ContentOperation);
+        assertTrue(operations.get(i++) instanceof ContentOperation);
+        assertTrue(operations.get(i++) instanceof ContentOperation);
+    }
+
+    @Test
+    public void testTransform_SetQueryParam() throws Exception {
+        String config = "operations:\n"
+                + "  setQueryParam:\n"
+                + "    data: '050220192020'\n"
+                + "  setQueryParam:\n"
+                + "    data: 50220192020\n";
+        List<Operation> operations = processOperations(config);
+        operations.forEach((op) -> assertTrue(operations.get(0) instanceof SetQueryParameterOperation));
+
+        SetQueryParameterOperation operation = (SetQueryParameterOperation) operations.get(0);
+        UnmutableValueExtractor extractor = (UnmutableValueExtractor) operation.getValueExtractor();
+        assertEquals("050220192020", extractor.getValue());
+
+        operation = (SetQueryParameterOperation) operations.get(1);
+        extractor = (UnmutableValueExtractor) operation.getValueExtractor();
+        assertEquals("50220192020", extractor.getValue());
     }
 
     @Test
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpSessionBlockerFilterTest.java	Mon May 13 12:36:44 2019 +0200
+++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpSessionBlockerFilterTest.java	Tue May 14 08:13:52 2019 +0200
@@ -11,12 +11,6 @@
 
 public class HttpSessionBlockerFilterTest {
 
-    private HttpRequest createRequest() {
-        HttpRequest req = get("http://test/test").build();
-        req.setTag(TAG_SESSION_ID, "sid1");
-        return req;
-    }
-
     @Test
     public void testFilter() {
         HttpSessionBlockerFilter filter = new HttpSessionBlockerFilter(2);