use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.
the class TestElementTest method checkElementCloning.
private static void checkElementCloning(TestElement item) {
TestElement clonedItem = (TestElement) item.clone();
cloneTesting(item, clonedItem);
PropertyIterator iter2 = item.propertyIterator();
while (iter2.hasNext()) {
JMeterProperty item2 = iter2.next();
assertEquals(item2.getStringValue(), clonedItem.getProperty(item2.getName()).getStringValue());
assertTrue(item2 != clonedItem.getProperty(item2.getName()));
}
}
use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.
the class HtmlParsingUtils method isAnchorMatched.
/**
* Check if anchor matches by checking against:
* - protocol
* - domain
* - path
* - parameter names
*
* @param newLink target to match
* @param config pattern to match against
*
* @return true if target URL matches pattern URL
*/
public static boolean isAnchorMatched(HTTPSamplerBase newLink, HTTPSamplerBase config) {
String query = null;
try {
query = URLDecoder.decode(newLink.getQueryString(), StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
// UTF-8 unsupported? You must be joking!
log.error("UTF-8 encoding not supported!");
throw new Error("Should not happen: " + e.toString(), e);
}
final Arguments arguments = config.getArguments();
final Perl5Matcher matcher = JMeterUtils.getMatcher();
final PatternCacheLRU patternCache = JMeterUtils.getPatternCache();
if (!isEqualOrMatches(newLink.getProtocol(), config.getProtocol(), matcher, patternCache)) {
return false;
}
final String domain = config.getDomain();
if (domain != null && domain.length() > 0) {
if (!isEqualOrMatches(newLink.getDomain(), domain, matcher, patternCache)) {
return false;
}
}
final String path = config.getPath();
if (!newLink.getPath().equals(path) && !matcher.matches(newLink.getPath(), // $NON-NLS-1$
patternCache.getPattern(// $NON-NLS-1$
"[/]*" + path, Perl5Compiler.READ_ONLY_MASK))) {
return false;
}
for (JMeterProperty argument : arguments) {
Argument item = (Argument) argument.getObjectValue();
final String name = item.getName();
if (!query.contains(name + "=")) {
// $NON-NLS-1$
if (!(matcher.contains(query, patternCache.getPattern(name, Perl5Compiler.READ_ONLY_MASK)))) {
return false;
}
}
}
return true;
}
use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.
the class AnchorModifier method process.
/**
* Modifies an Entry object based on HTML response text.
*/
@Override
public void process() {
JMeterContext context = getThreadContext();
Sampler sam = context.getCurrentSampler();
SampleResult res = context.getPreviousResult();
HTTPSamplerBase sampler;
HTTPSampleResult result;
if (!(sam instanceof HTTPSamplerBase) || !(res instanceof HTTPSampleResult)) {
log.info("Can't apply HTML Link Parser when the previous" + " sampler run is not an HTTP Request.");
return;
} else {
sampler = (HTTPSamplerBase) sam;
result = (HTTPSampleResult) res;
}
List<HTTPSamplerBase> potentialLinks = new ArrayList<>();
String responseText = result.getResponseDataAsString();
// $NON-NLS-1$
int index = responseText.indexOf('<');
if (index == -1) {
index = 0;
}
if (log.isDebugEnabled()) {
log.debug("Check for matches against: " + sampler.toString());
}
Document html = (Document) HtmlParsingUtils.getDOM(responseText.substring(index));
addAnchorUrls(html, result, sampler, potentialLinks);
addFormUrls(html, result, sampler, potentialLinks);
addFramesetUrls(html, result, sampler, potentialLinks);
if (!potentialLinks.isEmpty()) {
HTTPSamplerBase url = potentialLinks.get(ThreadLocalRandom.current().nextInt(potentialLinks.size()));
if (log.isDebugEnabled()) {
log.debug("Selected: " + url.toString());
}
sampler.setDomain(url.getDomain());
sampler.setPath(url.getPath());
if (url.getMethod().equals(HTTPConstants.POST)) {
for (JMeterProperty jMeterProperty : sampler.getArguments()) {
Argument arg = (Argument) jMeterProperty.getObjectValue();
modifyArgument(arg, url.getArguments());
}
} else {
sampler.setArguments(url.getArguments());
// config.parseArguments(url.getQueryString());
}
sampler.setProtocol(url.getProtocol());
} else {
log.debug("No matches found");
}
}
use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.
the class RegExUserParameters method process.
@Override
public void process() {
if (log.isDebugEnabled()) {
//$NON-NLS-1$
log.debug(Thread.currentThread().getName() + " Running up named: " + getName());
}
Sampler entry = getThreadContext().getCurrentSampler();
if (!(entry instanceof HTTPSamplerBase)) {
return;
}
Map<String, String> paramMap = buildParamsMap();
if (paramMap == null || paramMap.isEmpty()) {
log.info("RegExUserParameters element:" + getName() + " => Referenced RegExp was not found, no parameter will be changed");
return;
}
HTTPSamplerBase sampler = (HTTPSamplerBase) entry;
for (JMeterProperty jMeterProperty : sampler.getArguments()) {
Argument arg = (Argument) jMeterProperty.getObjectValue();
String oldValue = arg.getValue();
// if parameter name exists in http request
// then change its value with value obtained with regular expression
String val = paramMap.get(arg.getName());
if (val != null) {
arg.setValue(val);
}
if (log.isDebugEnabled()) {
log.debug("RegExUserParameters element:" + getName() + " => changed parameter: " + arg.getName() + " = " + arg.getValue() + ", was:" + oldValue);
}
}
}
use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.
the class ProxyControl method removeValuesFromSampler.
/**
* Remove from the sampler all values which match the one provided by the
* first configuration in the given collection which provides a value for
* that property.
*
* @param sampler
* Sampler to remove values from.
* @param configurations
* ConfigTestElements in descending priority.
*/
private void removeValuesFromSampler(HTTPSamplerBase sampler, Collection<ConfigTestElement> configurations) {
for (PropertyIterator props = sampler.propertyIterator(); props.hasNext(); ) {
JMeterProperty prop = props.next();
String name = prop.getName();
String value = prop.getStringValue();
// There's a few properties which are excluded from this processing:
if (name.equals(TestElement.ENABLED) || name.equals(TestElement.GUI_CLASS) || name.equals(TestElement.NAME) || name.equals(TestElement.TEST_CLASS)) {
// go on with next property.
continue;
}
for (ConfigTestElement config : configurations) {
String configValue = config.getPropertyAsString(name);
if (configValue != null && configValue.length() > 0) {
if (configValue.equals(value)) {
// $NON-NLS-1$
sampler.setProperty(name, "");
}
// this property -- don't look at lower-priority configs:
break;
}
}
}
}
Aggregations