View | Details | Raw Unified | Return to bug 42156
Collapse All | Expand All

(-)C:/Documents and Settings/alf.hogemark/workspace/JMeter 2.2 official_2/test/src/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplersAgainstHttpMirrorServer.java (-62 / +312 lines)
Lines 24-34 Link Here
24
import java.io.IOException;
24
import java.io.IOException;
25
import java.io.OutputStream;
25
import java.io.OutputStream;
26
import java.io.UnsupportedEncodingException;
26
import java.io.UnsupportedEncodingException;
27
import java.net.URLDecoder;
27
import java.net.URLEncoder;
28
import java.net.URLEncoder;
28
import java.net.URL;
29
import java.net.URL;
29
import java.util.Locale;
30
import java.util.Locale;
30
31
31
import org.apache.jmeter.config.Arguments;
32
import org.apache.jmeter.engine.util.ValueReplacer;
32
import org.apache.jmeter.engine.util.ValueReplacer;
33
import org.apache.jmeter.protocol.http.control.HttpMirrorControl;
33
import org.apache.jmeter.protocol.http.control.HttpMirrorControl;
34
import org.apache.jmeter.protocol.http.util.EncoderCache;
34
import org.apache.jmeter.protocol.http.util.EncoderCache;
Lines 121-126 Link Here
121
        testPostRequest_FileUpload(HTTP_SAMPLER2, samplerDefaultEncoding);
121
        testPostRequest_FileUpload(HTTP_SAMPLER2, samplerDefaultEncoding);
122
    }
122
    }
123
123
124
    public void testPostRequest_BodyFromParameterValues() throws Exception {
125
        // Test HTTPSampler
126
        String samplerDefaultEncoding = "ISO-8859-1";
127
        testPostRequest_BodyFromParameterValues(HTTP_SAMPLER, samplerDefaultEncoding);
128
        
129
        // Test HTTPSampler2
130
        samplerDefaultEncoding = "US-ASCII";
131
        testPostRequest_BodyFromParameterValues(HTTP_SAMPLER2, samplerDefaultEncoding);
132
    }
133
124
    public void testGetRequest() throws Exception {
134
    public void testGetRequest() throws Exception {
125
        // Test HTTPSampler
135
        // Test HTTPSampler
126
        testGetRequest(HTTP_SAMPLER);
136
        testGetRequest(HTTP_SAMPLER);
Lines 149-155 Link Here
149
        setupUrl(sampler, contentEncoding);
159
        setupUrl(sampler, contentEncoding);
150
        setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
160
        setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
151
        HTTPSampleResult res = executeSampler(sampler);
161
        HTTPSampleResult res = executeSampler(sampler);
152
        checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue);
162
        checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, false);
153
        
163
        
154
        // Test sending data as ISO-8859-1
164
        // Test sending data as ISO-8859-1
155
        sampler = createHttpSampler(samplerType);
165
        sampler = createHttpSampler(samplerType);
Lines 157-163 Link Here
157
        setupUrl(sampler, contentEncoding);
167
        setupUrl(sampler, contentEncoding);
158
        setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
168
        setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
159
        res = executeSampler(sampler);
169
        res = executeSampler(sampler);
160
        checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue);
170
        checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, false);
161
171
162
        // Test sending data as UTF-8
172
        // Test sending data as UTF-8
163
        sampler = createHttpSampler(samplerType);
173
        sampler = createHttpSampler(samplerType);
Lines 167-174 Link Here
167
        setupUrl(sampler, contentEncoding);
177
        setupUrl(sampler, contentEncoding);
168
        setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
178
        setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
169
        res = executeSampler(sampler);
179
        res = executeSampler(sampler);
170
        checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue);
180
        checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, false);
171
181
182
        // Test sending data as UTF-8, with values that will change when urlencoded
183
        sampler = createHttpSampler(samplerType);
184
        contentEncoding = "UTF-8";
185
        titleValue = "mytitle/=";
186
        descriptionValue = "mydescription   /\\";
187
        setupUrl(sampler, contentEncoding);
188
        setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
189
        res = executeSampler(sampler);
190
        checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, false);
191
192
        // Test sending data as UTF-8, with values that have been urlencoded
193
        sampler = createHttpSampler(samplerType);
194
        contentEncoding = "UTF-8";
195
        titleValue = "mytitle%2F%3D";
196
        descriptionValue = "mydescription+++%2F%5C";
197
        setupUrl(sampler, contentEncoding);
198
        setupFormData(sampler, true, titleField, titleValue, descriptionField, descriptionValue);
199
        res = executeSampler(sampler);
200
        checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, true);
201
202
        // Test sending data as UTF-8, with values similar to __VIEWSTATE parameter that .net uses
203
        sampler = createHttpSampler(samplerType);
204
        contentEncoding = "UTF-8";
205
        titleValue = "/wEPDwULLTE2MzM2OTA0NTYPZBYCAgMPZ/rA+8DZ2dnZ2dnZ2d/GNDar6OshPwdJc=";
206
        descriptionValue = "mydescription";
207
        setupUrl(sampler, contentEncoding);
208
        setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
209
        res = executeSampler(sampler);
210
        checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, false);
211
        
212
        // Test sending data as UTF-8, with values similar to __VIEWSTATE parameter that .net uses,
213
        // with values urlencoded, but the always encode set to false for the arguments
214
        // This is how the HTTP Proxy server adds arguments to the sampler
215
        sampler = createHttpSampler(samplerType);
216
        contentEncoding = "UTF-8";
