001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.jmeter.protocol.http.sampler;
020:
021: import org.apache.jmeter.config.Argument;
022: import org.apache.jmeter.config.Arguments;
023:
024: import junit.framework.TestCase;
025:
026: public class TestHTTPSamplers extends TestCase {
027:
028: public TestHTTPSamplers(String arg0) {
029: super (arg0);
030: }
031:
032: // Parse arguments singly
033: public void testParseArguments() {
034: HTTPSamplerBase sampler = new HTTPNullSampler();
035: Arguments args;
036: Argument arg;
037:
038: args = sampler.getArguments();
039: assertEquals(0, args.getArgumentCount());
040:
041: sampler.parseArguments("");
042: args = sampler.getArguments();
043: assertEquals(0, args.getArgumentCount());
044:
045: sampler.parseArguments("name1");
046: args = sampler.getArguments();
047: assertEquals(1, args.getArgumentCount());
048: arg = args.getArgument(0);
049: assertEquals("name1", arg.getName());
050: assertEquals("", arg.getMetaData());
051: assertEquals("", arg.getValue());
052:
053: sampler.parseArguments("name2=");
054: args = sampler.getArguments();
055: assertEquals(2, args.getArgumentCount());
056: arg = args.getArgument(1);
057: assertEquals("name2", arg.getName());
058: assertEquals("=", arg.getMetaData());
059: assertEquals("", arg.getValue());
060:
061: sampler.parseArguments("name3=value3");
062: args = sampler.getArguments();
063: assertEquals(3, args.getArgumentCount());
064: arg = args.getArgument(2);
065: assertEquals("name3", arg.getName());
066: assertEquals("=", arg.getMetaData());
067: assertEquals("value3", arg.getValue());
068:
069: }
070:
071: // Parse arguments all at once
072: public void testParseArguments2() {
073: HTTPSamplerBase sampler = new HTTPNullSampler();
074: Arguments args;
075: Argument arg;
076:
077: args = sampler.getArguments();
078: assertEquals(0, args.getArgumentCount());
079:
080: sampler.parseArguments("&name1&name2=&name3=value3");
081: args = sampler.getArguments();
082: assertEquals(3, args.getArgumentCount());
083:
084: arg = args.getArgument(0);
085: assertEquals("name1", arg.getName());
086: assertEquals("", arg.getMetaData());
087: assertEquals("", arg.getValue());
088:
089: arg = args.getArgument(1);
090: assertEquals("name2", arg.getName());
091: assertEquals("=", arg.getMetaData());
092: assertEquals("", arg.getValue());
093:
094: arg = args.getArgument(2);
095: assertEquals("name3", arg.getName());
096: assertEquals("=", arg.getMetaData());
097: assertEquals("value3", arg.getValue());
098:
099: }
100:
101: public void testArgumentWithoutEquals() throws Exception {
102: HTTPSamplerBase sampler = new HTTPNullSampler();
103: sampler.setProtocol("http");
104: sampler.setMethod(HTTPSamplerBase.GET);
105: sampler.setPath("/index.html?pear");
106: sampler.setDomain("www.apache.org");
107: assertEquals("http://www.apache.org/index.html?pear", sampler
108: .getUrl().toString());
109: }
110:
111: public void testMakingUrl() throws Exception {
112: HTTPSamplerBase config = new HTTPNullSampler();
113: config.setProtocol("http");
114: config.setMethod(HTTPSamplerBase.GET);
115: config.addArgument("param1", "value1");
116: config.setPath("/index.html");
117: config.setDomain("www.apache.org");
118: assertEquals("http://www.apache.org/index.html?param1=value1",
119: config.getUrl().toString());
120: }
121:
122: public void testMakingUrl2() throws Exception {
123: HTTPSamplerBase config = new HTTPNullSampler();
124: config.setProtocol("http");
125: config.setMethod(HTTPSamplerBase.GET);
126: config.addArgument("param1", "value1");
127: config.setPath("/index.html?p1=p2");
128: config.setDomain("www.apache.org");
129: assertEquals(
130: "http://www.apache.org/index.html?param1=value1&p1=p2",
131: config.getUrl().toString());
132: }
133:
134: public void testMakingUrl3() throws Exception {
135: HTTPSamplerBase config = new HTTPNullSampler();
136: config.setProtocol("http");
137: config.setMethod(HTTPSamplerBase.POST);
138: config.addArgument("param1", "value1");
139: config.setPath("/index.html?p1=p2");
140: config.setDomain("www.apache.org");
141: assertEquals("http://www.apache.org/index.html?p1=p2", config
142: .getUrl().toString());
143: }
144:
145: // test cases for making Url, and exercise method
146: // addArgument(String name,String value,String metadata)
147:
148: public void testMakingUrl4() throws Exception {
149: HTTPSamplerBase config = new HTTPNullSampler();
150: config.setProtocol("http");
151: config.setMethod(HTTPSamplerBase.GET);
152: config.addArgument("param1", "value1", "=");
153: config.setPath("/index.html");
154: config.setDomain("www.apache.org");
155: assertEquals("http://www.apache.org/index.html?param1=value1",
156: config.getUrl().toString());
157: }
158:
159: public void testMakingUrl5() throws Exception {
160: HTTPSamplerBase config = new HTTPNullSampler();
161: config.setProtocol("http");
162: config.setMethod(HTTPSamplerBase.GET);
163: config.addArgument("param1", "", "=");
164: config.setPath("/index.html");
165: config.setDomain("www.apache.org");
166: assertEquals("http://www.apache.org/index.html?param1=", config
167: .getUrl().toString());
168: }
169:
170: public void testMakingUrl6() throws Exception {
171: HTTPSamplerBase config = new HTTPNullSampler();
172: config.setProtocol("http");
173: config.setMethod(HTTPSamplerBase.GET);
174: config.addArgument("param1", "", "");
175: config.setPath("/index.html");
176: config.setDomain("www.apache.org");
177: assertEquals("http://www.apache.org/index.html?param1", config
178: .getUrl().toString());
179: }
180:
181: // test cases for making Url, and exercise method
182: // parseArguments(String queryString)
183:
184: public void testMakingUrl7() throws Exception {
185: HTTPSamplerBase config = new HTTPNullSampler();
186: config.setProtocol("http");
187: config.setMethod(HTTPSamplerBase.GET);
188: config.parseArguments("param1=value1");
189: config.setPath("/index.html");
190: config.setDomain("www.apache.org");
191: assertEquals("http://www.apache.org/index.html?param1=value1",
192: config.getUrl().toString());
193: }
194:
195: public void testMakingUrl8() throws Exception {
196: HTTPSamplerBase config = new HTTPNullSampler();
197: config.setProtocol("http");
198: config.setMethod(HTTPSamplerBase.GET);
199: config.parseArguments("param1=");
200: config.setPath("/index.html");
201: config.setDomain("www.apache.org");
202: assertEquals("http://www.apache.org/index.html?param1=", config
203: .getUrl().toString());
204: }
205:
206: public void testMakingUrl9() throws Exception {
207: HTTPSamplerBase config = new HTTPNullSampler();
208: config.setProtocol("http");
209: config.setMethod(HTTPSamplerBase.GET);
210: config.parseArguments("param1");
211: config.setPath("/index.html");
212: config.setDomain("www.apache.org");
213: assertEquals("http://www.apache.org/index.html?param1", config
214: .getUrl().toString());
215: }
216:
217: public void testMakingUrl10() throws Exception {
218: HTTPSamplerBase config = new HTTPNullSampler();
219: config.setProtocol("http");
220: config.setMethod(HTTPSamplerBase.GET);
221: config.parseArguments("");
222: config.setPath("/index.html");
223: config.setDomain("www.apache.org");
224: assertEquals("http://www.apache.org/index.html", config
225: .getUrl().toString());
226: }
227: }
|