Author: sebb
Date: Wed Apr 18 13:09:15 2007
New Revision: 530144

URL: http://svn.apache.org/viewvc?view=rev&rev=530144
Log:
Bug 42139 - Add more unit tests to TestHTTPSamplersAgainstHttpMirrorServer 

Modified:
    
jakarta/jmeter/branches/rel-2-2/test/src/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplersAgainstHttpMirrorServer.java

Modified: 
jakarta/jmeter/branches/rel-2-2/test/src/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplersAgainstHttpMirrorServer.java
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/test/src/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplersAgainstHttpMirrorServer.java?view=diff&rev=530144&r1=530143&r2=530144
==============================================================================
--- 
jakarta/jmeter/branches/rel-2-2/test/src/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplersAgainstHttpMirrorServer.java
 (original)
+++ 
jakarta/jmeter/branches/rel-2-2/test/src/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplersAgainstHttpMirrorServer.java
 Wed Apr 18 13:09:15 2007
@@ -24,11 +24,11 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
 import java.net.URLEncoder;
 import java.net.URL;
 import java.util.Locale;
 
-import org.apache.jmeter.config.Arguments;
 import org.apache.jmeter.engine.util.ValueReplacer;
 import org.apache.jmeter.protocol.http.control.HttpMirrorControl;
 import org.apache.jmeter.protocol.http.util.EncoderCache;
@@ -121,6 +121,16 @@
         testPostRequest_FileUpload(HTTP_SAMPLER2, samplerDefaultEncoding);
     }
 
+    public void testPostRequest_BodyFromParameterValues() throws Exception {
+        // Test HTTPSampler
+        String samplerDefaultEncoding = "ISO-8859-1";
+        testPostRequest_BodyFromParameterValues(HTTP_SAMPLER, 
samplerDefaultEncoding);
+        
+        // Test HTTPSampler2
+        samplerDefaultEncoding = "US-ASCII";
+        testPostRequest_BodyFromParameterValues(HTTP_SAMPLER2, 
samplerDefaultEncoding);
+    }
+
     public void testGetRequest() throws Exception {
         // Test HTTPSampler
         testGetRequest(HTTP_SAMPLER);
@@ -149,7 +159,7 @@
         setupUrl(sampler, contentEncoding);
         setupFormData(sampler, false, titleField, titleValue, 
descriptionField, descriptionValue);
         HTTPSampleResult res = executeSampler(sampler);
-        checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, 
contentEncoding, titleField, titleValue, descriptionField, descriptionValue);
+        checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, 
contentEncoding, titleField, titleValue, descriptionField, descriptionValue, 
false);
         
         // Test sending data as ISO-8859-1
         sampler = createHttpSampler(samplerType);
@@ -157,7 +167,7 @@
         setupUrl(sampler, contentEncoding);
         setupFormData(sampler, false, titleField, titleValue, 
descriptionField, descriptionValue);
         res = executeSampler(sampler);
-        checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, 
contentEncoding, titleField, titleValue, descriptionField, descriptionValue);
+        checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, 
contentEncoding, titleField, titleValue, descriptionField, descriptionValue, 
false);
 
         // Test sending data as UTF-8
         sampler = createHttpSampler(samplerType);
@@ -167,7 +177,37 @@
         setupUrl(sampler, contentEncoding);
         setupFormData(sampler, false, titleField, titleValue, 
descriptionField, descriptionValue);
         res = executeSampler(sampler);
-        checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, 
contentEncoding, titleField, titleValue, descriptionField, descriptionValue);
+        checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, 
contentEncoding, titleField, titleValue, descriptionField, descriptionValue, 
false);
+
+        // 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);
+        res = executeSampler(sampler);
+        checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, 
contentEncoding, titleField, titleValue, descriptionField, descriptionValue, 
false);
+
+        // 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, true, titleField, titleValue, descriptionField, 
descriptionValue);
+        res = executeSampler(sampler);
+        checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, 
contentEncoding, titleField, titleValue, descriptionField, descriptionValue, 
true);
+
+        // 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);
+        res = executeSampler(sampler);
+        checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, 
contentEncoding, titleField, titleValue, descriptionField, descriptionValue, 
false);
 
         // Test sending data as UTF-8, where user defined variables are used
         // to set the value for form data
@@ -192,7 +232,7 @@
         res = executeSampler(sampler);
         String expectedTitleValue = "a 
test\u00c5mytitle\u0153\u20a1\u0115\u00c5";
         String expectedDescriptionValue = 