217
        titleValue = "%2FwEPDwULLTE2MzM2OTA0NTYPZBYCAgMPZ%2FrA%2B8DZ2dnZ2dnZ2d%2FGNDar6OshPwdJc%3D";
218
        descriptionValue = "mydescription";
219
        setupUrl(sampler, contentEncoding);
220
        setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
221
        ((HTTPArgument)sampler.getArguments().getArgument(0)).setAlwaysEncoded(false);
222
        ((HTTPArgument)sampler.getArguments().getArgument(1)).setAlwaysEncoded(false);
223
        res = executeSampler(sampler);
224
        assertFalse(((HTTPArgument)sampler.getArguments().getArgument(0)).isAlwaysEncoded());
225
        assertFalse(((HTTPArgument)sampler.getArguments().getArgument(1)).isAlwaysEncoded());
226
        checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, true);
227
172
        // Test sending data as UTF-8, where user defined variables are used
228
        // Test sending data as UTF-8, where user defined variables are used
173
        // to set the value for form data
229
        // to set the value for form data
174
        JMeterUtils.setLocale(Locale.ENGLISH);
230
        JMeterUtils.setLocale(Locale.ENGLISH);
Lines 192-198 Link Here
192
        res = executeSampler(sampler);
248
        res = executeSampler(sampler);
193
        String expectedTitleValue = "a test\u00c5mytitle\u0153\u20a1\u0115\u00c5";
249
        String expectedTitleValue = "a test\u00c5mytitle\u0153\u20a1\u0115\u00c5";
194
        String expectedDescriptionValue = "mydescription\u0153\u20a1\u0115\u00c5the_end";
250
        String expectedDescriptionValue = "mydescription\u0153\u20a1\u0115\u00c5the_end";
195
        checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, expectedTitleValue, descriptionField, expectedDescriptionValue);
251
        checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, expectedTitleValue, descriptionField, expectedDescriptionValue, false);
196
    }
252
    }
197
253
198
    private void testPostRequest_FormMultipart(int samplerType, String samplerDefaultEncoding) throws Exception {
254
    private void testPostRequest_FormMultipart(int samplerType, String samplerDefaultEncoding) throws Exception {
Lines 234-247 Link Here
234
        // if it was not sent as multipart
290
        // if it was not sent as multipart
235
        sampler = createHttpSampler(samplerType);
291
        sampler = createHttpSampler(samplerType);
236
        contentEncoding = "UTF-8";
292
        contentEncoding = "UTF-8";
237
        titleValue = "mytitle\u0153+\u20a1 \u0115&yes\u00c5";
293
        titleValue = "mytitle/=";
238
        descriptionValue = "mydescription \u0153 \u20a1 \u0115 \u00c5";
294
        descriptionValue = "mydescription   /\\";
239
        setupUrl(sampler, contentEncoding);
295
        setupUrl(sampler, contentEncoding);
240
        setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
296
        setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
241
        sampler.setDoMultipartPost(true);
297
        sampler.setDoMultipartPost(true);
242
        res = executeSampler(sampler);
298
        res = executeSampler(sampler);
243
        checkPostRequestFormMultipart(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue);
299
        checkPostRequestFormMultipart(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue);
244
300
301
        // Test sending data as UTF-8, with values that have been urlencoded
302
        sampler = createHttpSampler(samplerType);
303
        contentEncoding = "UTF-8";
304
        titleValue = "mytitle%2F%3D";
305
        descriptionValue = "mydescription+++%2F%5C";
306
        setupUrl(sampler, contentEncoding);
307
        setupFormData(sampler, true, titleField, titleValue, descriptionField, descriptionValue);
308
        sampler.setDoMultipartPost(true);
309
        res = executeSampler(sampler);
310
        String expectedTitleValue = "mytitle/=";
311
        String expectedDescriptionValue = "mydescription   /\\";
312
        checkPostRequestFormMultipart(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, expectedTitleValue, descriptionField, expectedDescriptionValue);
313
314
        // Test sending data as UTF-8, with values similar to __VIEWSTATE parameter that .net uses
315
        sampler = createHttpSampler(samplerType);
316
        contentEncoding = "UTF-8";
317
        titleValue = "/wEPDwULLTE2MzM2OTA0NTYPZBYCAgMPZ/rA+8DZ2dnZ2dnZ2d/GNDar6OshPwdJc=";
318
        descriptionValue = "mydescription";
319
        setupUrl(sampler, contentEncoding);
320
        setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
321
        sampler.setDoMultipartPost(true);
322
        res = executeSampler(sampler);
323
        checkPostRequestFormMultipart(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue);
324
        
245
        // Test sending data as UTF-8, where user defined variables are used
325
        // Test sending data as UTF-8, where user defined variables are used
246
        // to set the value for form data
326
        // to set the value for form data
247
        JMeterUtils.setLocale(Locale.ENGLISH);
327
        JMeterUtils.setLocale(Locale.ENGLISH);
Lines 264-271 Link Here
264
        // Replace the variables in the sampler
344
        // Replace the variables in the sampler
265
        replacer.replaceValues(sampler);
345
        replacer.replaceValues(sampler);
266
        res = executeSampler(sampler);
346
        res = executeSampler(sampler);
267
        String expectedTitleValue = "a test\u00c5mytitle\u0153\u20a1\u0115\u00c5";
347
        expectedTitleValue = "a test\u00c5mytitle\u0153\u20a1\u0115\u00c5";
268
        String expectedDescriptionValue = "mydescription\u0153\u20a1\u0115\u00c5the_end";
348
        expectedDescriptionValue = "mydescription\u0153\u20a1\u0115\u00c5the_end";
269
        checkPostRequestFormMultipart(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, expectedTitleValue, descriptionField, expectedDescriptionValue);
349
        checkPostRequestFormMultipart(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, expectedTitleValue, descriptionField, expectedDescriptionValue);
270
    }
350
    }
