Mercurial > stress-tester
changeset 507:f91dee0f0bbc
unit tests
author | Devel 1 |
---|---|
date | Thu, 17 Aug 2017 14:56:18 +0200 |
parents | 6f28783661b5 |
children | 91b6bab38277 |
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, 20 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/test/java/com/passus/st/client/http/extractor/RegexValueExtractorTest.java Thu Aug 17 14:33:32 2017 +0200 +++ b/stress-tester/src/test/java/com/passus/st/client/http/extractor/RegexValueExtractorTest.java Thu Aug 17 14:56:18 2017 +0200 @@ -35,6 +35,15 @@ assertEquals(null, extract("no_such_pattern(.*?)", content)); } + @Test + public void testInvalidRegex() { + try { + RegexValueExtractor e = new RegexValueExtractor("((("); + fail("should throw exception"); + } catch (Exception ignore) { + } + } + 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 14:33:32 2017 +0200 +++ b/stress-tester/src/test/java/com/passus/st/client/http/extractor/XmlValueExtractorTest.java Thu Aug 17 14:56:18 2017 +0200 @@ -1,7 +1,7 @@ package com.passus.st.client.http.extractor; import com.passus.st.Log4jConfigurationFactory; -import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.*; import org.testng.annotations.Test; /** @@ -26,7 +26,7 @@ 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(null, extract("/root/node1", "NOT AN XML")); @@ -34,8 +34,16 @@ // TODO: sprawdzić zachowanie i wydajność Apache JXPath } + @Test + public void testInvalidXPath() { + try { + XmlValueExtractor e = new XmlValueExtractor("not a path"); + fail("should throw exception"); + } catch (Exception ignore) { + } + } + static String extract(String path, String content) throws Exception { - System.out.println(path); return new XmlValueExtractor(path).extract(content); } }