use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.
the class TestJavascriptFunction method setUp.
@Before
public void setUp() {
function = new JavaScript();
result = new SampleResult();
jmctx = JMeterContextService.getContext();
String data = "The quick brown fox";
result.setResponseData(data, null);
vars = new JMeterVariables();
jmctx.setVariables(vars);
jmctx.setPreviousResult(result);
params = new LinkedList<>();
}
use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.
the class TestMachineIPName method setUp.
@Before
public void setUp() {
result = new SampleResult();
jmctx = JMeterContextService.getContext();
String data = "The quick brown fox";
result.setResponseData(data, null);
vars = new JMeterVariables();
jmctx.setVariables(vars);
jmctx.setPreviousResult(result);
params = new LinkedList<>();
}
use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.
the class TestTimeFunction method setUp.
@Before
public void setUp() {
jmctx = JMeterContextService.getContext();
vars = new JMeterVariables();
jmctx.setVariables(vars);
jmctx.setPreviousResult(result);
params = new LinkedList<>();
result = new SampleResult();
variable = new TimeFunction();
}
use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.
the class TestRandomFromMultipleVars method setUp.
@Before
public void setUp() {
result = new SampleResult();
jmctx = JMeterContextService.getContext();
String data = "The quick brown fox";
result.setResponseData(data, null);
function = new RandomFromMultipleVars();
vars = new JMeterVariables();
jmctx.setVariables(vars);
jmctx.setPreviousResult(result);
params = new LinkedList<>();
}
use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.
the class TestHTTPSamplersAgainstHttpMirrorServer method testPostRequest_UrlEncoded.
private void testPostRequest_UrlEncoded(int samplerType, String samplerDefaultEncoding, int test) throws Exception {
String titleField = "title";
String titleValue = "mytitle";
String descriptionField = "description";
String descriptionValue = "mydescription";
HTTPSamplerBase sampler = createHttpSampler(samplerType);
HTTPSampleResult res;
String contentEncoding;
switch(test) {
case 0:
// Test sending data with default encoding
contentEncoding = "";
setupUrl(sampler, contentEncoding);
setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
res = executeSampler(sampler);
checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, false);
break;
case 1:
// Test sending data as ISO-8859-1
contentEncoding = ISO_8859_1;
setupUrl(sampler, contentEncoding);
setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
res = executeSampler(sampler);
checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, false);
break;
case 2:
// Test sending data as UTF-8
contentEncoding = "UTF-8";
titleValue = "mytitle2œ₡ĕÅ";
descriptionValue = "mydescription2œ₡ĕÅ";
setupUrl(sampler, contentEncoding);
setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
res = executeSampler(sampler);
checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, false);
break;
case 3:
// Test sending data as UTF-8, with values that will change when urlencoded
contentEncoding = "UTF-8";
titleValue = "mytitle3/=";
descriptionValue = "mydescription3 /\\";
setupUrl(sampler, contentEncoding);
setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
res = executeSampler(sampler);
checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, false);
break;
case 4:
// Test sending data as UTF-8, with values that have been urlencoded
contentEncoding = "UTF-8";
titleValue = "mytitle4%2F%3D";
descriptionValue = "mydescription4+++%2F%5C";
setupUrl(sampler, contentEncoding);
setupFormData(sampler, true, titleField, titleValue, descriptionField, descriptionValue);
res = executeSampler(sampler);
checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, true);
break;
case 5:
// Test sending data as UTF-8, with values similar to __VIEWSTATE parameter that .net uses
contentEncoding = "UTF-8";
titleValue = "/wEPDwULLTE2MzM2OTA0NTYPZBYCAgMPZ/rA+8DZ2dnZ2dnZ2d/GNDar6OshPwdJc=";
descriptionValue = "mydescription5";
setupUrl(sampler, contentEncoding);
setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
res = executeSampler(sampler);
checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, false);
break;
case 6:
// Test sending data as UTF-8, with values similar to __VIEWSTATE parameter that .net uses,
// with values urlencoded, but the always encode set to false for the arguments
// This is how the HTTP Proxy server adds arguments to the sampler
contentEncoding = "UTF-8";
titleValue = "%2FwEPDwULLTE2MzM2OTA0NTYPZBYCAgMPZ%2FrA%2B8DZ2dnZ2dnZ2d%2FGNDar6OshPwdJc%3D";
descriptionValue = "mydescription6";
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);
assertFalse(((HTTPArgument) sampler.getArguments().getArgument(0)).isAlwaysEncoded());
assertFalse(((HTTPArgument) sampler.getArguments().getArgument(1)).isAlwaysEncoded());
checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, true);
break;
case 7:
// 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());
contentEncoding = "UTF-8";
titleValue = "${title_prefix}mytitle7œ₡ĕÅ";
descriptionValue = "mydescription7œ₡ĕÅ${description_suffix}";
setupUrl(sampler, contentEncoding);
setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
// Replace the variables in the sampler
replacer.replaceValues(sampler);
res = executeSampler(sampler);
String expectedTitleValue = "a testÅmytitle7œ₡ĕÅ";
String expectedDescriptionValue = "mydescription7œ₡ĕÅthe_end";
checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, expectedTitleValue, descriptionField, expectedDescriptionValue, false);
break;
case 8:
break;
case 9:
break;
case 10:
break;
default:
fail("Unexpected switch value: " + test);
}
}
Aggregations