271
351
Lines 303-309 Link Here
303
        res = executeSampler(sampler);
383
        res = executeSampler(sampler);
304
        checkPostRequestFileUpload(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, fileField, temporaryFile, fileMimeType, TEST_FILE_CONTENT);
384
        checkPostRequestFileUpload(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, fileField, temporaryFile, fileMimeType, TEST_FILE_CONTENT);
305
    }
385
    }
306
    
386
387
    private void testPostRequest_BodyFromParameterValues(int samplerType, String samplerDefaultEncoding) throws Exception {
388
        String titleField = "";
389
        String titleValue = "mytitle";
390
        String descriptionField = "";
391
        String descriptionValue = "mydescription";
392
393
        // Test sending data with default encoding
394
        HTTPSamplerBase sampler = createHttpSampler(samplerType);
395
        String contentEncoding = "";
396
        setupUrl(sampler, contentEncoding);
397
        setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
398
        HTTPSampleResult res = executeSampler(sampler);
399
        String expectedPostBody = titleValue + descriptionValue;
400
        checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody);
401
        
402
        // Test sending data as ISO-8859-1
403
        sampler = createHttpSampler(samplerType);
404
        contentEncoding = "ISO-8859-1";
405
        setupUrl(sampler, contentEncoding);
406
        setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
407
        res = executeSampler(sampler);
408
        expectedPostBody = titleValue + descriptionValue;
409
        checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody);
410
411
        // Test sending data as UTF-8
412
        sampler = createHttpSampler(samplerType);
413
        contentEncoding = "UTF-8";
414
        titleValue = "mytitle\u0153\u20a1\u0115\u00c5";
415
        descriptionValue = "mydescription\u0153\u20a1\u0115\u00c5";
416
        setupUrl(sampler, contentEncoding);
417
        setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
418
        res = executeSampler(sampler);
419
        expectedPostBody = titleValue + descriptionValue;
420
        checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody);
421
422
        // Test sending data as UTF-8, with values that will change when urlencoded
423
        sampler = createHttpSampler(samplerType);
424
        contentEncoding = "UTF-8";
425
        titleValue = "mytitle/=";
426
        descriptionValue = "mydescription   /\\";
427
        setupUrl(sampler, contentEncoding);
428
        setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
429
        res = executeSampler(sampler);
430
        expectedPostBody = titleValue + descriptionValue;
431
        checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody);
432
433
        // Test sending data as UTF-8, with values that have been urlencoded
434
        sampler = createHttpSampler(samplerType);
435
        contentEncoding = "UTF-8";
436
        titleValue = "mytitle%2F%3D";
437
        descriptionValue = "mydescription+++%2F%5C";
438
        setupUrl(sampler, contentEncoding);
439
        setupFormData(sampler, true, titleField, titleValue, descriptionField, descriptionValue);
440
        res = executeSampler(sampler);
441
        expectedPostBody = URLDecoder.decode(titleValue, contentEncoding) + URLDecoder.decode(descriptionValue, contentEncoding);
442
        checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody);
443
444
        // Test sending data as UTF-8, with values similar to __VIEWSTATE parameter that .net uses
445
        sampler = createHttpSampler(samplerType);
446
        contentEncoding = "UTF-8";
447
        titleValue = "/wEPDwULLTE2MzM2OTA0NTYPZBYCAgMPZ/rA+8DZ2dnZ2dnZ2d/GNDar6OshPwdJc=";
448
        descriptionValue = "mydescription";
449
        setupUrl(sampler, contentEncoding);
450
        setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
451
        res = executeSampler(sampler);
452
        expectedPostBody = titleValue + descriptionValue;
453
        checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody);
454
        
455
        // Test sending data as UTF-8, with + as part of the value,
456
        // where the value is set in sampler as not urluencoded, but the 
457
        // isalwaysencoded flag of the argument is set to false.
458
        // This mimics the HTTPSamplerBase.addNonEncodedArgument, which the
459
        // Proxy server calls in some cases
460
        sampler = createHttpSampler(samplerType);
461
        contentEncoding = "UTF-8";
462
        titleValue = "mytitle++";
463
        descriptionValue = "mydescription+";
464
        setupUrl(sampler, contentEncoding);
465
        setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
466
        ((HTTPArgument)sampler.getArguments().getArgument(0)).setAlwaysEncoded(false);
467
        ((HTTPArgument)sampler.getArguments().getArgument(1)).setAlwaysEncoded(false);
468
        res = executeSampler(sampler);
469
        expectedPostBody = titleValue + descriptionValue;
470
        checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody);
471
        
472
        // Test sending data as UTF-8, where user defined variables are used
473
        // to set the value for form data
474
        JMeterUtils.setLocale(Locale.ENGLISH);
475
        TestPlan testPlan = new TestPlan();
476
        JMeterVariables vars = new JMeterVariables();
477
        vars.put("title_prefix", "a test\u00c5");
478
        vars.put("description_suffix", "the_end");
479
        JMeterContextService.getContext().setVariables(vars);
480
        JMeterContextService.getContext().setSamplingStarted(true);
481
        ValueReplacer replacer = new ValueReplacer();
482
        replacer.setUserDefinedVariables(testPlan.getUserDefinedVariables());
483
        
484
        sampler = createHttpSampler(samplerType);
