use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.
the class PackageTest method testParseExample10.
@Test
public void testParseExample10() throws Exception {
StringProperty prop = new StringProperty("html", "${__regexFunction(\\ " + "(\\\\\\$\\d+\\.\\d+\\,\\\\$\\d+\\.\\d+),$1$)}");
JMeterProperty newProp = transformer.transformValue(prop);
newProp.setRunningVersion(true);
assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName());
assertEquals("$3.47,$5.67", newProp.getStringValue());
}
use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.
the class PackageTest method testNestedExample1.
@Test
public void testNestedExample1() throws Exception {
StringProperty prop = new StringProperty("html", "${__regexFunction(<html>(${my_regex})</html>," + "$1$)}${__regexFunction(<html>(.*o)(.*o)(.*)" + "</html>,$1$$3$)}");
JMeterProperty newProp = transformer.transformValue(prop);
newProp.setRunningVersion(true);
assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName());
assertEquals("hello worldhellorld", newProp.getStringValue());
}
use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.
the class PackageTest method testParseExample12.
// N.B. See Bug 46831 which wanted to changed the behaviour of \$
// It's too late now, as this would invalidate some existing test plans,
// so document the current behaviour with some more tests.
// Escaped dollar commma and backslash with variable reference
@Test
public void testParseExample12() throws Exception {
StringProperty prop = new StringProperty("html", "\\$a \\, \\\\ \\x \\ ${server} \\$b \\, \\\\ cd");
JMeterProperty newProp = transformer.transformValue(prop);
newProp.setRunningVersion(true);
// N.B. Backslashes are removed before dollar, comma and backslash
assertEquals("$a , \\ \\x \\ jakarta.apache.org $b , \\ cd", newProp.getStringValue());
}
use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.
the class PackageTest method testParseExample5.
@Test
public void testParseExample5() throws Exception {
StringProperty prop = new StringProperty("html", "");
JMeterProperty newProp = transformer.transformValue(prop);
newProp.setRunningVersion(true);
assertEquals("org.apache.jmeter.testelement.property.StringProperty", newProp.getClass().getName());
assertEquals("", newProp.getStringValue());
}
use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.
the class ResponseAssertion method evaluateResponse.
/**
* Make sure the response satisfies the specified assertion requirements.
*
* @param response
* an instance of SampleResult
* @return an instance of AssertionResult
*/
private AssertionResult evaluateResponse(SampleResult response) {
AssertionResult result = new AssertionResult(getName());
if (getAssumeSuccess()) {
// Allow testing of failure codes
response.setSuccessful(true);
}
// The string to check (Url or data)
String toCheck;
// What are we testing against?
if (isScopeVariable()) {
toCheck = getThreadContext().getVariables().get(getVariableName());
} else if (isTestFieldResponseData()) {
// (bug25052)
toCheck = response.getResponseDataAsString();
} else if (isTestFieldResponseDataAsDocument()) {
toCheck = Document.getTextFromDocument(response.getResponseData());
} else if (isTestFieldResponseCode()) {
toCheck = response.getResponseCode();
} else if (isTestFieldResponseMessage()) {
toCheck = response.getResponseMessage();
} else if (isTestFieldRequestHeaders()) {
toCheck = response.getRequestHeaders();
} else if (isTestFieldResponseHeaders()) {
toCheck = response.getResponseHeaders();
} else {
// Assume it is the URL
toCheck = "";
final URL url = response.getURL();
if (url != null) {
toCheck = url.toString();
}
}
result.setFailure(false);
result.setError(false);
boolean notTest = (NOT & getTestType()) > 0;
boolean orTest = (OR & getTestType()) > 0;
// do it once outside loop
boolean contains = isContainsType();
boolean equals = isEqualsType();
boolean substring = isSubstringType();
boolean matches = isMatchType();
log.debug("Test Type Info: contains={}, notTest={}, orTest={}", contains, notTest, orTest);
if (StringUtils.isEmpty(toCheck)) {
if (notTest) {
// Not should always succeed against an empty result
return result;
}
if (log.isDebugEnabled()) {
log.debug("Not checking empty response field in: {}", response.getSampleLabel());
}
return result.setResultForNull();
}
boolean pass = true;
boolean hasTrue = false;
ArrayList<String> allCheckMessage = new ArrayList<>();
try {
// Get the Matcher for this thread
Perl5Matcher localMatcher = JMeterUtils.getMatcher();
for (JMeterProperty jMeterProperty : getTestStrings()) {
String stringPattern = jMeterProperty.getStringValue();
Pattern pattern = null;
if (contains || matches) {
pattern = JMeterUtils.getPatternCache().getPattern(stringPattern, Perl5Compiler.READ_ONLY_MASK);
}
boolean found;
if (contains) {
found = localMatcher.contains(toCheck, pattern);
} else if (equals) {
found = toCheck.equals(stringPattern);
} else if (substring) {
found = toCheck.contains(stringPattern);
} else {
found = localMatcher.matches(toCheck, pattern);
}
pass = notTest ? !found : found;
if (orTest) {
if (!pass) {
log.debug("Failed: {}", stringPattern);
allCheckMessage.add(getFailText(stringPattern, toCheck));
} else {
hasTrue = true;
break;
}
} else {
if (!pass) {
log.debug("Failed: {}", stringPattern);
result.setFailure(true);
result.setFailureMessage(getFailText(stringPattern, toCheck));
break;
}
log.debug("Passed: {}", stringPattern);
}
}
if (orTest && !hasTrue) {
StringBuilder errorMsg = new StringBuilder();
for (String tmp : allCheckMessage) {
errorMsg.append(tmp).append('\t');
}
result.setFailure(true);
result.setFailureMessage(errorMsg.toString());
}
} catch (MalformedCachePatternException e) {
result.setError(true);
result.setFailure(false);
result.setFailureMessage("Bad test configuration " + e);
}
return result;
}
Aggregations