File path: /jakarta-jmeter-2.3.2/test/src/org/apache/jmeter/protocol/http/proxy/TestHttpRequestHdr.java | File path: /jakarta-jmeter-2.3.2/test/src/org/apache/jmeter/protocol/http/proxy/TestHttpRequestHdr.java | |||
Method name: void testPostRequestEncodings()
|
Method name: void testGetRequestEncodings()
|
|||
Number of AST nodes: 40 | Number of AST nodes: 37 | |||
1 | String url = "http://localhost/matrix.html";↵ | 1 | String url = "http://localhost/matrix.html";↵ | |
2 | // A HTTP POST request, with encoding not known↵ | 2 | // A HTTP GET request, with encoding not known↵ | |
3 | String contentEncoding = "";↵ | 3 | String contentEncoding = "";↵ | |
4 | String param1Value = "yes";↵ | 4 | String param1Value = "yes";↵ | |
5 | String param2Value = "0+5 -\u00c5%C3%85";↵ | 5 | String param2Value = "0+5 -\u00c5\uc385%C3%85";↵ | |
6 | String param2ValueEncoded = URLEncoder.encode(param2Value,"UTF-8");↵ | 6 | String param2ValueEncoded = URLEncoder.encode(param2Value,"UTF-8");↵ | |
7 | String postBody = "param1=" + param1Value + "¶m2=" + param2ValueEncoded + "\r\n"; ↵ | 7 | String ↵ | |
8 | String testPostRequest = ↵ | 8 | testGetRequest = ↵ | |
9 | "POST " + url + " HTTP/1.1\r\n"↵ | 9 | "GET " + url↵ | |
10 | + "Content-type: "↵ | |||
11 | + HTTPSamplerBase.APPLICATION_X_WWW_FORM_URLENCODED + "\r\n"↵ | |||
12 | + "Content-length: " + getBodyLength(postBody, contentEncoding) + "\r\n"↵ | |||
13 | + "\r\n"↵ | |||
14 | + postBody;↵ | |||
15 | ↵ | |||
10 | + "?param1=" + param1Value + "¶m2=" + param2ValueEncoded + " "↵ | |||
11 | + "HTTP/1.1\r\n\r\n";↵ | |||
16 | // Use null for url and contentEncoding, to simulate that HttpRequestHdr do not↵ | 12 | // Use null for url and contentEncoding, to simulate that HttpRequestHdr do not↵ | |
17 | // know the encoding for the page↵ | 13 | // know the encoding for the page↵ | |
18 | HTTPSamplerBase s = getSamplerForRequest(null, testPostRequest, null);↵ | 14 | HTTPSamplerBase s = getSamplerForRequest(null, testGetRequest, null);↵ | |
19 | assertEquals(HTTPSamplerBase.POST, s.getMethod());↵ | 15 | assertEquals(HTTPSamplerBase.GET, s.getMethod());↵ | |
20 | assertEquals(contentEncoding, s.getContentEncoding());↵ | 16 | assertEquals(contentEncoding, s.getContentEncoding());↵ | |
21 | // Check arguments↵ | 17 | // Check arguments↵ | |
22 | Arguments arguments = s.getArguments();↵ | 18 | Arguments arguments = s.getArguments();↵ | |
23 | assertEquals(2, arguments.getArgumentCount());↵ | 19 | assertEquals(2, arguments.getArgumentCount());↵ | |
24 | checkArgument((HTTPArgument)arguments.getArgument(0), "param1", param1Value, param1Value, contentEncoding, false);↵ | 20 | checkArgument((HTTPArgument)arguments.getArgument(0), "param1", param1Value, param1Value, contentEncoding, false);↵ | |
25 | // When the encoding is not known, the argument will get the encoded value, and the "encode?" set to false↵ | 21 | // When the encoding is not known, the argument will get the encoded value, and the "encode?" set to false↵ | |
26 | checkArgument((HTTPArgument)arguments.getArgument(1), "param2", param2ValueEncoded, param2ValueEncoded, contentEncoding, false);↵ | 22 | checkArgument((HTTPArgument)arguments.getArgument(1), "param2", param2ValueEncoded, param2ValueEncoded, contentEncoding, false);↵ | |
27 | // A HTTP POST request, with UTF-8 encoding↵ | 23 | // A HTTP GET request, with UTF-8 encoding↵ | |
28 | contentEncoding = "UTF-8";↵ | 24 | contentEncoding = "UTF-8";↵ | |
29 | param1Value = "yes";↵ | 25 | param1Value = "yes";↵ | |
30 | param2Value = "0+5 -\u007c\u2aa1\u266a\u0153\u20a1\u0115\u0364\u00c5\u2052\uc385%C3%85";↵ | 26 | param2Value = "0+5 -\u007c\u2aa1\u266a\u0153\u20a1\u0115\u0364\u00c5\u2052\uc385%C3%85";↵ | |
31 | param2ValueEncoded = URLEncoder.encode(param2Value, contentEncoding);↵ | 27 | param2ValueEncoded = URLEncoder.encode(param2Value, contentEncoding);↵ | |
32 | postBody = "param1=" + param1Value + "¶m2=" + param2ValueEncoded + "\r\n"; ↵ | 28 | ↵ | |
33 | testPostRequest = ↵ | 29 | testGetRequest = ↵ | |
34 | "POST " + url + " HTTP/1.1\r\n"↵ | 30 | "GET " + url↵ | |
35 | + "Content-type: "↵ | |||
36 | + HTTPSamplerBase.APPLICATION_X_WWW_FORM_URLENCODED + "\r\n"↵ | |||
37 | + "Content-length: " + getBodyLength(postBody, contentEncoding) + "\r\n"↵ | |||
38 | + "\r\n"↵ | |||
39 | + postBody;↵ | |||
31 | + "?param1=" + param1Value + "¶m2=" + param2ValueEncoded + " "↵ | |||
32 | + "HTTP/1.1\r\n\r\n";↵ | |||
40 | s = getSamplerForRequest(url, testPostRequest, contentEncoding);↵ | 33 | s = getSamplerForRequest(url, testGetRequest, contentEncoding);↵ | |
41 | assertEquals(HTTPSamplerBase.POST, s.getMethod());↵ | 34 | assertEquals(HTTPSamplerBase.GET, s.getMethod());↵ | |
42 | assertEquals(contentEncoding, s.getContentEncoding());↵ | 35 | assertEquals(contentEncoding, s.getContentEncoding());↵ | |
43 | // Check arguments↵ | 36 | // Check arguments↵ | |
44 | arguments = s.getArguments();↵ | 37 | arguments = s.getArguments();↵ | |
45 | assertEquals(2, arguments.getArgumentCount());↵ | 38 | assertEquals(2, arguments.getArgumentCount());↵ | |
46 | checkArgument((HTTPArgument)arguments.getArgument(0), "param1", param1Value, param1Value, contentEncoding, false);↵ | 39 | checkArgument((HTTPArgument)arguments.getArgument(0), "param1", param1Value, param1Value, contentEncoding, false);↵ | |
47 | checkArgument((HTTPArgument)arguments.getArgument(1), "param2", param2Value, param2ValueEncoded, contentEncoding, true);↵ | 40 | checkArgument((HTTPArgument)arguments.getArgument(1), "param2", param2Value, param2ValueEncoded, contentEncoding, true);↵ | |
48 | // A HTTP POST request, with ISO-8859-1 encoding↵ | 41 | // A HTTP GET request, with ISO-8859-1 encoding↵ | |
49 | contentEncoding = "ISO-8859-1";↵ | 42 | contentEncoding = "ISO-8859-1";↵ | |
50 | param1Value = "yes";↵ | 43 | param1Value = "yes";↵ | |
51 | param2Value = "0+5 -\u00c5%C3%85";↵ | 44 | param2Value = "0+5 -\u00c5%C3%85";↵ | |
52 | param2ValueEncoded = URLEncoder.encode(param2Value, contentEncoding);↵ | 45 | param2ValueEncoded = URLEncoder.encode(param2Value, contentEncoding);↵ | |
53 | postBody = "param1=" + param1Value + "¶m2=" + param2ValueEncoded + "\r\n"; ↵ | 46 | ↵ | |
54 | testPostRequest = ↵ | 47 | testGetRequest = ↵ | |
55 | "POST " + url + " HTTP/1.1\r\n"↵ | 48 | "GET " + url↵ | |
56 | + "Content-type: "↵ | |||
57 | + HTTPSamplerBase.APPLICATION_X_WWW_FORM_URLENCODED + "\r\n"↵ | |||
58 | + "Content-length: " + getBodyLength(postBody, contentEncoding) + "\r\n"↵ | |||
59 | + "\r\n"↵ | |||
60 | + postBody;↵ | |||
49 | + "?param1=" + param1Value + "¶m2=" + param2ValueEncoded + " "↵ | |||
50 | + "HTTP/1.1\r\n\r\n";↵ | |||
61 | s = getSamplerForRequest(url, testPostRequest, contentEncoding);↵ | 51 | s = getSamplerForRequest(url, testGetRequest, contentEncoding);↵ | |
62 | assertEquals(HTTPSamplerBase.POST, s.getMethod());↵ | 52 | assertEquals(HTTPSamplerBase.GET, s.getMethod());↵ | |
63 | assertEquals(contentEncoding, s.getContentEncoding());↵ | 53 | assertEquals(contentEncoding, s.getContentEncoding());↵ | |
64 | // Check arguments↵ | 54 | // Check arguments↵ | |
65 | arguments = s.getArguments();↵ | 55 | arguments = s.getArguments();↵ | |
66 | assertEquals(2, arguments.getArgumentCount());↵ | 56 | assertEquals(2, arguments.getArgumentCount());↵ | |
67 | checkArgument((HTTPArgument)arguments.getArgument(0), "param1", param1Value, param1Value, contentEncoding, false);↵ | 57 | checkArgument((HTTPArgument)arguments.getArgument(0), "param1", param1Value, param1Value, contentEncoding, false);↵ | |
68 | checkArgument((HTTPArgument)arguments.getArgument(1), "param2", param2Value, param2ValueEncoded, contentEncoding, true); | 58 |
| |
See real code fragment | See real code fragment |
Number of common nesting structure subtrees | 1 |
Number of refactorable cases | 0 |
Number of non-refactorable cases | 1 |
Time elapsed for finding largest common nesting structure subtrees (ms) | 0.0 |
Clones location | Clones are declared in the same class |
Number of node comparisons | 503 |
Number of mapped statements | 37 |
Number of unmapped statements in the first code fragment | 3 |
Number of unmapped statements in the second code fragment | 0 |
Time elapsed for statement mapping (ms) | 0.0 |
Clone type | Type 3 |
ID | Statement | ID | Statement | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | String url = "http://localhost/matrix.html"; | 1 | String url = "http://localhost/matrix.html"; | |||||||||||||||||||
2 | String contentEncoding = ""; | 2 | String contentEncoding = ""; | |||||||||||||||||||
3 | String param1Value = "yes"; | 3 | String param1Value = "yes"; | |||||||||||||||||||
4 | String param2Value = "0+5 -\u00c5%C3%85"; |
| 4 | String param2Value = "0+5 -\u00c5\uc385%C3%85"; | ||||||||||||||||||
5 | String param2ValueEncoded = URLEncoder.encode(param2Value, "UTF-8"); | 5 | String param2ValueEncoded = URLEncoder.encode(param2Value, "UTF-8"); | |||||||||||||||||||
6 | String postBody = "param1=" + param1Value + "¶m2=" + param2ValueEncoded + "\r\n"; |
| | |||||||||||||||||||
7 | String testPostRequest = "POST " + url + " HTTP/1.1\r\n" + "Content-type: " + HTTPSamplerBase.APPLICATION_X_WWW_FORM_URLENCODED + "\r\n" + "Content-length: " + getBodyLength(postBody, contentEncoding) + "\r\n" + "\r\n" + postBody; |
| 6 | String testGetRequest = "GET " + url + "?param1=" + param1Value + "¶m2=" + param2ValueEncoded + " " + "HTTP/1.1\r\n\r\n"; | ||||||||||||||||||
8 | HTTPSamplerBase s = getSamplerForRequest(null, testPostRequest, null); |
| 7 | HTTPSamplerBase s = getSamplerForRequest(null, testGetRequest, null); | ||||||||||||||||||
9 | assertEquals(HTTPSamplerBase.POST, s.getMethod()); |
| 8 | assertEquals(HTTPSamplerBase.GET, s.getMethod()); | ||||||||||||||||||
10 | assertEquals(contentEncoding, s.getContentEncoding()); | 9 | assertEquals(contentEncoding, s.getContentEncoding()); | |||||||||||||||||||
11 | Arguments arguments = s.getArguments(); | 10 | Arguments arguments = s.getArguments(); | |||||||||||||||||||
12 | assertEquals(2, arguments.getArgumentCount()); | 11 | assertEquals(2, arguments.getArgumentCount()); | |||||||||||||||||||
13 | checkArgument((HTTPArgument)arguments.getArgument(0), "param1", param1Value, param1Value, contentEncoding, false); | 12 | checkArgument((HTTPArgument)arguments.getArgument(0), "param1", param1Value, param1Value, contentEncoding, false); | |||||||||||||||||||
14 | checkArgument((HTTPArgument)arguments.getArgument(1), "param2", param2ValueEncoded, param2ValueEncoded, contentEncoding, false); | 13 | checkArgument((HTTPArgument)arguments.getArgument(1), "param2", param2ValueEncoded, param2ValueEncoded, contentEncoding, false); | |||||||||||||||||||
15 | contentEncoding = "UTF-8"; | 14 | contentEncoding = "UTF-8"; | |||||||||||||||||||
16 | param1Value = "yes"; | 15 | param1Value = "yes"; | |||||||||||||||||||
17 | param2Value = "0+5 -\u007c\u2aa1\u266a\u0153\u20a1\u0115\u0364\u00c5\u2052\uc385%C3%85"; | 16 | param2Value = "0+5 -\u007c\u2aa1\u266a\u0153\u20a1\u0115\u0364\u00c5\u2052\uc385%C3%85"; | |||||||||||||||||||
18 | param2ValueEncoded = URLEncoder.encode(param2Value, contentEncoding); | 17 | param2ValueEncoded = URLEncoder.encode(param2Value, contentEncoding); | |||||||||||||||||||
19 | postBody = "param1=" + param1Value + "¶m2=" + param2ValueEncoded + "\r\n"; |
| | |||||||||||||||||||
20 | testPostRequest = "POST " + url + " HTTP/1.1\r\n" + "Content-type: " + HTTPSamplerBase.APPLICATION_X_WWW_FORM_URLENCODED + "\r\n" + "Content-length: " + getBodyLength(postBody, contentEncoding) + "\r\n" + "\r\n" + postBody; |
| 18 | testGetRequest = "GET " + url + "?param1=" + param1Value + "¶m2=" + param2ValueEncoded + " " + "HTTP/1.1\r\n\r\n"; | ||||||||||||||||||
21 | s = getSamplerForRequest(url, testPostRequest, contentEncoding); |
| 19 | s = getSamplerForRequest(url, testGetRequest, contentEncoding); | ||||||||||||||||||
22 | assertEquals(HTTPSamplerBase.POST, s.getMethod()); |
| 20 | assertEquals(HTTPSamplerBase.GET, s.getMethod()); | ||||||||||||||||||
23 | assertEquals(contentEncoding, s.getContentEncoding()); | 21 | assertEquals(contentEncoding, s.getContentEncoding()); | |||||||||||||||||||
24 | arguments = s.getArguments(); | 22 | arguments = s.getArguments(); | |||||||||||||||||||
25 | assertEquals(2, arguments.getArgumentCount()); | 23 | assertEquals(2, arguments.getArgumentCount()); | |||||||||||||||||||
26 | checkArgument((HTTPArgument)arguments.getArgument(0), "param1", param1Value, param1Value, contentEncoding, false); | 24 | checkArgument((HTTPArgument)arguments.getArgument(0), "param1", param1Value, param1Value, contentEncoding, false); | |||||||||||||||||||
27 | checkArgument((HTTPArgument)arguments.getArgument(1), "param2", param2Value, param2ValueEncoded, contentEncoding, true); | 25 | checkArgument((HTTPArgument)arguments.getArgument(1), "param2", param2Value, param2ValueEncoded, contentEncoding, true); | |||||||||||||||||||
28 | contentEncoding = "ISO-8859-1"; | 26 | contentEncoding = "ISO-8859-1"; | |||||||||||||||||||
29 | param1Value = "yes"; | 27 | param1Value = "yes"; | |||||||||||||||||||
30 | param2Value = "0+5 -\u00c5%C3%85"; | 28 | param2Value = "0+5 -\u00c5%C3%85"; | |||||||||||||||||||
31 | param2ValueEncoded = URLEncoder.encode(param2Value, contentEncoding); | 29 | param2ValueEncoded = URLEncoder.encode(param2Value, contentEncoding); | |||||||||||||||||||
32 | postBody = "param1=" + param1Value + "¶m2=" + param2ValueEncoded + "\r\n"; |
| | |||||||||||||||||||
33 | testPostRequest = "POST " + url + " HTTP/1.1\r\n" + "Content-type: " + HTTPSamplerBase.APPLICATION_X_WWW_FORM_URLENCODED + "\r\n" + "Content-length: " + getBodyLength(postBody, contentEncoding) + "\r\n" + "\r\n" + postBody; |
| 30 | testGetRequest = "GET " + url + "?param1=" + param1Value + "¶m2=" + param2ValueEncoded + " " + "HTTP/1.1\r\n\r\n"; | ||||||||||||||||||
34 | s = getSamplerForRequest(url, testPostRequest, contentEncoding); |
| 31 | s = getSamplerForRequest(url, testGetRequest, contentEncoding); | ||||||||||||||||||
35 | assertEquals(HTTPSamplerBase.POST, s.getMethod()); |
| 32 | assertEquals(HTTPSamplerBase.GET, s.getMethod()); | ||||||||||||||||||
36 | assertEquals(contentEncoding, s.getContentEncoding()); | 33 | assertEquals(contentEncoding, s.getContentEncoding()); | |||||||||||||||||||
37 | arguments = s.getArguments(); | 34 | arguments = s.getArguments(); | |||||||||||||||||||
38 | assertEquals(2, arguments.getArgumentCount()); | 35 | assertEquals(2, arguments.getArgumentCount()); | |||||||||||||||||||
39 | checkArgument((HTTPArgument)arguments.getArgument(0), "param1", param1Value, param1Value, contentEncoding, false); | 36 | checkArgument((HTTPArgument)arguments.getArgument(0), "param1", param1Value, param1Value, contentEncoding, false); | |||||||||||||||||||
40 | checkArgument((HTTPArgument)arguments.getArgument(1), "param2", param2Value, param2ValueEncoded, contentEncoding, true); | 37 | checkArgument((HTTPArgument)arguments.getArgument(1), "param2", param2Value, param2ValueEncoded, contentEncoding, true); |
Row | Violation |
---|---|
1 | Unmatched statement String postBody="param1=" + param1Value + "¶m2="+ param2ValueEncoded+ "\r\n"; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
2 | Expression "POST " + url + " HTTP/1.1\r\n"+ "Content-type: "+ HTTPSamplerBase.APPLICATION_X_WWW_FORM_URLENCODED+ "\r\n"+ "Content-length: "+ getBodyLength(postBody,contentEncoding)+ "\r\n"+ "\r\n"+ postBody cannot be parameterized, because it has dependencies to/from statements that will be extracted |
3 | Expression "GET " + url + "?param1="+ param1Value+ "¶m2="+ param2ValueEncoded+ " "+ "HTTP/1.1\r\n\r\n" cannot be parameterized, because it has dependencies to/from statements that will be extracted |
4 | Unmatched statement postBody="param1=" + param1Value + "¶m2="+ param2ValueEncoded+ "\r\n"; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
5 | Expression "POST " + url + " HTTP/1.1\r\n"+ "Content-type: "+ HTTPSamplerBase.APPLICATION_X_WWW_FORM_URLENCODED+ "\r\n"+ "Content-length: "+ getBodyLength(postBody,contentEncoding)+ "\r\n"+ "\r\n"+ postBody cannot be parameterized, because it has dependencies to/from statements that will be extracted |
6 | Expression "GET " + url + "?param1="+ param1Value+ "¶m2="+ param2ValueEncoded+ " "+ "HTTP/1.1\r\n\r\n" cannot be parameterized, because it has dependencies to/from statements that will be extracted |
7 | Unmatched statement postBody="param1=" + param1Value + "¶m2="+ param2ValueEncoded+ "\r\n"; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
8 | Expression "POST " + url + " HTTP/1.1\r\n"+ "Content-type: "+ HTTPSamplerBase.APPLICATION_X_WWW_FORM_URLENCODED+ "\r\n"+ "Content-length: "+ getBodyLength(postBody,contentEncoding)+ "\r\n"+ "\r\n"+ postBody cannot be parameterized, because it has dependencies to/from statements that will be extracted |
9 | Expression "GET " + url + "?param1="+ param1Value+ "¶m2="+ param2ValueEncoded+ " "+ "HTTP/1.1\r\n\r\n" cannot be parameterized, because it has dependencies to/from statements that will be extracted |
10 | Clone fragment #1 returns variables param1Value, param2ValueEncoded , while Clone fragment #2 returns variables |