"mydescription\u0153\u20a1\u0115\u00c5the_end";
-        checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, 
contentEncoding, titleField, expectedTitleValue, descriptionField, 
expectedDescriptionValue);
+        checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, 
contentEncoding, titleField, expectedTitleValue, descriptionField, 
expectedDescriptionValue, false);
     }
 
     private void testPostRequest_FormMultipart(int samplerType, String 
samplerDefaultEncoding) throws Exception {
@@ -234,14 +274,38 @@
         // if it was not sent as multipart
         sampler = createHttpSampler(samplerType);
         contentEncoding = "UTF-8";
-        titleValue = "mytitle\u0153+\u20a1 \u0115&yes\u00c5";
-        descriptionValue = "mydescription \u0153 \u20a1 \u0115 \u00c5";
+        titleValue = "mytitle/=";
+        descriptionValue = "mydescription   /\\";
         setupUrl(sampler, contentEncoding);
         setupFormData(sampler, false, titleField, titleValue, 
descriptionField, descriptionValue);
         sampler.setDoMultipartPost(true);
         res = executeSampler(sampler);
         checkPostRequestFormMultipart(sampler, res, samplerDefaultEncoding, 
contentEncoding, titleField, titleValue, descriptionField, descriptionValue);
 
+        // 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, true, titleField, titleValue, descriptionField, 
descriptionValue);
+        sampler.setDoMultipartPost(true);
+        res = executeSampler(sampler);
+        String expectedTitleValue = "mytitle/=";
+        String expectedDescriptionValue = "mydescription   /\\";
+        checkPostRequestFormMultipart(sampler, res, samplerDefaultEncoding, 
contentEncoding, titleField, expectedTitleValue, descriptionField, 
expectedDescriptionValue);
+
+        // 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);
+        sampler.setDoMultipartPost(true);
+        res = executeSampler(sampler);
+        checkPostRequestFormMultipart(sampler, res, samplerDefaultEncoding, 
contentEncoding, titleField, titleValue, descriptionField, descriptionValue);
+        
         // Test sending data as UTF-8, where user defined variables are used
         // to set the value for form data
         JMeterUtils.setLocale(Locale.ENGLISH);
@@ -264,8 +328,8 @@
         // Replace the variables in the sampler
         replacer.replaceValues(sampler);
         res = executeSampler(sampler);
-        String expectedTitleValue = "a 
test\u00c5mytitle\u0153\u20a1\u0115\u00c5";
-        String expectedDescriptionValue = 
"mydescription\u0153\u20a1\u0115\u00c5the_end";
+        expectedTitleValue = "a test\u00c5mytitle\u0153\u20a1\u0115\u00c5";
+        expectedDescriptionValue = 
"mydescription\u0153\u20a1\u0115\u00c5the_end";
         checkPostRequestFormMultipart(sampler, res, samplerDefaultEncoding, 
contentEncoding, titleField, expectedTitleValue, descriptionField, 
expectedDescriptionValue);
     }
 
@@ -303,7 +367,119 @@
         res = executeSampler(sampler);
         checkPostRequestFileUpload(sampler, res, samplerDefaultEncoding, 
contentEncoding, titleField, titleValue, descriptionField, descriptionValue, 
fileField, temporaryFile, fileMimeType, TEST_FILE_CONTENT);
     }
-    
+
+    private void testPostRequest_BodyFromParameterValues(int samplerType, 
String samplerDefaultEncoding) throws Exception {
+        String titleField = "";
+        String titleValue = "mytitle";
+        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);
+        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);
+        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\u0153\u20a1\u0115\u00c5";
+        descriptionValue = "mydescription\u0153\u20a1\u0115\u00c5";
+        setupUrl(sampler, contentEncoding);
+        setupFormData(sampler, false, titleField, titleValue, 
descriptionField, descriptionValue);
+        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);
+        res = executeSampler(sampler);
+        expectedPostBody = titleValue + descriptionValue;
+        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, true, titleField, titleValue, descriptionField, 
descriptionValue);
+        res = executeSampler(sampler);
+        expectedPostBody = URLDecoder.decode(titleValue, contentEncoding) + 
URLDecoder.decode(descriptionValue, contentEncoding);
+        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);
+        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 HTTPSamplerBase.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\u00c5");
+        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\u0153\u20a1\u0115\u00c5";
+        descriptionValue = 
"mydescription\u0153\u20a1\u0115\u00c5${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\u00c5mytitle\u0153\u20a1\u0115\u00c5";
+        String expectedDescriptionValue = 
"mydescription\u0153\u20a1\u0115\u00c5the_end";
+        expectedPostBody = expectedTitleValue+ expectedDescriptionValue;
+        checkPostRequestBody(sampler, res, samplerDefaultEncoding, 
contentEncoding, expectedPostBody);
+    }
+
     private void testGetRequest(int samplerType) throws Exception {
         // Test sending simple HTTP get
         // Test sending data with default encoding
@@ -348,7 +524,7 @@
         sampler.setRunningVersion(true);
         URL executedUrl = sampler.getUrl();
         sampler.setRunningVersion(false);
-        checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, 
titleField, titleValue, descriptionField, descriptionValue);
+        checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, 
titleField, titleValue, descriptionField, descriptionValue, false);
         
         // Test sending data with ISO-8859-1 encoding
         sampler = createHttpSampler(samplerType);
