KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > configuration > web > TestServletRequestConfiguration


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License")
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.commons.configuration.web;
18
19 import java.util.Enumeration JavaDoc;
20 import javax.servlet.ServletRequest JavaDoc;
21
22 import com.mockobjects.servlet.MockHttpServletRequest;
23 import org.apache.commons.collections.iterators.IteratorEnumeration;
24 import org.apache.commons.configuration.AbstractConfiguration;
25 import org.apache.commons.configuration.BaseConfiguration;
26 import org.apache.commons.configuration.Configuration;
27 import org.apache.commons.configuration.TestAbstractConfiguration;
28
29 /**
30  * Test case for the {@link ServletRequestConfiguration} class.
31  *
32  * @author Emmanuel Bourg
33  * @version $Revision: 155408 $, $Date: 2005-02-26 13:56:39 +0100 (Sa, 26 Feb 2005) $
34  */

35 public class TestServletRequestConfiguration extends TestAbstractConfiguration
36 {
37     protected AbstractConfiguration getConfiguration()
38     {
39         final Configuration configuration = new BaseConfiguration();
40         configuration.setProperty("key1", "value1");
41         configuration.setProperty("key2", "value2");
42         configuration.addProperty("list", "value1");
43         configuration.addProperty("list", "value2");
44
45         ServletRequest JavaDoc request = new MockHttpServletRequest()
46         {
47             public String JavaDoc[] getParameterValues(String JavaDoc key)
48             {
49                 return configuration.getStringArray(key);
50             }
51
52             public Enumeration JavaDoc getParameterNames()
53             {
54                 return new IteratorEnumeration(configuration.getKeys());
55             }
56         };
57
58         return new ServletRequestConfiguration(request);
59     }
60
61     protected AbstractConfiguration getEmptyConfiguration()
62     {
63         final Configuration configuration = new BaseConfiguration();
64
65         ServletRequest JavaDoc request = new MockHttpServletRequest()
66         {
67             public String JavaDoc getParameter(String JavaDoc key)
68             {
69                 return null;
70             }
71
72             public Enumeration JavaDoc getParameterNames()
73             {
74                 return new IteratorEnumeration(configuration.getKeys());
75             }
76         };
77
78         return new ServletRequestConfiguration(request);
79     }
80
81     public void testAddPropertyDirect()
82     {
83         try
84         {
85             super.testAddPropertyDirect();
86             fail("addPropertyDirect should throw an UnsupportedException");
87         }
88         catch (UnsupportedOperationException JavaDoc e)
89         {
90             // ok
91
}
92     }
93
94     public void testClearProperty()
95     {
96         try
97         {
98             super.testClearProperty();
99             fail("testClearProperty should throw an UnsupportedException");
100         }
101         catch (UnsupportedOperationException JavaDoc e)
102         {
103             // ok
104
}
105     }
106
107 }
108
Popular Tags