changeset 853:dd889cf40118

reverseTransform in progress
author Devel 1
date Tue, 23 Jan 2018 16:02:42 +0100
parents bd7ddb7ff81d
children b680a2485161
files stress-tester/src/main/java/com/passus/st/client/credentials/CsvUsernamePasswordCredentialsProvider.java stress-tester/src/main/java/com/passus/st/client/http/filter/HttpCsrfFilterStoreTransformer.java stress-tester/src/main/java/com/passus/st/emitter/PortIgnoringSocketAddressProvider.java stress-tester/src/main/java/com/passus/st/emitter/PortSpecificSocketAddressProvider.java stress-tester/src/main/java/com/passus/st/emitter/SimpleSocketMatcher.java stress-tester/src/test/java/com/passus/st/client/credentials/CsvUsernamePasswordCredentialsProviderTest.java stress-tester/src/test/java/com/passus/st/client/credentials/MultiCredentialsProviderTransformerTest.java stress-tester/src/test/java/com/passus/st/config/StringToExecutableStatementValueTransformerTest.java
diffstat 8 files changed, 51 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/credentials/CsvUsernamePasswordCredentialsProvider.java	Tue Jan 23 15:17:53 2018 +0100
+++ b/stress-tester/src/main/java/com/passus/st/client/credentials/CsvUsernamePasswordCredentialsProvider.java	Tue Jan 23 16:02:42 2018 +0100
@@ -5,6 +5,7 @@
 import com.passus.commons.ConversionException;
 import com.passus.commons.annotations.Plugin;
 import com.passus.config.Configuration;
+import com.passus.config.StringToEnumValueTransformer;
 import com.passus.config.ValueTransformer;
 import com.passus.config.annotations.NodeDefinitionCreate;
 import static com.passus.config.schema.ConfigurationSchemaBuilder.mapDef;
@@ -129,7 +130,7 @@
         } catch (IOException ex) {
             credentialsList = Collections.EMPTY_LIST;
         } catch (NullPointerException npe) {
-            // TODO: workaround, pomimo negatywnej walidacji wywołuje się configure (z pustym fileName)
+            // TODO: workaround, pomimo negatywnej walidacji wywoluje sie configure (z pustym fileName)
             credentialsList = Collections.EMPTY_LIST;
         }
     }
@@ -165,7 +166,7 @@
 
     public static class NodeDefCreator implements NodeDefinitionCreator {
 
-        private static final ReadModeTransformer TRANSFORMER = new ReadModeTransformer();
+        private static final StringToEnumValueTransformer TRANSFORMER = new StringToEnumValueTransformer(ReadMode.class, false);
 
         @Override
         public NodeDefinition create() {
@@ -177,22 +178,4 @@
         }
     }
 
-    private static class ReadModeTransformer implements ValueTransformer {
-
-        @Override
-        public Object transform(Object obj) throws ConversionException {
-            String readMode = (String) obj;
-            readMode = readMode.toUpperCase();
-            try {
-                return ReadMode.valueOf(readMode);
-            } catch (IllegalArgumentException ex) {
-                throw new ConversionException("Illegal value", ex);
-            }
-        }
-
-        @Override
-        public Object reverseTransform(Object obj) throws ConversionException {
-            return obj.toString();
-        }
-    }
 }
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpCsrfFilterStoreTransformer.java	Tue Jan 23 15:17:53 2018 +0100
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpCsrfFilterStoreTransformer.java	Tue Jan 23 16:02:42 2018 +0100
@@ -27,7 +27,13 @@
 
     @Override
     public Object reverseTransform(Object obj) throws ConversionException {
-        throw new UnsupportedOperationException("Not supported yet.");
+        if (obj instanceof HttpCsrfFilter.QueueStore) {
+            return "queue";
+        } else if (obj instanceof HttpCsrfFilter.SingleTokenStore) {
+            return "single";
+        } else {
+            throw new ConversionException("Unknown token store type: " + obj.getClass().getSimpleName());
+        }
     }
 
 }
--- a/stress-tester/src/main/java/com/passus/st/emitter/PortIgnoringSocketAddressProvider.java	Tue Jan 23 15:17:53 2018 +0100
+++ b/stress-tester/src/main/java/com/passus/st/emitter/PortIgnoringSocketAddressProvider.java	Tue Jan 23 16:02:42 2018 +0100
@@ -13,7 +13,7 @@
 
     private int index;
 
