use of org.apache.jmeter.testelement.property.PropertyIterator in project jmeter by apache.
the class HTTPHC4Impl method createUrlEncodedFormEntity.
/**
* Create UrlEncodedFormEntity from parameters
* @param contentEncoding Content encoding may be null or empty
* @return {@link UrlEncodedFormEntity}
* @throws UnsupportedEncodingException
*/
private UrlEncodedFormEntity createUrlEncodedFormEntity(final String contentEncoding) throws UnsupportedEncodingException {
// It is a normal request, with parameter names and values
// Add the parameters
PropertyIterator args = getArguments().iterator();
List<NameValuePair> nvps = new ArrayList<>();
String urlContentEncoding = contentEncoding;
if (urlContentEncoding == null || urlContentEncoding.length() == 0) {
// Use the default encoding for urls
urlContentEncoding = EncoderCache.URL_ARGUMENT_ENCODING;
}
while (args.hasNext()) {
HTTPArgument arg = (HTTPArgument) args.next().getObjectValue();
// The HTTPClient always urlencodes both name and value,
// so if the argument is already encoded, we have to decode
// it before adding it to the post request
String parameterName = arg.getName();
if (arg.isSkippable(parameterName)) {
continue;
}
String parameterValue = arg.getValue();
if (!arg.isAlwaysEncoded()) {
// The value is already encoded by the user
// Must decode the value now, so that when the
// httpclient encodes it, we end up with the same value
// as the user had entered.
parameterName = URLDecoder.decode(parameterName, urlContentEncoding);
parameterValue = URLDecoder.decode(parameterValue, urlContentEncoding);
}
// Add the parameter, httpclient will urlencode it
nvps.add(new BasicNameValuePair(parameterName, parameterValue));
}
return new UrlEncodedFormEntity(nvps, urlContentEncoding);
}
use of org.apache.jmeter.testelement.property.PropertyIterator 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) {
PropertyIterator props = sampler.propertyIterator();
while (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;
}
}
}
}
use of org.apache.jmeter.testelement.property.PropertyIterator in project jmeter by apache.
the class HTTPFileArgs method toString.
/**
* Create a string representation of the files.
*
* @return the string representation of the files
*/
@Override
public String toString() {
StringBuilder str = new StringBuilder();
PropertyIterator iter = getHTTPFileArgsCollection().iterator();
while (iter.hasNext()) {
HTTPFileArg file = (HTTPFileArg) iter.next().getObjectValue();
str.append(file.toString());
if (iter.hasNext()) {
// $NON-NLS-1$
str.append("\n");
}
}
return str.toString();
}
use of org.apache.jmeter.testelement.property.PropertyIterator in project jmeter by apache.
the class TestHTTPFileArgs method testRemoving.
@Test
public void testRemoving() throws Exception {
HTTPFileArgs files = new HTTPFileArgs();
assertEquals(0, files.getHTTPFileArgCount());
files.addHTTPFileArg("hede");
assertEquals(1, files.getHTTPFileArgCount());
files.clear();
assertEquals(0, files.getHTTPFileArgCount());
files.addHTTPFileArg("file1");
files.addHTTPFileArg("file2");
files.addHTTPFileArg("file3");
HTTPFileArg file = new HTTPFileArg("file4");
files.addHTTPFileArg(file);
files.addHTTPFileArg("file5");
files.addHTTPFileArg("file6");
assertEquals(6, files.getHTTPFileArgCount());
files.removeHTTPFileArg("file3");
assertEquals(5, files.getHTTPFileArgCount());
PropertyIterator iter = files.iterator();
assertEquals("file1", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
assertEquals("file2", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
assertEquals("file4", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
assertEquals("file5", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
assertEquals("file6", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
files.removeHTTPFileArg(file);
assertEquals(4, files.getHTTPFileArgCount());
iter = files.iterator();
assertEquals("file1", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
assertEquals("file2", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
assertEquals("file5", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
assertEquals("file6", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
files.removeHTTPFileArg(new HTTPFileArg("file5"));
assertEquals(3, files.getHTTPFileArgCount());
iter = files.iterator();
assertEquals("file1", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
assertEquals("file2", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
assertEquals("file6", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
files.removeHTTPFileArg(1);
assertEquals(2, files.getHTTPFileArgCount());
iter = files.iterator();
assertEquals("file1", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
assertEquals("file6", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
files.removeAllHTTPFileArgs();
assertEquals(0, files.getHTTPFileArgCount());
}
use of org.apache.jmeter.testelement.property.PropertyIterator in project jmeter by apache.
the class JMSProperties method toString.
/**
* Create a string representation of the JmsProperties.
*
* @return the string representation of the JmsProperties
*/
@Override
public String toString() {
StringBuilder str = new StringBuilder();
PropertyIterator iter = getProperties().iterator();
while (iter.hasNext()) {
JMSProperty arg = (JMSProperty) iter.next().getObjectValue();
str.append(arg.toString());
if (iter.hasNext()) {
// $NON-NLS-1$
str.append(",");
}
}
return str.toString();
}
Aggregations