use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.
the class HTTPFileArg method setProperty.
private void setProperty(String name, JMeterProperty prop) {
JMeterProperty jmp = prop.clone();
jmp.setName(name);
setProperty(jmp);
}
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;
}
use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.
the class AssertionGui method configure.
/**
* A newly created component can be initialized with the contents of a Test
* Element object by calling this method. The component is responsible for
* querying the Test Element object for the relevant information to display
* in its GUI.
*
* @param el
* the TestElement to configure
*/
@Override
public void configure(TestElement el) {
super.configure(el);
ResponseAssertion model = (ResponseAssertion) el;
showScopeSettings(model, true);
if (model.isContainsType()) {
containsBox.setSelected(true);
} else if (model.isEqualsType()) {
equalsBox.setSelected(true);
} else if (model.isSubstringType()) {
substringBox.setSelected(true);
} else {
matchesBox.setSelected(true);
}
notBox.setSelected(model.isNotType());
orBox.setSelected(model.isOrType());
if (model.isTestFieldResponseData()) {
responseStringButton.setSelected(true);
} else if (model.isTestFieldResponseDataAsDocument()) {
responseAsDocumentButton.setSelected(true);
} else if (model.isTestFieldResponseCode()) {
responseCodeButton.setSelected(true);
} else if (model.isTestFieldResponseMessage()) {
responseMessageButton.setSelected(true);
} else if (model.isTestFieldRequestHeaders()) {
requestHeadersButton.setSelected(true);
} else if (model.isTestFieldResponseHeaders()) {
responseHeadersButton.setSelected(true);
} else // Assume it is the URL
{
urlButton.setSelected(true);
}
assumeSuccess.setSelected(model.getAssumeSuccess());
tableModel.clearData();
for (JMeterProperty jMeterProperty : model.getTestStrings()) {
tableModel.addRow(new Object[] { jMeterProperty.getStringValue() });
}
if (model.getTestStrings().size() == 0) {
deletePattern.setEnabled(false);
} else {
deletePattern.setEnabled(true);
}
tableModel.fireTableDataChanged();
}
use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.
the class DebugPostProcessor method formatPropertyIterator.
private void formatPropertyIterator(StringBuilder sb, PropertyIterator iter) {
Map<String, String> map = new HashMap<>();
while (iter.hasNext()) {
JMeterProperty item = iter.next();
map.put(item.getName(), item.getStringValue());
}
formatSet(sb, map.entrySet());
}
use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.
the class ThroughputController method getMaxThroughputAsInt.
protected int getMaxThroughputAsInt() {
JMeterProperty prop = getProperty(MAXTHROUGHPUT);
int retVal = 1;
if (prop instanceof IntegerProperty) {
retVal = ((IntegerProperty) prop).getIntValue();
} else {
String valueString = prop.getStringValue();
try {
retVal = Integer.parseInt(valueString);
} catch (NumberFormatException e) {
log.warn("Error parsing '{}'", valueString, e);
}
}
return retVal;
}
Aggregations