01: /*
02: * ========================================================================
03: *
04: * Copyright 2001-2003 The Apache Software Foundation.
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: *
18: * ========================================================================
19: */
20: package org.apache.cactus.sample.servlet.unit;
21:
22: import org.apache.cactus.ServletTestCase;
23: import org.apache.cactus.WebRequest;
24:
25: /**
26: * Test passing HTTP parameters to the server side.
27: *
28: * @version $Id: TestHttpParameters.java 238816 2004-02-29 16:36:46Z vmassol $
29: */
30: public class TestHttpParameters extends ServletTestCase {
31: /**
32: * Verify that multi value parameters can be sent in the
33: * <code>beingXXX()</code> method to the server redirector.
34: *
35: * @param theRequest the request object that serves to initialize the
36: * HTTP connection to the server redirector.
37: */
38: public void beginMultiValueParameters(WebRequest theRequest) {
39: theRequest.addParameter("multivalue", "value 1");
40: theRequest.addParameter("multivalue", "value 2");
41: }
42:
43: /**
44: * Verify that multi value parameters can be sent in the
45: * <code>beingXXX()</code> method to the server redirector.
46: */
47: public void testMultiValueParameters() {
48: String[] values = request.getParameterValues("multivalue");
49:
50: if (values[0].equals("value 1")) {
51: assertEquals("value 2", values[1]);
52: } else if (values[0].equals("value 2")) {
53: assertEquals("value 1", values[1]);
54: } else {
55: fail("Shoud have returned a vector with the "
56: + "values \"value 1\" and \"value 2\"");
57: }
58: }
59:
60: //-------------------------------------------------------------------------
61:
62: /**
63: * Verify we can set and retrieve several parameters.
64: *
65: * @param theRequest the request object that serves to initialize the
66: * HTTP connection to the server redirector.
67: */
68: public void beginSeveralParameters(WebRequest theRequest) {
69: theRequest.addParameter("PostParameter1", "EMPLOYEE0145",
70: WebRequest.POST_METHOD);
71: theRequest.addParameter("PostParameter2", "W",
72: WebRequest.GET_METHOD);
73: theRequest.addParameter("PostParameter3", "07/08/2002",
74: WebRequest.POST_METHOD);
75: theRequest.addParameter("PostParameter4",
76: "/tas/ViewSchedule.esp", WebRequest.GET_METHOD);
77: }
78:
79: /**
80: * Verify we can set and retrieve several parameters.
81: */
82: public void testSeveralParameters() {
83: assertEquals("parameter4", "/tas/ViewSchedule.esp", request
84: .getParameter("PostParameter4"));
85: assertEquals("parameter1", "EMPLOYEE0145", request
86: .getParameter("PostParameter1"));
87: assertEquals("parameter2", "W", request
88: .getParameter("PostParameter2"));
89: assertEquals("parameter3", "07/08/2002", request
90: .getParameter("PostParameter3"));
91: }
92:
93: }
|