use of org.apache.jmeter.testelement.TestPlan in project jmeter by apache.
the class TestHTTPSamplersAgainstHttpMirrorServer method testPostRequest_BodyFromParameterValues.
private void testPostRequest_BodyFromParameterValues(int samplerType, String samplerDefaultEncoding) throws Exception {
// ensure only values are used
final String titleField = "";
String titleValue = "mytitle";
// ensure only values are used
final String descriptionField = "";
String descriptionValue = "mydescription";
// Test sending data with default encoding
HTTPSamplerBase sampler = createHttpSampler(samplerType);
String contentEncoding = "";
setupUrl(sampler, contentEncoding);
setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
((HTTPArgument) sampler.getArguments().getArgument(0)).setAlwaysEncoded(false);
((HTTPArgument) sampler.getArguments().getArgument(1)).setAlwaysEncoded(false);
HTTPSampleResult res = executeSampler(sampler);
String expectedPostBody = titleValue + descriptionValue;
checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody);
// Test sending data as ISO-8859-1
sampler = createHttpSampler(samplerType);
contentEncoding = ISO_8859_1;
setupUrl(sampler, contentEncoding);
setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
((HTTPArgument) sampler.getArguments().getArgument(0)).setAlwaysEncoded(false);
((HTTPArgument) sampler.getArguments().getArgument(1)).setAlwaysEncoded(false);
res = executeSampler(sampler);
expectedPostBody = titleValue + descriptionValue;
checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody);
// Test sending data as UTF-8
sampler = createHttpSampler(samplerType);
contentEncoding = "UTF-8";
titleValue = "mytitleœ₡ĕÅ";
descriptionValue = "mydescriptionœ₡ĕÅ";
setupUrl(sampler, contentEncoding);
setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
((HTTPArgument) sampler.getArguments().getArgument(0)).setAlwaysEncoded(false);
((HTTPArgument) sampler.getArguments().getArgument(1)).setAlwaysEncoded(false);
res = executeSampler(sampler);
expectedPostBody = titleValue + descriptionValue;
checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody);
// Test sending data as UTF-8, with values that will change when urlencoded
sampler = createHttpSampler(samplerType);
contentEncoding = "UTF-8";
titleValue = "mytitle/=";
descriptionValue = "mydescription /\\";
setupUrl(sampler, contentEncoding);
setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
((HTTPArgument) sampler.getArguments().getArgument(0)).setAlwaysEncoded(false);
((HTTPArgument) sampler.getArguments().getArgument(1)).setAlwaysEncoded(false);
res = executeSampler(sampler);
expectedPostBody = titleValue + descriptionValue;
checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody);
// Test sending data as UTF-8, with values that will change when urlencoded, and where
// we tell the sampler to urlencode the parameter value
sampler = createHttpSampler(samplerType);
contentEncoding = "UTF-8";
titleValue = "mytitle/=";
descriptionValue = "mydescription /\\";
setupUrl(sampler, contentEncoding);
setupFormData(sampler, true, titleField, titleValue, descriptionField, descriptionValue);
res = executeSampler(sampler);
expectedPostBody = URLEncoder.encode(titleValue + descriptionValue, contentEncoding);
checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody);
// Test sending data as UTF-8, with values that have been urlencoded
sampler = createHttpSampler(samplerType);
contentEncoding = "UTF-8";
titleValue = "mytitle%2F%3D";
descriptionValue = "mydescription+++%2F%5C";
setupUrl(sampler, contentEncoding);
setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
((HTTPArgument) sampler.getArguments().getArgument(0)).setAlwaysEncoded(false);
((HTTPArgument) sampler.getArguments().getArgument(1)).setAlwaysEncoded(false);
res = executeSampler(sampler);
expectedPostBody = titleValue + descriptionValue;
checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody);
// Test sending data as UTF-8, with values that have been urlencoded, and
// where we tell the sampler to urlencode the parameter values
sampler = createHttpSampler(samplerType);
contentEncoding = "UTF-8";
titleValue = "mytitle%2F%3D";
descriptionValue = "mydescription+++%2F%5C";
setupUrl(sampler, contentEncoding);
setupFormData(sampler, true, titleField, titleValue, descriptionField, descriptionValue);
res = executeSampler(sampler);
expectedPostBody = titleValue + descriptionValue;
checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody);
// Test sending data as UTF-8, with values similar to __VIEWSTATE parameter that .net uses
sampler = createHttpSampler(samplerType);
contentEncoding = "UTF-8";
titleValue = "/wEPDwULLTE2MzM2OTA0NTYPZBYCAgMPZ/rA+8DZ2dnZ2dnZ2d/GNDar6OshPwdJc=";
descriptionValue = "mydescription";
setupUrl(sampler, contentEncoding);
setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
((HTTPArgument) sampler.getArguments().getArgument(0)).setAlwaysEncoded(false);
((HTTPArgument) sampler.getArguments().getArgument(1)).setAlwaysEncoded(false);
res = executeSampler(sampler);
expectedPostBody = titleValue + descriptionValue;
checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody);
// Test sending data as UTF-8, with + as part of the value,
// where the value is set in sampler as not urluencoded, but the
// isalwaysencoded flag of the argument is set to false.
// This mimics the HTTPConstants.addNonEncodedArgument, which the
// Proxy server calls in some cases
sampler = createHttpSampler(samplerType);
contentEncoding = "UTF-8";
titleValue = "mytitle++";
descriptionValue = "mydescription+";
setupUrl(sampler, contentEncoding);
setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
((HTTPArgument) sampler.getArguments().getArgument(0)).setAlwaysEncoded(false);
((HTTPArgument) sampler.getArguments().getArgument(1)).setAlwaysEncoded(false);
res = executeSampler(sampler);
expectedPostBody = titleValue + descriptionValue;
checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody);
// Test sending data as UTF-8, where user defined variables are used
// to set the value for form data
JMeterUtils.setLocale(Locale.ENGLISH);
TestPlan testPlan = new TestPlan();
JMeterVariables vars = new JMeterVariables();
vars.put("title_prefix", "a testÅ");
vars.put("description_suffix", "the_end");
JMeterContextService.getContext().setVariables(vars);
JMeterContextService.getContext().setSamplingStarted(true);
ValueReplacer replacer = new ValueReplacer();
replacer.setUserDefinedVariables(testPlan.getUserDefinedVariables());
sampler = createHttpSampler(samplerType);
contentEncoding = "UTF-8";
titleValue = "${title_prefix}mytitleœ₡ĕÅ";
descriptionValue = "mydescriptionœ₡ĕÅ${description_suffix}";
setupUrl(sampler, contentEncoding);
setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
((HTTPArgument) sampler.getArguments().getArgument(0)).setAlwaysEncoded(false);
((HTTPArgument) sampler.getArguments().getArgument(1)).setAlwaysEncoded(false);
// Replace the variables in the sampler
replacer.replaceValues(sampler);
res = executeSampler(sampler);
String expectedTitleValue = "a testÅmytitleœ₡ĕÅ";
String expectedDescriptionValue = "mydescriptionœ₡ĕÅthe_end";
expectedPostBody = expectedTitleValue + expectedDescriptionValue;
checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody);
}
use of org.apache.jmeter.testelement.TestPlan in project jmeter by apache.
the class Move method getParentNode.
private JMeterTreeNode getParentNode(JMeterTreeNode currentNode) {
JMeterTreeNode parentNode = (JMeterTreeNode) currentNode.getParent();
TestElement te = currentNode.getTestElement();
if (te instanceof TestPlan || te instanceof WorkBench) {
// So elements can only be added as children
parentNode = null;
}
return parentNode;
}
use of org.apache.jmeter.testelement.TestPlan in project jmeter by apache.
the class ProxyControlGui method buildNodesModel.
private void buildNodesModel(JMeterTreeNode node, String parentName, int level) {
String separator = " > ";
if (node != null) {
for (int i = 0; i < node.getChildCount(); i++) {
StringBuilder name = new StringBuilder();
JMeterTreeNode cur = (JMeterTreeNode) node.getChildAt(i);
TestElement te = cur.getTestElement();
/*
* Will never be true. Probably intended to use
* org.apache.jmeter.threads.ThreadGroup rather than
* java.lang.ThreadGroup However, that does not work correctly;
* whereas treating it as a Controller does. if (te instanceof
* ThreadGroup) { name.append(parent_name);
* name.append(cur.getName()); name.append(separator);
* buildNodesModel(cur, name.toString(), level); } else
*/
if (te instanceof Controller) {
name.append(parentName);
name.append(cur.getName());
TreeNodeWrapper tnw = new TreeNodeWrapper(cur, name.toString());
targetNodesModel.addElement(tnw);
name.append(separator);
buildNodesModel(cur, name.toString(), level + 1);
} else if (te instanceof TestPlan || te instanceof WorkBench) {
name.append(cur.getName());
name.append(separator);
buildNodesModel(cur, name.toString(), 0);
}
// Ignore everything else
}
}
}
use of org.apache.jmeter.testelement.TestPlan in project jmeter by apache.
the class TestValueReplacer method testReverseReplacementXml.
@Test
public void testReverseReplacementXml() throws Exception {
ValueReplacer replacer = new ValueReplacer(variables);
assertTrue(variables.getUserDefinedVariables().containsKey("bounded_regex"));
assertTrue(variables.getUserDefinedVariables().containsKey("normal_regex"));
assertTrue(replacer.containsKey("bounded_regex"));
assertTrue(replacer.containsKey("normal_regex"));
TestElement element = new TestPlan();
element.setProperty(new StringProperty("domain", "<this><is>xml</this></is>"));
List<Object> argsin = new ArrayList<>();
argsin.add("<this><is>xml</this></is>");
argsin.add("And I say: Hello World.");
element.setProperty(new CollectionProperty("args", argsin));
replacer.reverseReplace(element, true);
@SuppressWarnings("unchecked") List<JMeterProperty> args = (List<JMeterProperty>) element.getProperty("args").getObjectValue();
assertEquals("${bounded_regex}", element.getPropertyAsString("domain"));
assertEquals("${bounded_regex}", args.get(0).getStringValue());
}
use of org.apache.jmeter.testelement.TestPlan in project jmeter by apache.
the class PreCompiler method addNode.
/** {@inheritDoc} */
@Override
public void addNode(Object node, HashTree subTree) {
if (isRemote && node instanceof ResultCollector) {
try {
replacer.replaceValues((TestElement) node);
} catch (InvalidVariableException e) {
log.error("invalid variables", e);
}
}
if (isRemote) {
return;
}
if (node instanceof TestElement) {
try {
replacer.replaceValues((TestElement) node);
} catch (InvalidVariableException e) {
log.error("invalid variables", e);
}
}
if (node instanceof TestPlan) {
//A hack to make user-defined variables in the testplan element more dynamic
((TestPlan) node).prepareForPreCompile();
Map<String, String> args = ((TestPlan) node).getUserDefinedVariables();
replacer.setUserDefinedVariables(args);
JMeterVariables vars = new JMeterVariables();
vars.putAll(args);
JMeterContextService.getContext().setVariables(vars);
}
if (node instanceof Arguments) {
((Arguments) node).setRunningVersion(true);
Map<String, String> args = ((Arguments) node).getArgumentsAsMap();
replacer.addVariables(args);
JMeterContextService.getContext().getVariables().putAll(args);
}
}
Aggregations