485
        contentEncoding = "UTF-8";
486
        titleValue = "${title_prefix}mytitle\u0153\u20a1\u0115\u00c5";
487
        descriptionValue = "mydescription\u0153\u20a1\u0115\u00c5${description_suffix}";
488
        setupUrl(sampler, contentEncoding);
489
        setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
490
        // Replace the variables in the sampler
491
        replacer.replaceValues(sampler);
492
        res = executeSampler(sampler);
493
        String expectedTitleValue = "a test\u00c5mytitle\u0153\u20a1\u0115\u00c5";
494
        String expectedDescriptionValue = "mydescription\u0153\u20a1\u0115\u00c5the_end";
495
        expectedPostBody = expectedTitleValue+ expectedDescriptionValue;
496
        checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody);
497
    }
498
307
    private void testGetRequest(int samplerType) throws Exception {
499
    private void testGetRequest(int samplerType) throws Exception {
308
        // Test sending simple HTTP get
500
        // Test sending simple HTTP get
309
        // Test sending data with default encoding
501
        // Test sending data with default encoding
Lines 348-354 Link Here
348
        sampler.setRunningVersion(true);
540
        sampler.setRunningVersion(true);
349
        URL executedUrl = sampler.getUrl();
541
        URL executedUrl = sampler.getUrl();
350
        sampler.setRunningVersion(false);
542
        sampler.setRunningVersion(false);
351
        checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, titleField, titleValue, descriptionField, descriptionValue);
543
        checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, titleField, titleValue, descriptionField, descriptionValue, false);
352
        
544
        
353
        // Test sending data with ISO-8859-1 encoding
545
        // Test sending data with ISO-8859-1 encoding
354
        sampler = createHttpSampler(samplerType);
546
        sampler = createHttpSampler(samplerType);
Lines 362-368 Link Here
362
        sampler.setRunningVersion(true);
554
        sampler.setRunningVersion(true);
363
        executedUrl = sampler.getUrl();
555
        executedUrl = sampler.getUrl();
364
        sampler.setRunningVersion(false);
556
        sampler.setRunningVersion(false);
365
        checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, titleField, titleValue, descriptionField, descriptionValue);
557
        checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, titleField, titleValue, descriptionField, descriptionValue, false);
366
558
367
        // Test sending data with UTF-8 encoding
559
        // Test sending data with UTF-8 encoding
368
        sampler = createHttpSampler(samplerType);
560
        sampler = createHttpSampler(samplerType);
Lines 376-382 Link Here
376
        sampler.setRunningVersion(true);
568
        sampler.setRunningVersion(true);
377
        executedUrl = sampler.getUrl();
569
        executedUrl = sampler.getUrl();
378
        sampler.setRunningVersion(false);
570
        sampler.setRunningVersion(false);
379
        checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, titleField, titleValue, descriptionField, descriptionValue);
571
        checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, titleField, titleValue, descriptionField, descriptionValue, false);
380
        
572
        
381
        // Test sending data as UTF-8, with values that changes when urlencoded
573
        // Test sending data as UTF-8, with values that changes when urlencoded
382
        sampler = createHttpSampler(samplerType);
574
        sampler = createHttpSampler(samplerType);
Lines 390-397 Link Here
390
        sampler.setRunningVersion(true);
582
        sampler.setRunningVersion(true);
391
        executedUrl = sampler.getUrl();
583
        executedUrl = sampler.getUrl();
392
        sampler.setRunningVersion(false);
584
        sampler.setRunningVersion(false);
393
        checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, titleField, titleValue, descriptionField, descriptionValue);
585
        String expectedTitleValue = "mytitle\u0153%2B\u20a1+\u0115%26yes\u00c5";
586
        String expectedDescriptionValue = "mydescription+\u0153+\u20a1+\u0115+\u00c5";
587
        checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, titleField, titleValue, descriptionField, descriptionValue, false);
394
588
589
        // Test sending data as UTF-8, with values that have been urlencoded
590
        sampler = createHttpSampler(samplerType);
591
        contentEncoding = "UTF-8";
592
        titleValue = "mytitle%2F%3D";
593
        descriptionValue = "mydescription+++%2F%5C";
594
        setupUrl(sampler, contentEncoding);
595
        sampler.setMethod(HTTPSamplerBase.GET);
596
        setupFormData(sampler, true, titleField, titleValue, descriptionField, descriptionValue);
597
        res = executeSampler(sampler);
598
        sampler.setRunningVersion(true);
599
        executedUrl = sampler.getUrl();
600
        sampler.setRunningVersion(false);
601
        checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, titleField, titleValue, descriptionField, descriptionValue, true);
602
395
        // Test sending data as UTF-8, where user defined variables are used
603
        // Test sending data as UTF-8, where user defined variables are used
396
        // to set the value for form data
604
        // to set the value for form data
397
        JMeterUtils.setLocale(Locale.ENGLISH);
605
        JMeterUtils.setLocale(Locale.ENGLISH);
Lines 414-425 Link Here
414
        // Replace the variables in the sampler
622
        // Replace the variables in the sampler
415
        replacer.replaceValues(sampler);
623
        replacer.replaceValues(sampler);
416
        res = executeSampler(sampler);
624
        res = executeSampler(sampler);
417
        String expectedTitleValue = "a test\u00c5mytitle\u0153\u20a1\u0115\u00c5";
625
        expectedTitleValue = "a test\u00c5mytitle\u0153\u20a1\u0115\u00c5";
418
        String expectedDescriptionValue = "mydescription\u0153\u20a1\u0115\u00c5the_end";
