changeset 504:793e0f11c260

unit tests
author Devel 1
date Thu, 17 Aug 2017 11:20:16 +0200
parents 2790f0eb7985
children c10b0d35b676
files stress-tester/src/test/java/com/passus/st/client/http/extractor/RegexValueExtractorTest.java stress-tester/src/test/java/com/passus/st/client/http/extractor/XmlValueExtractorTest.java
diffstat 2 files changed, 21 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/test/java/com/passus/st/client/http/extractor/RegexValueExtractorTest.java	Thu Aug 17 11:00:02 2017 +0200
+++ b/stress-tester/src/test/java/com/passus/st/client/http/extractor/RegexValueExtractorTest.java	Thu Aug 17 11:20:16 2017 +0200
@@ -30,9 +30,12 @@
                 + "</body>\n"
                 + "</html>";
 
-        RegexValueExtractor extractor = new RegexValueExtractor("\"SECURE_TOKEN\"[ ]*:[ ]*\"(.*?)\"");
-        String value = extractor.extract(content);
-        assertEquals("a5UrXJGaMULhiejTuGeAIwlDN9gEvTUf", value);
+        assertEquals("a5UrXJGaMULhiejTuGeAIwlDN9gEvTUf", extract("\"SECURE_TOKEN\"[ ]*:[ ]*\"(.*?)\"", content));
+        assertEquals(null, extract("\"SECURE_TOKEN\"[ ]*:[ ]*\"\"", content));
+        assertEquals(null, extract("no_such_pattern(.*?)", content));
     }
 
+    static String extract(String regex, String content) {
+        return new RegexValueExtractor(regex).extract(content);
+    }
 }
--- a/stress-tester/src/test/java/com/passus/st/client/http/extractor/XmlValueExtractorTest.java	Thu Aug 17 11:00:02 2017 +0200
+++ b/stress-tester/src/test/java/com/passus/st/client/http/extractor/XmlValueExtractorTest.java	Thu Aug 17 11:20:16 2017 +0200
@@ -19,13 +19,23 @@
                 + " <node2>value2</node2>"
                 + " <node2>value3</node2>"
                 + " <node3><node4>value4</node4></node3>"
+                + " <emptyNode></emptyNode>"
                 + "</root>";
 
-        XmlValueExtractor extractor = new XmlValueExtractor("/root/node1");
-        assertEquals("value1", extractor.extract(xml));
-
-        extractor = new XmlValueExtractor("/root/node2[2]");
-        assertEquals("value3", extractor.extract(xml));
+        assertEquals("value1", extract("/root/node1", xml));
+        assertEquals("value2", extract("/root/node2", xml));
+        assertEquals("value3", extract("/root/node2[2]", xml));
+        assertEquals("", extract("/root/emptyNode", xml));
+        
+        assertEquals("", extract("/root/noSuchNode", xml));
+        assertEquals("", extract("/root/node1/@noSuchAttribute", xml));
+        assertEquals("", extract("/root/node1", "NOT AN XML"));
+        // TODO: zwraca pusty string, gdy nie ma podanej ścieżki, przydałby się null
+        // TODO: sprawdzić zachowanie i wydajność Apache JXPath
     }
 
+    static String extract(String path, String content) throws Exception {
+        System.out.println(path);
+        return new XmlValueExtractor(path).extract(content);
+    }
 }