@@ -362,7 +538,7 @@
         sampler.setRunningVersion(true);
         executedUrl = sampler.getUrl();
         sampler.setRunningVersion(false);
-        checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, 
titleField, titleValue, descriptionField, descriptionValue);
+        checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, 
titleField, titleValue, descriptionField, descriptionValue, false);
 
         // Test sending data with UTF-8 encoding
         sampler = createHttpSampler(samplerType);
@@ -376,7 +552,7 @@
         sampler.setRunningVersion(true);
         executedUrl = sampler.getUrl();
         sampler.setRunningVersion(false);
-        checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, 
titleField, titleValue, descriptionField, descriptionValue);
+        checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, 
titleField, titleValue, descriptionField, descriptionValue, false);
         
         // Test sending data as UTF-8, with values that changes when urlencoded
         sampler = createHttpSampler(samplerType);
@@ -390,7 +566,23 @@
         sampler.setRunningVersion(true);
         executedUrl = sampler.getUrl();
         sampler.setRunningVersion(false);
-        checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, 
titleField, titleValue, descriptionField, descriptionValue);
+        String expectedTitleValue = 
"mytitle\u0153%2B\u20a1+\u0115%26yes\u00c5";
+        String expectedDescriptionValue = 
"mydescription+\u0153+\u20a1+\u0115+\u00c5";
+        checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, 
titleField, titleValue, descriptionField, descriptionValue, false);
+
+        // 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);
+        sampler.setMethod(HTTPSamplerBase.GET);
+        setupFormData(sampler, true, titleField, titleValue, descriptionField, 
descriptionValue);
+        res = executeSampler(sampler);
+        sampler.setRunningVersion(true);
+        executedUrl = sampler.getUrl();
+        sampler.setRunningVersion(false);
+        checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, 
titleField, titleValue, descriptionField, descriptionValue, true);
 
         // Test sending data as UTF-8, where user defined variables are used
         // to set the value for form data
@@ -414,12 +606,12 @@
         // Replace the variables in the sampler
         replacer.replaceValues(sampler);
         res = executeSampler(sampler);
-        String expectedTitleValue = "a 
test\u00c5mytitle\u0153\u20a1\u0115\u00c5";
-        String expectedDescriptionValue = 
"mydescription\u0153\u20a1\u0115\u00c5the_end";
+        expectedTitleValue = "a test\u00c5mytitle\u0153\u20a1\u0115\u00c5";
+        expectedDescriptionValue = 
"mydescription\u0153\u20a1\u0115\u00c5the_end";
         sampler.setRunningVersion(true);
         executedUrl = sampler.getUrl();
         sampler.setRunningVersion(false);
