diff --git a/src/components/org/apache/jmeter/assertions/ResponseAssertion.java b/src/components/org/apache/jmeter/assertions/ResponseAssertion.java index cd1e35efac..80a3ffc541 100644 --- a/src/components/org/apache/jmeter/assertions/ResponseAssertion.java +++ b/src/components/org/apache/jmeter/assertions/ResponseAssertion.java @@ -19,6 +19,7 @@ package org.apache.jmeter.assertions; import java.io.Serializable; +import java.net.URL; import java.util.ArrayList; import org.apache.jmeter.samplers.SampleResult; @@ -276,9 +277,9 @@ public class ResponseAssertion extends AbstractTestElement implements Serializab * an instance of SampleResult * @return an instance of AssertionResult */ - AssertionResult evaluateResponse(SampleResult response) { + private AssertionResult evaluateResponse(SampleResult response) { boolean pass = true; - boolean not = (NOT & getTestType()) > 0; + boolean notTest = (NOT & getTestType()) > 0; AssertionResult result = new AssertionResult(getName()); String toCheck = ""; // The string to check (Url or data) @@ -296,26 +297,30 @@ public class ResponseAssertion extends AbstractTestElement implements Serializab } else if (isTestFieldResponseHeaders()) { toCheck = response.getResponseHeaders(); } else { // Assume it is the URL - toCheck = response.getSamplerData(); // TODO - is this where the URL is stored? - if (toCheck == null) { - toCheck = ""; + toCheck = ""; + final URL url = response.getURL(); + if (url != null){ + toCheck = url.toString(); } } - if (toCheck.length() == 0) { - return result.setResultForNull(); - } - result.setFailure(false); result.setError(false); + if (toCheck.length() == 0) { + if (notTest) { + return result; + } + return result.setResultForNull(); + } + boolean contains = isContainsType(); // do it once outside loop boolean equals = isEqualsType(); boolean substring = isSubstringType(); boolean matches = isMatchType(); boolean debugEnabled = log.isDebugEnabled(); if (debugEnabled){ - log.debug("Type:" + (contains?"Contains":"Match") + (not? "(not)": "")); + log.debug("Type:" + (contains?"Contains":"Match") + (notTest? "(not)": "")); } try { @@ -338,7 +343,7 @@ public class ResponseAssertion extends AbstractTestElement implements Serializab } else { found = localMatcher.matches(toCheck, pattern); } - pass = not ? !found : found; + pass = notTest ? !found : found; if (!pass) { if (debugEnabled){log.debug("Failed: "+stringPattern);} result.setFailure(true); diff --git a/test/src/org/apache/jmeter/assertions/PackageTest.java b/test/src/org/apache/jmeter/assertions/PackageTest.java index 5188e5fd3e..908d19f724 100644 --- a/test/src/org/apache/jmeter/assertions/PackageTest.java +++ b/test/src/org/apache/jmeter/assertions/PackageTest.java @@ -18,6 +18,9 @@ package org.apache.jmeter.assertions; +import java.net.MalformedURLException; +import java.net.URL; + import junit.framework.TestCase; import org.apache.jmeter.junit.JMeterTestCase; @@ -41,9 +44,9 @@ public class PackageTest extends TestCase { assertEquals("D41D8CD98F00B204E9800998ECF8427E", MD5HexAssertion.baMD5Hex(new byte[] {}).toUpperCase(java.util.Locale.ENGLISH)); } - int threadsRunning; + volatile int threadsRunning; - int failed; + volatile int failed; public void testThreadSafety() throws Exception { Thread[] threads = new Thread[100]; @@ -259,7 +262,7 @@ public class PackageTest extends TestCase { private JMeterVariables vars; private AssertionResult result; - public void setUp() { + public void setUp() throws MalformedURLException { jmctx = JMeterContextService.getContext(); assertion = new ResponseAssertion(); assertion.setThreadContext(jmctx); @@ -272,7 +275,7 @@ public class PackageTest extends TestCase { "response Data\n" + "line 2\n\nEOF" ).getBytes()); - sample.setSamplerData("Sampler Label");// This is where RA checks the URL! + sample.setURL(new URL("http://localhost/Sampler/Data/")); sample.setResponseCode("401"); sample.setResponseHeaders("X-Header: abcd"); } diff --git a/xdocs/changes.xml b/xdocs/changes.xml index 67b08e91dd..4fa7579255 100644 --- a/xdocs/changes.xml +++ b/xdocs/changes.xml @@ -110,6 +110,7 @@ Moved the Scoping Rules sub-section from Section 3. "Building a Test Plan" to S