use of org.apache.jmeter.config.Argument in project jmeter by apache.
the class SmtpPanel method getHeaderFields.
public CollectionProperty getHeaderFields() {
CollectionProperty result = new CollectionProperty();
result.setName(SmtpSampler.HEADER_FIELDS);
for (JTextField headerName : headerFields.keySet()) {
String name = headerName.getText();
String value = headerFields.get(headerName).getText();
Argument argument = new Argument(name, value);
result.addItem(argument);
}
return result;
}
use of org.apache.jmeter.config.Argument in project jmeter by apache.
the class LDAPExtSampler method getUserAttributes.
/***************************************************************************
* Collect all the values from the table (Arguments), using this create the
* Attributes, this will create the Attributes for the User
* defined TestCase for Add Test
*
* @return The Attributes
**************************************************************************/
private Attributes getUserAttributes() {
Attributes attrs = new BasicAttributes(true);
Attribute attr;
for (JMeterProperty jMeterProperty : getArguments()) {
Argument item = (Argument) jMeterProperty.getObjectValue();
attr = attrs.get(item.getName());
if (attr == null) {
attr = getBasicAttribute(item.getName(), item.getValue());
} else {
attr.add(item.getValue());
}
attrs.put(attr);
}
return attrs;
}
use of org.apache.jmeter.config.Argument in project jmeter by apache.
the class LDAPSampler method getUserModAttributes.
/**
* Collect all the value from the table (Arguments), using this create the
* basicAttributes. This will create the Basic Attributes for the User
* defined TestCase for Modify test.
*
* @return the BasicAttributes
*/
private ModificationItem[] getUserModAttributes() {
ModificationItem[] mods = new ModificationItem[getArguments().getArguments().size()];
BasicAttribute attr;
PropertyIterator iter = getArguments().iterator();
int count = 0;
while (iter.hasNext()) {
Argument item = (Argument) iter.next().getObjectValue();
attr = getBasicAttribute(item.getName(), item.getValue());
mods[count] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, attr);
count = +1;
}
return mods;
}
use of org.apache.jmeter.config.Argument in project jmeter by apache.
the class SystemSampler method sample.
/**
* Performs a test sample.
*
* @param entry
* the Entry for this sample
* @return test SampleResult
*/
@Override
public SampleResult sample(Entry entry) {
SampleResult results = new SampleResult();
results.setDataType(SampleResult.TEXT);
results.setSampleLabel(getName());
String command = getCommand();
Arguments args = getArguments();
Arguments environment = getEnvironmentVariables();
boolean checkReturnCode = getCheckReturnCode();
int expectedReturnCode = getExpectedReturnCode();
List<String> cmds = new ArrayList<>(args.getArgumentCount() + 1);
StringBuilder cmdLine = new StringBuilder((null == command) ? "" : command);
cmds.add(command);
for (int i = 0; i < args.getArgumentCount(); i++) {
Argument arg = args.getArgument(i);
cmds.add(arg.getPropertyAsString(Argument.VALUE));
cmdLine.append(" ");
cmdLine.append(cmds.get(i + 1));
}
Map<String, String> env = new HashMap<>();
for (int i = 0; i < environment.getArgumentCount(); i++) {
Argument arg = environment.getArgument(i);
env.put(arg.getName(), arg.getPropertyAsString(Argument.VALUE));
}
File directory;
if (StringUtils.isEmpty(getDirectory())) {
directory = new File(FileServer.getDefaultBase());
if (log.isDebugEnabled()) {
log.debug("Using default directory:" + directory.getAbsolutePath());
}
} else {
directory = new File(getDirectory());
if (log.isDebugEnabled()) {
log.debug("Using configured directory:" + directory.getAbsolutePath());
}
}
if (log.isDebugEnabled()) {
log.debug("Will run : " + cmdLine + " using working directory:" + directory.getAbsolutePath() + " with environment: " + env);
}
results.setSamplerData("Working Directory: " + directory.getAbsolutePath() + "\nEnvironment: " + env + "\nExecuting: " + cmdLine.toString());
SystemCommand nativeCommand = null;
try {
nativeCommand = new SystemCommand(directory, getTimeout(), POLL_INTERVAL, env, getStdin(), getStdout(), getStderr());
results.sampleStart();
int returnCode = nativeCommand.run(cmds);
results.sampleEnd();
results.setResponseCode(Integer.toString(returnCode));
if (log.isDebugEnabled()) {
log.debug("Ran : " + cmdLine + " using working directory: " + directory.getAbsolutePath() + " with execution environment: " + nativeCommand.getExecutionEnvironment() + " => " + returnCode);
}
if (checkReturnCode && (returnCode != expectedReturnCode)) {
results.setSuccessful(false);
results.setResponseMessage("Unexpected return code. Expected [" + expectedReturnCode + "]. Actual [" + returnCode + "].");
} else {
results.setSuccessful(true);
results.setResponseMessage("OK");
}
} catch (IOException ioe) {
results.sampleEnd();
results.setSuccessful(false);
//$NON-NLS-1$
results.setResponseCode("500");
results.setResponseMessage("Exception occurred whilst executing system call: " + ioe);
} catch (InterruptedException ie) {
results.sampleEnd();
results.setSuccessful(false);
//$NON-NLS-1$
results.setResponseCode("500");
results.setResponseMessage("System Sampler interrupted whilst executing system call: " + ie);
Thread.currentThread().interrupt();
}
if (nativeCommand != null) {
// default charset is deliberate here
results.setResponseData(nativeCommand.getOutResult().getBytes());
}
return results;
}
use of org.apache.jmeter.config.Argument 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;
}
Aggregations