-        checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, 
titleField, expectedTitleValue, descriptionField, expectedDescriptionValue);
+        checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, 
titleField, expectedTitleValue, descriptionField, expectedDescriptionValue, 
false);
     }
     
     private HTTPSampleResult executeSampler(HTTPSamplerBase sampler) {
@@ -439,24 +631,60 @@
             String titleField,
             String titleValue,
             String descriptionField,
+            String descriptionValue,
+            boolean valuesAlreadyUrlEncoded) throws IOException {
+        if(contentEncoding == null || contentEncoding.length() == 0) {
+            contentEncoding = samplerDefaultEncoding;
+        }
+        // Check URL
+        assertEquals(sampler.getUrl(), res.getURL());
+        String expectedPostBody = null;
+        if(!valuesAlreadyUrlEncoded) {
+            String expectedTitle = URLEncoder.encode(titleValue, 
contentEncoding);
+            String expectedDescription = URLEncoder.encode(descriptionValue, 
contentEncoding);
+            expectedPostBody = titleField + "=" + expectedTitle + "&" + 
descriptionField + "=" + expectedDescription;
+        }
+        else {
+            expectedPostBody = titleField + "=" + titleValue + "&" + 
descriptionField + "=" + descriptionValue;
+        }
+        // Check the request
+        checkPostRequestBody(
+            sampler,
+            res,
+            samplerDefaultEncoding,
+            contentEncoding,
+            expectedPostBody
+        );        
+    }
+
+    private void checkPostRequestFormMultipart(
+            HTTPSamplerBase sampler,
+            HTTPSampleResult res,
+            String samplerDefaultEncoding,
+            String contentEncoding,
+            String titleField,
+            String titleValue,
+            String descriptionField,
             String descriptionValue) throws IOException {
         if(contentEncoding == null || contentEncoding.length() == 0) {
             contentEncoding = samplerDefaultEncoding;
         }
         // Check URL
         assertEquals(sampler.getUrl(), res.getURL());
-        String expectedPostBody = titleField + "=" + 
URLEncoder.encode(titleValue, contentEncoding) + "&" + descriptionField + "=" + 
URLEncoder.encode(descriptionValue, contentEncoding);
+        String boundaryString = 
getBoundaryStringFromContentType(res.getRequestHeaders());
+        assertNotNull(boundaryString);
+        byte[] expectedPostBody = createExpectedFormdataOutput(boundaryString, 
contentEncoding, titleField, titleValue, descriptionField, descriptionValue, 
true, true);
         // Check request headers
-        assertTrue(isInRequestHeaders(res.getRequestHeaders(), 
HTTPSamplerBase.HEADER_CONTENT_TYPE, 
HTTPSamplerBase.APPLICATION_X_WWW_FORM_URLENCODED));
+        assertTrue(isInRequestHeaders(res.getRequestHeaders(), 
HTTPSamplerBase.HEADER_CONTENT_TYPE, "multipart/form-data" + "; boundary=" + 
boundaryString));
         assertTrue(
                 isInRequestHeaders(
                         res.getRequestHeaders(),
                         HTTPSamplerBase.HEADER_CONTENT_LENGTH,
-                        
Integer.toString(expectedPostBody.getBytes(contentEncoding).length)
+                        Integer.toString(expectedPostBody.length)
                 )
         );
         // Check post body from the result query string
-        checkArraysHaveSameContent(expectedPostBody.getBytes(contentEncoding), 
res.getQueryString().getBytes(contentEncoding));
+        checkArraysHaveSameContent(expectedPostBody, 
res.getQueryString().getBytes(contentEncoding));
 
         // Find the data sent to the mirror server, which the mirror server is 
sending back to us
         String dataSentToMirrorServer = new String(res.getResponseData(), 
contentEncoding);
@@ -472,22 +700,22 @@
             fail("No header and body section found");
         }
         // Check response headers
-        assertTrue(isInRequestHeaders(headersSent, 
HTTPSamplerBase.HEADER_CONTENT_TYPE, 
HTTPSamplerBase.APPLICATION_X_WWW_FORM_URLENCODED));
+        assertTrue(isInRequestHeaders(headersSent, 
HTTPSamplerBase.HEADER_CONTENT_TYPE, "multipart/form-data" + "; boundary=" + 
boundaryString));
         assertTrue(
                 isInRequestHeaders(
                         headersSent,
                         HTTPSamplerBase.HEADER_CONTENT_LENGTH,
-                        
Integer.toString(expectedPostBody.getBytes(contentEncoding).length)
+                        Integer.toString(expectedPostBody.length)
                 )
         );
         // Check post body which was sent to the mirror server, and
         // sent back by the mirror server
-        checkArraysHaveSameContent(expectedPostBody.getBytes(contentEncoding), 
bodySent.getBytes(contentEncoding));
+        checkArraysHaveSameContent(expectedPostBody, 
bodySent.getBytes(contentEncoding));
         // Check method, path and query sent
         checkMethodPathQuery(headersSent, sampler.getMethod(), 
sampler.getPath(), null);
     }