-    public PortIgnoringSocketAddressProvider(IpAddress... addresses) {
+    PortIgnoringSocketAddressProvider(IpAddress... addresses) {
         this.addresses = addresses;
     }
 
--- a/stress-tester/src/main/java/com/passus/st/emitter/PortSpecificSocketAddressProvider.java	Tue Jan 23 15:17:53 2018 +0100
+++ b/stress-tester/src/main/java/com/passus/st/emitter/PortSpecificSocketAddressProvider.java	Tue Jan 23 16:02:42 2018 +0100
@@ -16,7 +16,7 @@
 
     private int index;
 
-    public PortSpecificSocketAddressProvider(IpAddress[] addresses, int[] ports) {
+    PortSpecificSocketAddressProvider(IpAddress[] addresses, int[] ports) {
         Assert.notEmpty(addresses, "addresses");
         Assert.notEmpty(ports, "ports");
         this.addresses = addresses;
--- a/stress-tester/src/main/java/com/passus/st/emitter/SimpleSocketMatcher.java	Tue Jan 23 15:17:53 2018 +0100
+++ b/stress-tester/src/main/java/com/passus/st/emitter/SimpleSocketMatcher.java	Tue Jan 23 16:02:42 2018 +0100
@@ -26,4 +26,11 @@
         return this.ip == null || this.ip.equals(ip);
     }
 
+    @Override
+    public String toString() {
+        String ipStr = ip == null ? "*" : ip.toString();
+        String portStr = port == -1 ? "*" : String.valueOf(port);
+        return ipStr + ":" + portStr;
+    }
+
 }
--- a/stress-tester/src/test/java/com/passus/st/client/credentials/CsvUsernamePasswordCredentialsProviderTest.java	Tue Jan 23 15:17:53 2018 +0100
+++ b/stress-tester/src/test/java/com/passus/st/client/credentials/CsvUsernamePasswordCredentialsProviderTest.java	Tue Jan 23 16:02:42 2018 +0100
@@ -72,8 +72,5 @@
         return new Credentials(u, p);
     }
 
-    @Test
-    public void testConfigure() {
-        assertTrue(true);
-    }
+// konfiguracja jest testowana w MultiCredentialsProviderTransformerTest
 }
--- a/stress-tester/src/test/java/com/passus/st/client/credentials/MultiCredentialsProviderTransformerTest.java	Tue Jan 23 15:17:53 2018 +0100
+++ b/stress-tester/src/test/java/com/passus/st/client/credentials/MultiCredentialsProviderTransformerTest.java	Tue Jan 23 16:02:42 2018 +0100
@@ -24,6 +24,8 @@
  */
 public class MultiCredentialsProviderTransformerTest {
 
+    private static final MultiCredentialsProviderTransformer TRANSFORMER = new MultiCredentialsProviderTransformer();
+
     @Test
     public void testTransformUsernamePassword() throws Exception {
         String content
@@ -58,7 +60,8 @@
                 = "provider:\n"
                 + "    CsvUsernamePassword:\n"
                 + "        fileName: '%s'\n"
-                + "        separator: ','\n";
+                + "        separator: ','\n"
+                + "        readMode: random\n";
         content = String.format(content, file.getAbsolutePath());
 
         List<CredentialsProvider> providers = readAndTransform(content).getProviders();
@@ -67,7 +70,7 @@
 
         assertTrue(providers.get(0) instanceof CsvUsernamePasswordCredentialsProvider);
         CsvUsernamePasswordCredentialsProvider cupcp = (CsvUsernamePasswordCredentialsProvider) providers.get(0);
-        assertEquals(ReadMode.STEP_BY_STEP, cupcp.getReadMode());
+        assertEquals(ReadMode.RANDOM, cupcp.getReadMode());
         assertEquals(file.getAbsolutePath(), cupcp.getFileName());
         assertEquals(',', cupcp.getSeparator());
         List<Credentials> actualList = cupcp.getCredentialsList();
@@ -92,8 +95,8 @@
         }
     }
 
-    private static MultiCredentialsProvider readAndTransform(String content) throws IOException, NodeException, ConversionException {
-        return readAndTransform(new MultiCredentialsProviderTransformer(), content);
+    static MultiCredentialsProvider readAndTransform(String content) throws IOException, NodeException, ConversionException {
+        return readAndTransform(TRANSFORMER, content);
     }
 
     static <T extends NodeTransformer<CValueNode>, P extends CredentialsProvider> P
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stress-tester/src/test/java/com/passus/st/config/StringToExecutableStatementValueTransformerTest.java	Tue Jan 23 16:02:42 2018 +0100
@@ -0,0 +1,24 @@
+package com.passus.st.config;
+
+import org.mvel2.compiler.ExecutableStatement;
+import static org.testng.AssertJUnit.*;
+import org.testng.annotations.Test;
+
+/**
+ *
+ * @author mikolaj.podbielski
+ */
+public class StringToExecutableStatementValueTransformerTest {
+
+    private final StringToExecutableStatementValueTransformer trans = new StringToExecutableStatementValueTransformer();
+
+    private final String expression = "$req.setMethod(com.passus.net.http.HttpMethod.HEAD);"
+            + "$req.getUri().toString().equals(\"/index.html\") ? 1 : 0";
+
+    @Test
+    public void testTransform() throws Exception {
+        Object transformed = trans.transform(expression);
+        assertTrue(transformed instanceof ExecutableStatement);
+    }
+
+}