mirror of https://github.com/apache/jmeter.git
Bug 45904 - Allow 'Not' Response Assertion to succeed with null sample
git-svn-id: https://svn.apache.org/repos/asf/jakarta/jmeter/trunk@701680 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9e257074eb
commit
2ab1c97a10
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -110,6 +110,7 @@ Moved the Scoping Rules sub-section from Section 3. "Building a Test Plan" to S
|
|||
<li>Bug 45831 - WS Sampler reports incorrect throughput if SOAP packet creation fails</li>
|
||||
<li>Bug 45887 - TCPSampler: timeout property incorrectly set</li>
|
||||
<li>Bug 45928 - AJP/1.3 Sampler doesn't retrieve his label from messages.properties</li>
|
||||
<li>Bug 45904 - Allow 'Not' Response Assertion to succeed with null sample</li>
|
||||
</ul>
|
||||
|
||||
<h3>Improvements</h3>
|
||||
|
|
|
|||
Loading…
Reference in New Issue