626
        expectedDescriptionValue = "mydescription\u0153\u20a1\u0115\u00c5the_end";
419
        sampler.setRunningVersion(true);
627
        sampler.setRunningVersion(true);
420
        executedUrl = sampler.getUrl();
628
        executedUrl = sampler.getUrl();
421
        sampler.setRunningVersion(false);
629
        sampler.setRunningVersion(false);
422
        checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, titleField, expectedTitleValue, descriptionField, expectedDescriptionValue);
630
        checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, titleField, expectedTitleValue, descriptionField, expectedDescriptionValue, false);
423
    }
631
    }
424
    
632
    
425
    private HTTPSampleResult executeSampler(HTTPSamplerBase sampler) {
633
    private HTTPSampleResult executeSampler(HTTPSamplerBase sampler) {
Lines 439-462 Link Here
439
            String titleField,
647
            String titleField,
440
            String titleValue,
648
            String titleValue,
441
            String descriptionField,
649
            String descriptionField,
650
            String descriptionValue,
651
            boolean valuesAlreadyUrlEncoded) throws IOException {
652
        if(contentEncoding == null || contentEncoding.length() == 0) {
653
            contentEncoding = samplerDefaultEncoding;
654
        }
655
        // Check URL
656
        assertEquals(sampler.getUrl(), res.getURL());
657
        String expectedPostBody = null;
658
        if(!valuesAlreadyUrlEncoded) {
659
            String expectedTitle = URLEncoder.encode(titleValue, contentEncoding);
660
            String expectedDescription = URLEncoder.encode(descriptionValue, contentEncoding);
661
            expectedPostBody = titleField + "=" + expectedTitle + "&" + descriptionField + "=" + expectedDescription;
662
        }
663
        else {
664
            expectedPostBody = titleField + "=" + titleValue + "&" + descriptionField + "=" + descriptionValue;
665
        }
666
        // Check the request
667
        checkPostRequestBody(
668
            sampler,
669
            res,
670
            samplerDefaultEncoding,
671
            contentEncoding,
672
            expectedPostBody
673
        );        
674
    }
675
676
    private void checkPostRequestFormMultipart(
677
            HTTPSamplerBase sampler,
678
            HTTPSampleResult res,
679
            String samplerDefaultEncoding,
680
            String contentEncoding,
681
            String titleField,
682
            String titleValue,
683
            String descriptionField,
442
            String descriptionValue) throws IOException {
684
            String descriptionValue) throws IOException {
443
        if(contentEncoding == null || contentEncoding.length() == 0) {
685
        if(contentEncoding == null || contentEncoding.length() == 0) {
444
            contentEncoding = samplerDefaultEncoding;
686
            contentEncoding = samplerDefaultEncoding;
445
        }
687
        }
446
        // Check URL
688
        // Check URL
447
        assertEquals(sampler.getUrl(), res.getURL());
689
        assertEquals(sampler.getUrl(), res.getURL());
448
        String expectedPostBody = titleField + "=" + URLEncoder.encode(titleValue, contentEncoding) + "&" + descriptionField + "=" + URLEncoder.encode(descriptionValue, contentEncoding);
690
        String boundaryString = getBoundaryStringFromContentType(res.getRequestHeaders());
691
        assertNotNull(boundaryString);
692
        byte[] expectedPostBody = createExpectedFormdataOutput(boundaryString, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, true, true);
449
        // Check request headers
693
        // Check request headers
450
        assertTrue(isInRequestHeaders(res.getRequestHeaders(), HTTPSamplerBase.HEADER_CONTENT_TYPE, HTTPSamplerBase.APPLICATION_X_WWW_FORM_URLENCODED));
694
        assertTrue(isInRequestHeaders(res.getRequestHeaders(), HTTPSamplerBase.HEADER_CONTENT_TYPE, "multipart/form-data" + "; boundary=" + boundaryString));
451
        assertTrue(
695
        assertTrue(
452
                isInRequestHeaders(
696
                isInRequestHeaders(
453
                        res.getRequestHeaders(),
697
                        res.getRequestHeaders(),
454
                        HTTPSamplerBase.HEADER_CONTENT_LENGTH,
698
                        HTTPSamplerBase.HEADER_CONTENT_LENGTH,
455
                        Integer.toString(expectedPostBody.getBytes(contentEncoding).length)
699
                        Integer.toString(expectedPostBody.length)
456
                )
700
                )
457
        );
701
        );
458
        // Check post body from the result query string
702
        // Check post body from the result query string
459
        checkArraysHaveSameContent(expectedPostBody.getBytes(contentEncoding), res.getQueryString().getBytes(contentEncoding));
703
        checkArraysHaveSameContent(expectedPostBody, res.getQueryString().getBytes(contentEncoding));
460
704
461
        // Find the data sent to the mirror server, which the mirror server is sending back to us
705
        // Find the data sent to the mirror server, which the mirror server is sending back to us
462
        String dataSentToMirrorServer = new String(res.getResponseData(), contentEncoding);
706
        String dataSentToMirrorServer = new String(res.getResponseData(), contentEncoding);
Lines 472-493 Link Here
472
            fail("No header and body section found");
716
            fail("No header and body section found");
473
        }
717
        }
474
        // Check response headers
718
        // Check response headers
475
        assertTrue(isInRequestHeaders(headersSent, HTTPSamplerBase.HEADER_CONTENT_TYPE, HTTPSamplerBase.APPLICATION_X_WWW_FORM_URLENCODED));
719
        assertTrue(isInRequestHeaders(headersSent, HTTPSamplerBase.HEADER_CONTENT_TYPE, "multipart/form-data" + "; boundary=" + boundaryString));
