01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: package org.apache.jmeter.protocol.http.util;
20:
21: import junit.framework.TestCase;
22:
23: import org.apache.jmeter.config.Arguments;
24: import org.apache.jmeter.testelement.property.CollectionProperty;
25:
26: public class TestHTTPArgument extends TestCase {
27: public TestHTTPArgument(String name) {
28: super (name);
29: }
30:
31: public void testCloning() throws Exception {
32: HTTPArgument arg = new HTTPArgument("name.?", "value_ here");
33: assertEquals("name.?", arg.getName());
34: assertEquals("value_ here", arg.getValue());
35: assertEquals("name.%3F", arg.getEncodedName());
36: assertEquals("value_+here", arg.getEncodedValue());
37: HTTPArgument clone = (HTTPArgument) arg.clone();
38: assertEquals("name.%3F", clone.getEncodedName());
39: assertEquals("value_+here", clone.getEncodedValue());
40: assertEquals("name.?", clone.getName());
41: assertEquals("value_ here", clone.getValue());
42: }
43:
44: public void testConversion() throws Exception {
45: Arguments args = new Arguments();
46: args.addArgument("name.?", "value_ here");
47: args.addArgument("name$of property", "value_.+");
48: HTTPArgument.convertArgumentsToHTTP(args);
49: CollectionProperty argList = args.getArguments();
50: HTTPArgument httpArg = (HTTPArgument) argList.get(0)
51: .getObjectValue();
52: assertEquals("name.%3F", httpArg.getEncodedName());
53: assertEquals("value_+here", httpArg.getEncodedValue());
54: httpArg = (HTTPArgument) argList.get(1).getObjectValue();
55: assertEquals("name%24of+property", httpArg.getEncodedName());
56: assertEquals("value_.%2B", httpArg.getEncodedValue());
57: }
58:
59: public void testEncoding() throws Exception {
60: HTTPArgument arg;
61: arg = new HTTPArgument("name.?", "value_ here", false);
62: assertEquals("name.?", arg.getName());
63: assertEquals("value_ here", arg.getValue());
64: assertEquals("name.%3F", arg.getEncodedName());
65: assertEquals("value_+here", arg.getEncodedValue());
66: arg = new HTTPArgument("name.?", "value_ here", true);
67: assertEquals("name.?", arg.getName());
68: assertEquals("value_ here", arg.getValue());
69: // TODO - should these be enabled?
70: // i.e. Does it make sense that name/value are decoded if alreadyEncoded is true?
71: //assertEquals("name.?", arg.getEncodedName());
72: //assertEquals("value_ here", arg.getEncodedValue());
73: }
74: }
|