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