KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > sample > servlet > unit > TestHttpParameters


1 /*
2  * ========================================================================
3  *
4  * Copyright 2001-2003 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
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,v 1.3 2004/02/29 16:36:44 vmassol Exp $
29  */

30 public class TestHttpParameters extends ServletTestCase
31 {
32     /**
33      * Verify that multi value parameters can be sent in the
34      * <code>beingXXX()</code> method to the server redirector.
35      *
36      * @param theRequest the request object that serves to initialize the
37      * HTTP connection to the server redirector.
38      */

39     public void beginMultiValueParameters(WebRequest theRequest)
40     {
41         theRequest.addParameter("multivalue", "value 1");
42         theRequest.addParameter("multivalue", "value 2");
43     }
44
45     /**
46      * Verify that multi value parameters can be sent in the
47      * <code>beingXXX()</code> method to the server redirector.
48      */

49     public void testMultiValueParameters()
50     {
51         String JavaDoc[] values = request.getParameterValues("multivalue");
52
53         if (values[0].equals("value 1"))
54         {
55             assertEquals("value 2", values[1]);
56         }
57         else if (values[0].equals("value 2"))
58         {
59             assertEquals("value 1", values[1]);
60         }
61         else
62         {
63             fail("Shoud have returned a vector with the "
64                 + "values \"value 1\" and \"value 2\"");
65         }
66     }
67
68     //-------------------------------------------------------------------------
69

70     /**
71      * Verify we can set and retrieve several parameters.
72      *
73      * @param theRequest the request object that serves to initialize the
74      * HTTP connection to the server redirector.
75      */

76     public void beginSeveralParameters(WebRequest theRequest)
77     {
78         theRequest.addParameter("PostParameter1", "EMPLOYEE0145",
79             WebRequest.POST_METHOD);
80         theRequest.addParameter("PostParameter2", "W", WebRequest.GET_METHOD);
81         theRequest.addParameter("PostParameter3", "07/08/2002",
82             WebRequest.POST_METHOD);
83         theRequest.addParameter("PostParameter4", "/tas/ViewSchedule.esp",
84             WebRequest.GET_METHOD);
85     }
86
87     /**
88      * Verify we can set and retrieve several parameters.
89      */

90     public void testSeveralParameters()
91     {
92         assertEquals("parameter4", "/tas/ViewSchedule.esp",
93             request.getParameter("PostParameter4"));
94         assertEquals("parameter1", "EMPLOYEE0145",
95             request.getParameter("PostParameter1"));
96         assertEquals("parameter2", "W", request.getParameter("PostParameter2"));
97         assertEquals("parameter3", "07/08/2002",
98             request.getParameter("PostParameter3"));
99     }
100
101 }
102
Popular Tags