476
        assertTrue(
720
        assertTrue(
477
                isInRequestHeaders(
721
                isInRequestHeaders(
478
                        headersSent,
722
                        headersSent,
479
                        HTTPSamplerBase.HEADER_CONTENT_LENGTH,
723
                        HTTPSamplerBase.HEADER_CONTENT_LENGTH,
480
                        Integer.toString(expectedPostBody.getBytes(contentEncoding).length)
724
                        Integer.toString(expectedPostBody.length)
481
                )
725
                )
482
        );
726
        );
483
        // Check post body which was sent to the mirror server, and
727
        // Check post body which was sent to the mirror server, and
484
        // sent back by the mirror server
728
        // sent back by the mirror server
485
        checkArraysHaveSameContent(expectedPostBody.getBytes(contentEncoding), bodySent.getBytes(contentEncoding));
729
        checkArraysHaveSameContent(expectedPostBody, bodySent.getBytes(contentEncoding));
486
        // Check method, path and query sent
730
        // Check method, path and query sent
487
        checkMethodPathQuery(headersSent, sampler.getMethod(), sampler.getPath(), null);
731
        checkMethodPathQuery(headersSent, sampler.getMethod(), sampler.getPath(), null);
488
    }
732
    }
489
733
    
490
    private void checkPostRequestFormMultipart(
734
    private void checkPostRequestFileUpload(
491
            HTTPSamplerBase sampler,
735
            HTTPSamplerBase sampler,
492
            HTTPSampleResult res,
736
            HTTPSampleResult res,
493
            String samplerDefaultEncoding,
737
            String samplerDefaultEncoding,
Lines 495-501 Link Here
495
            String titleField,
739
            String titleField,
496
            String titleValue,
740
            String titleValue,
497
            String descriptionField,
741
            String descriptionField,
498
            String descriptionValue) throws IOException {
742
            String descriptionValue,
743
            String fileField,
744
            File fileValue,
745
            String fileMimeType,
746
            byte[] fileContent) throws IOException {
499
        if(contentEncoding == null || contentEncoding.length() == 0) {
747
        if(contentEncoding == null || contentEncoding.length() == 0) {
500
            contentEncoding = samplerDefaultEncoding;
748
            contentEncoding = samplerDefaultEncoding;
501
        }
749
        }
Lines 503-509 Link Here
503
        assertEquals(sampler.getUrl(), res.getURL());
751
        assertEquals(sampler.getUrl(), res.getURL());
504
        String boundaryString = getBoundaryStringFromContentType(res.getRequestHeaders());
752
        String boundaryString = getBoundaryStringFromContentType(res.getRequestHeaders());
505
        assertNotNull(boundaryString);
753
        assertNotNull(boundaryString);
506
        byte[] expectedPostBody = createExpectedFormdataOutput(boundaryString, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, true, true);
754
        byte[] expectedPostBody = createExpectedFormAndUploadOutput(boundaryString, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, fileField, fileValue, fileMimeType, fileContent);
507
        // Check request headers
755
        // Check request headers
508
        assertTrue(isInRequestHeaders(res.getRequestHeaders(), HTTPSamplerBase.HEADER_CONTENT_TYPE, "multipart/form-data" + "; boundary=" + boundaryString));
756
        assertTrue(isInRequestHeaders(res.getRequestHeaders(), HTTPSamplerBase.HEADER_CONTENT_TYPE, "multipart/form-data" + "; boundary=" + boundaryString));
509
        assertTrue(
757
        assertTrue(
Lines 513-520 Link Here
513
                        Integer.toString(expectedPostBody.length)
761
                        Integer.toString(expectedPostBody.length)
514
                )
762
                )
515
        );
763
        );
516
        // Check post body from the result query string
764
        // We cannot check post body from the result query string, since that will not contain
517
        checkArraysHaveSameContent(expectedPostBody, res.getQueryString().getBytes(contentEncoding));
765
        // the actual file content, but placeholder text for file content
766
        //checkArraysHaveSameContent(expectedPostBody, res.getQueryString().getBytes(contentEncoding));
518
767
519
        // Find the data sent to the mirror server, which the mirror server is sending back to us
768
        // Find the data sent to the mirror server, which the mirror server is sending back to us
520
        String dataSentToMirrorServer = new String(res.getResponseData(), contentEncoding);
769
        String dataSentToMirrorServer = new String(res.getResponseData(), contentEncoding);
Lines 540-583 Link Here
540
        );
789
        );
541
        // Check post body which was sent to the mirror server, and
790
        // Check post body which was sent to the mirror server, and
542
        // sent back by the mirror server
791
        // sent back by the mirror server
543
        checkArraysHaveSameContent(expectedPostBody, bodySent.getBytes(contentEncoding));
792
        // We cannot check this merely by getting the body in the contentEncoding,
793
        // since the actual file content is sent binary, without being encoded
794
        //checkArraysHaveSameContent(expectedPostBody, bodySent.getBytes(contentEncoding));
544
        // Check method, path and query sent
795
        // Check method, path and query sent
545
        checkMethodPathQuery(headersSent, sampler.getMethod(), sampler.getPath(), null);
796
        checkMethodPathQuery(headersSent, sampler.getMethod(), sampler.getPath(), null);
546
    }
797
    }
547
    