-
-    private void checkPostRequestFormMultipart(
+    
+    private void checkPostRequestFileUpload(
             HTTPSamplerBase sampler,
             HTTPSampleResult res,
             String samplerDefaultEncoding,
@@ -495,7 +723,11 @@
             String titleField,
             String titleValue,
             String descriptionField,
-            String descriptionValue) throws IOException {
+            String descriptionValue,
+            String fileField,
+            File fileValue,
+            String fileMimeType,
+            byte[] fileContent) throws IOException {
         if(contentEncoding == null || contentEncoding.length() == 0) {
             contentEncoding = samplerDefaultEncoding;
         }
@@ -503,7 +735,7 @@
         assertEquals(sampler.getUrl(), res.getURL());
         String boundaryString = 
getBoundaryStringFromContentType(res.getRequestHeaders());
         assertNotNull(boundaryString);
-        byte[] expectedPostBody = createExpectedFormdataOutput(boundaryString, 
contentEncoding, titleField, titleValue, descriptionField, descriptionValue, 
true, true);
+        byte[] expectedPostBody = 
createExpectedFormAndUploadOutput(boundaryString, contentEncoding, titleField, 
titleValue, descriptionField, descriptionValue, fileField, fileValue, 
fileMimeType, fileContent);
         // Check request headers
         assertTrue(isInRequestHeaders(res.getRequestHeaders(), 
HTTPSamplerBase.HEADER_CONTENT_TYPE, "multipart/form-data" + "; boundary=" + 
boundaryString));
         assertTrue(
@@ -513,8 +745,9 @@
                         Integer.toString(expectedPostBody.length)
                 )
         );
-        // Check post body from the result query string
-        checkArraysHaveSameContent(expectedPostBody, 
res.getQueryString().getBytes(contentEncoding));
+        // We cannot check post body from the result query string, since that 
will not contain
+        // the actual file content, but placeholder text for file content
+        //checkArraysHaveSameContent(expectedPostBody, 
res.getQueryString().getBytes(contentEncoding));
 
         // Find the data sent to the mirror server, which the mirror server is 
sending back to us
         String dataSentToMirrorServer = new String(res.getResponseData(), 
contentEncoding);
@@ -540,44 +773,35 @@
         );
         // Check post body which was sent to the mirror server, and
         // sent back by the mirror server
-        checkArraysHaveSameContent(expectedPostBody, 
bodySent.getBytes(contentEncoding));
+        // We cannot check this merely by getting the body in the 
contentEncoding,
+        // since the actual file content is sent binary, without being encoded
+        //checkArraysHaveSameContent(expectedPostBody, 
bodySent.getBytes(contentEncoding));
         // Check method, path and query sent
         checkMethodPathQuery(headersSent, sampler.getMethod(), 
sampler.getPath(), null);
     }
-    
-    private void checkPostRequestFileUpload(
+
+    private void checkPostRequestBody(
             HTTPSamplerBase sampler,
             HTTPSampleResult res,
             String samplerDefaultEncoding,
             String contentEncoding,
-            String titleField,
-            String titleValue,
-            String descriptionField,
-            String descriptionValue,
-            String fileField,
-            File fileValue,
-            String fileMimeType,
-            byte[] fileContent) throws IOException {
+            String expectedPostBody) throws IOException {
         if(contentEncoding == null || contentEncoding.length() == 0) {
             contentEncoding = samplerDefaultEncoding;
         }
         // Check URL
         assertEquals(sampler.getUrl(), res.getURL());
-        String boundaryString = 
getBoundaryStringFromContentType(res.getRequestHeaders());
-        assertNotNull(boundaryString);
-        byte[] expectedPostBody = 
createExpectedFormAndUploadOutput(boundaryString, contentEncoding, titleField, 
titleValue, descriptionField, descriptionValue, fileField, fileValue, 
fileMimeType, fileContent);
         // Check request headers
-        assertTrue(isInRequestHeaders(res.getRequestHeaders(), 
HTTPSamplerBase.HEADER_CONTENT_TYPE, "multipart/form-data" + "; boundary=" + 
boundaryString));
+        assertTrue(isInRequestHeaders(res.getRequestHeaders(), 
HTTPSamplerBase.HEADER_CONTENT_TYPE, 
HTTPSamplerBase.APPLICATION_X_WWW_FORM_URLENCODED));
         assertTrue(
                 isInRequestHeaders(
                         res.getRequestHeaders(),
                         HTTPSamplerBase.HEADER_CONTENT_LENGTH,
-                        Integer.toString(expectedPostBody.length)
+                        
Integer.toString(expectedPostBody.getBytes(contentEncoding).length)
                 )
         );
-        // We cannot check post body from the result query string, since that 
will not contain
-        // the actual file content, but placeholder text for file content
-        //checkArraysHaveSameContent(expectedPostBody, 
res.getQueryString().getBytes(contentEncoding));
+        // Check post body from the result query string
+        checkArraysHaveSameContent(expectedPostBody.getBytes(contentEncoding), 
res.getQueryString().getBytes(contentEncoding));
 
         // Find the data sent to the mirror server, which the mirror server is 
sending back to us
         String dataSentToMirrorServer = new String(res.getResponseData(), 
contentEncoding);
@@ -593,19 +817,17 @@
             fail("No header and body section found");
         }
         // Check response headers