798
548
    private void checkPostRequestFileUpload(
799
    private void checkPostRequestBody(
549
            HTTPSamplerBase sampler,
800
            HTTPSamplerBase sampler,
550
            HTTPSampleResult res,
801
            HTTPSampleResult res,
551
            String samplerDefaultEncoding,
802
            String samplerDefaultEncoding,
552
            String contentEncoding,
803
            String contentEncoding,
553
            String titleField,
804
            String expectedPostBody) throws IOException {
554
            String titleValue,
555
            String descriptionField,
556
            String descriptionValue,
557
            String fileField,
558
            File fileValue,
559
            String fileMimeType,
560
            byte[] fileContent) throws IOException {
561
        if(contentEncoding == null || contentEncoding.length() == 0) {
805
        if(contentEncoding == null || contentEncoding.length() == 0) {
562
            contentEncoding = samplerDefaultEncoding;
806
            contentEncoding = samplerDefaultEncoding;
563
        }
807
        }
564
        // Check URL
808
        // Check URL
565
        assertEquals(sampler.getUrl(), res.getURL());
809
        assertEquals(sampler.getUrl(), res.getURL());
566
        String boundaryString = getBoundaryStringFromContentType(res.getRequestHeaders());
567
        assertNotNull(boundaryString);
568
        byte[] expectedPostBody = createExpectedFormAndUploadOutput(boundaryString, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, fileField, fileValue, fileMimeType, fileContent);
569
        // Check request headers
810
        // Check request headers
570
        assertTrue(isInRequestHeaders(res.getRequestHeaders(), HTTPSamplerBase.HEADER_CONTENT_TYPE, "multipart/form-data" + "; boundary=" + boundaryString));
811
        assertTrue(isInRequestHeaders(res.getRequestHeaders(), HTTPSamplerBase.HEADER_CONTENT_TYPE, HTTPSamplerBase.APPLICATION_X_WWW_FORM_URLENCODED));
571
        assertTrue(
812
        assertTrue(
572
                isInRequestHeaders(
813
                isInRequestHeaders(
573
                        res.getRequestHeaders(),
814
                        res.getRequestHeaders(),
574
                        HTTPSamplerBase.HEADER_CONTENT_LENGTH,
815
                        HTTPSamplerBase.HEADER_CONTENT_LENGTH,
575
                        Integer.toString(expectedPostBody.length)
816
                        Integer.toString(expectedPostBody.getBytes(contentEncoding).length)
576
                )
817
                )
577
        );
818
        );
578
        // We cannot check post body from the result query string, since that will not contain
819
        // Check post body from the result query string
579
        // the actual file content, but placeholder text for file content
820
        checkArraysHaveSameContent(expectedPostBody.getBytes(contentEncoding), res.getQueryString().getBytes(contentEncoding));
580
        //checkArraysHaveSameContent(expectedPostBody, res.getQueryString().getBytes(contentEncoding));
581
821
582
        // Find the data sent to the mirror server, which the mirror server is sending back to us
822
        // Find the data sent to the mirror server, which the mirror server is sending back to us
583
        String dataSentToMirrorServer = new String(res.getResponseData(), contentEncoding);
823
        String dataSentToMirrorServer = new String(res.getResponseData(), contentEncoding);
Lines 593-611 Link Here
593
            fail("No header and body section found");
833
            fail("No header and body section found");
594
        }
834
        }
595
        // Check response headers
835
        // Check response headers
596
        assertTrue(isInRequestHeaders(headersSent, HTTPSamplerBase.HEADER_CONTENT_TYPE, "multipart/form-data" + "; boundary=" + boundaryString));
836
        assertTrue(isInRequestHeaders(headersSent, HTTPSamplerBase.HEADER_CONTENT_TYPE, HTTPSamplerBase.APPLICATION_X_WWW_FORM_URLENCODED));
597
        assertTrue(
837
        assertTrue(
598
                isInRequestHeaders(
838
                isInRequestHeaders(
599
                        headersSent,
839
                        headersSent,
600
                        HTTPSamplerBase.HEADER_CONTENT_LENGTH,
840
                        HTTPSamplerBase.HEADER_CONTENT_LENGTH,
601
                        Integer.toString(expectedPostBody.length)
841
                        Integer.toString(expectedPostBody.getBytes(contentEncoding).length)
602
                )
842
                )
603
        );
843
        );
604
        // Check post body which was sent to the mirror server, and
844
        // Check post body which was sent to the mirror server, and
605
        // sent back by the mirror server
845
        // sent back by the mirror server
606
        // We cannot check this merely by getting the body in the contentEncoding,
846
        checkArraysHaveSameContent(expectedPostBody.getBytes(contentEncoding), bodySent.getBytes(contentEncoding));
607
        // since the actual file content is sent binary, without being encoded
608
        //checkArraysHaveSameContent(expectedPostBody, bodySent.getBytes(contentEncoding));
609
        // Check method, path and query sent
847
        // Check method, path and query sent
610
        checkMethodPathQuery(headersSent, sampler.getMethod(), sampler.getPath(), null);
848
        checkMethodPathQuery(headersSent, sampler.getMethod(), sampler.getPath(), null);
611
    }
849
    }
Lines 648-654 Link Here
648
            String titleField,
886
            String titleField,
649
            String titleValue,
887
            String titleValue,
650
            String descriptionField,
888
            String descriptionField,
651
            String descriptionValue) throws IOException {
889
            String descriptionValue,
890
            boolean valuesAlreadyUrlEncoded) throws IOException {
652
        if(contentEncoding == null || contentEncoding.length() == 0) {
891
        if(contentEncoding == null || contentEncoding.length() == 0) {
653
            contentEncoding = EncoderCache.URL_ARGUMENT_ENCODING;
892
            contentEncoding = EncoderCache.URL_ARGUMENT_ENCODING;
654
        }
893
        }
Lines 658-664 Link Here
658
        assertEquals(sampler.getMethod(), res.getHTTPMethod());
897
        assertEquals(sampler.getMethod(), res.getHTTPMethod());
659
        // Cannot check the query string of the result, because the mirror server
898
        // Cannot check the query string of the result, because the mirror server
660
        // replies without including query string in URL
899
        // replies without including query string in URL
661
        String expectedQueryString = titleField + "=" + URLEncoder.encode(titleValue, contentEncoding) + "&" + descriptionField + "=" + URLEncoder.encode(descriptionValue, contentEncoding);
900
        
901
        String expectedQueryString = null;
902
        if(!valuesAlreadyUrlEncoded) {
903
            String expectedTitle = URLEncoder.encode(titleValue, contentEncoding);
904
            String expectedDescription = URLEncoder.encode(descriptionValue, contentEncoding);
905
            expectedQueryString = titleField + "=" + expectedTitle + "&" + descriptionField + "=" + expectedDescription;
906
        }
907
        else {
908
            expectedQueryString = titleField + "=" + titleValue + "&" + descriptionField + "=" + descriptionValue;
909
        }
662
910
663
        // Find the data sent to the mirror server, which the mirror server is sending back to us
911
        // Find the data sent to the mirror server, which the mirror server is sending back to us
664
        String dataSentToMirrorServer = new String(res.getResponseData(), EncoderCache.URL_ARGUMENT_ENCODING);
912
        String dataSentToMirrorServer = new String(res.getResponseData(), EncoderCache.URL_ARGUMENT_ENCODING);
Lines 782-793 Link Here
782
     * @param httpSampler
1030
     * @param httpSampler
783
     */
1031
     */
784
    private void setupFormData(HTTPSamplerBase httpSampler, boolean isEncoded, String titleField, String titleValue, String descriptionField, String descriptionValue) {
1032
    private void setupFormData(HTTPSamplerBase httpSampler, boolean isEncoded, String titleField, String titleValue, String descriptionField, String descriptionValue) {
785
        Arguments args = new Arguments();
1033
        if(isEncoded) {
786
        HTTPArgument argument1 = new HTTPArgument(titleField, titleValue, isEncoded);
1034
            httpSampler.addEncodedArgument(titleField, titleValue);
787
        HTTPArgument argument2 = new HTTPArgument(descriptionField, descriptionValue, isEncoded);
1035
            httpSampler.addEncodedArgument(descriptionField, descriptionValue);
788
        args.addArgument(argument1);
1036
        }
789
        args.addArgument(argument2);
1037
        else {
790
        httpSampler.setArguments(args);
1038
            httpSampler.addArgument(titleField, titleValue);
1039
            httpSampler.addArgument(descriptionField, descriptionValue);
1040
        }
791
    }
1041
    }
792
1042
793
    /**
1043
    /**
(-)C:/Documents and Settings/alf.hogemark/workspace/JMeter 2.2 official_2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java (-1 / +34 lines)
Lines 361-368 Link Here
361
                    PropertyIterator args = getArguments().iterator();
361
                    PropertyIterator args = getArguments().iterator();
362
                    while (args.hasNext()) {
362
                    while (args.hasNext()) {
363
                        HTTPArgument arg = (HTTPArgument) args.next().getObjectValue();
363
                        HTTPArgument arg = (HTTPArgument) args.next().getObjectValue();
364
                        post.addParameter(arg.getName(), arg.getValue());
364
                        // The HTTPClient always urlencodes both name and value,
365
                        // so if the argument is already encoded, we have to decode
366
                        // it before adding it to the post request
367
                        String parameterName = arg.getName();
368
                        String parameterValue = arg.getValue();
369
                        if(!arg.isAlwaysEncoded()) {
370
                            // The value is already encoded by the user
371
                            // Must decode the value now, so that when the
372
                            // httpclient encodes it, we end up with the same value
373
                            // as the user had entered.
374
                            String urlContentEncoding = contentEncoding;
375
                            if(urlContentEncoding == null || urlContentEncoding.length() == 0) {
376
                                // Use the default encoding for urls 
377
                                urlContentEncoding = EncoderCache.URL_ARGUMENT_ENCODING;
378
                            }
379
                            parameterName = URLDecoder.decode(parameterName, urlContentEncoding);
380
                            parameterValue = URLDecoder.decode(parameterValue, urlContentEncoding);
381
                        }
382
                        // Add the parameter, httpclient will urlencode it
383
                        post.addParameter(parameterName, parameterValue);
365
                    }
384
                    }
385
                    
386
/*
387
                    // Alternative implementation, to make sure that HTTPSampler and HTTPSampler2
388
                    // sends the same post body.
389
                     
390
                    // Only include the content char set in the content-type header if it is not
391
                    // an APPLICATION_X_WWW_FORM_URLENCODED content type
392
                    String contentCharSet = null;
393
                    if(!post.getRequestHeader(HEADER_CONTENT_TYPE).getValue().equals(APPLICATION_X_WWW_FORM_URLENCODED)) {
394
                        contentCharSet = post.getRequestCharSet();
395
                    }
396
                    StringRequestEntity requestEntity = new StringRequestEntity(getQueryString(contentEncoding), post.getRequestHeader(HEADER_CONTENT_TYPE).getValue(), contentCharSet);
397
                    post.setRequestEntity(requestEntity);
398
*/                    
366
                }
399
                }
367
                else {
400
                else {
368
                    // Just append all the parameter values, and use that as the post body
401
                    // Just append all the parameter values, and use that as the post body

Return to bug 42156