-        assertTrue(isInRequestHeaders(headersSent, 
HTTPSamplerBase.HEADER_CONTENT_TYPE, "multipart/form-data" + "; boundary=" + 
boundaryString));
+        assertTrue(isInRequestHeaders(headersSent, 
HTTPSamplerBase.HEADER_CONTENT_TYPE, 
HTTPSamplerBase.APPLICATION_X_WWW_FORM_URLENCODED));
         assertTrue(
                 isInRequestHeaders(
                         headersSent,
                         HTTPSamplerBase.HEADER_CONTENT_LENGTH,
-                        Integer.toString(expectedPostBody.length)
+                        
Integer.toString(expectedPostBody.getBytes(contentEncoding).length)
                 )
         );
         // Check post body which was sent to the mirror server, and
         // sent back by the mirror server
-        // We cannot check this merely by getting the body in the 
contentEncoding,
-        // since the actual file content is sent binary, without being encoded
-        //checkArraysHaveSameContent(expectedPostBody, 
bodySent.getBytes(contentEncoding));
+        checkArraysHaveSameContent(expectedPostBody.getBytes(contentEncoding), 
bodySent.getBytes(contentEncoding));
         // Check method, path and query sent
         checkMethodPathQuery(headersSent, sampler.getMethod(), 
sampler.getPath(), null);
     }
@@ -648,7 +870,8 @@
             String titleField,
             String titleValue,
             String descriptionField,
-            String descriptionValue) throws IOException {
+            String descriptionValue,
+            boolean valuesAlreadyUrlEncoded) throws IOException {
         if(contentEncoding == null || contentEncoding.length() == 0) {
             contentEncoding = EncoderCache.URL_ARGUMENT_ENCODING;
         }
@@ -658,7 +881,16 @@
         assertEquals(sampler.getMethod(), res.getHTTPMethod());
         // Cannot check the query string of the result, because the mirror 
server
         // replies without including query string in URL
-        String expectedQueryString = titleField + "=" + 
URLEncoder.encode(titleValue, contentEncoding) + "&" + descriptionField + "=" + 
URLEncoder.encode(descriptionValue, contentEncoding);
+        
+        String expectedQueryString = null;
+        if(!valuesAlreadyUrlEncoded) {
+            String expectedTitle = URLEncoder.encode(titleValue, 
contentEncoding);
+            String expectedDescription = URLEncoder.encode(descriptionValue, 
contentEncoding);
+            expectedQueryString = titleField + "=" + expectedTitle + "&" + 
descriptionField + "=" + expectedDescription;
+        }
+        else {
+            expectedQueryString = titleField + "=" + titleValue + "&" + 
descriptionField + "=" + descriptionValue;
+        }
 
         // Find the data sent to the mirror server, which the mirror server is 
sending back to us
         String dataSentToMirrorServer = new String(res.getResponseData(), 
EncoderCache.URL_ARGUMENT_ENCODING);
@@ -782,12 +1014,14 @@
      * @param httpSampler
      */
     private void setupFormData(HTTPSamplerBase httpSampler, boolean isEncoded, 
String titleField, String titleValue, String descriptionField, String 
descriptionValue) {
-        Arguments args = new Arguments();
-        HTTPArgument argument1 = new HTTPArgument(titleField, titleValue, 
isEncoded);
-        HTTPArgument argument2 = new HTTPArgument(descriptionField, 
descriptionValue, isEncoded);
-        args.addArgument(argument1);
-        args.addArgument(argument2);
-        httpSampler.setArguments(args);
+        if(isEncoded) {
+            httpSampler.addEncodedArgument(titleField, titleValue);
+            httpSampler.addEncodedArgument(descriptionField, descriptionValue);
+        }
+        else {
+            httpSampler.addArgument(titleField, titleValue);
+            httpSampler.addArgument(descriptionField, descriptionValue);
+        }
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to