KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Properties JavaDoc;
21 import javax.servlet.Servlet JavaDoc;
22 import javax.servlet.ServletConfig JavaDoc;
23 import javax.servlet.ServletContext JavaDoc;
24 import javax.servlet.http.HttpServlet JavaDoc;
25
26 import com.mockobjects.servlet.MockServletConfig;
27 import com.mockobjects.servlet.MockServletContext;
28 import org.apache.commons.configuration.AbstractConfiguration;
29 import org.apache.commons.configuration.TestAbstractConfiguration;
30
31 /**
32  * Test case for the {@link ServletContextConfiguration} class.
33  *
34  * @author Emmanuel Bourg
35  * @version $Revision: 155408 $, $Date: 2005-02-26 13:56:39 +0100 (Sa, 26 Feb 2005) $
36  */

37 public class TestServletContextConfiguration extends TestAbstractConfiguration
38 {
39     protected AbstractConfiguration getConfiguration()
40     {
41         final Properties JavaDoc parameters = new Properties JavaDoc();
42         parameters.setProperty("key1", "value1");
43         parameters.setProperty("key2", "value2");
44         parameters.setProperty("list", "value1, value2");
45
46         // create a servlet context
47
ServletContext JavaDoc context = new MockServletContext()
48         {
49             public String JavaDoc getInitParameter(String JavaDoc key)
50             {
51                 return parameters.getProperty(key);
52             }
53
54             public Enumeration JavaDoc getInitParameterNames()
55             {
56                 return parameters.keys();
57             }
58         };
59
60         // create a servlet config
61
final MockServletConfig config = new MockServletConfig();
62         config.setServletContext(context);
63
64         // create a servlet
65
Servlet JavaDoc servlet = new HttpServlet JavaDoc()
66         {
67             public ServletConfig JavaDoc getServletConfig()
68             {
69                 return config;
70             }
71         };
72
73         return new ServletContextConfiguration(servlet);
74     }
75
76     protected AbstractConfiguration getEmptyConfiguration()
77     {
78         // create a servlet context
79
ServletContext JavaDoc context = new MockServletContext()
80         {
81             public Enumeration JavaDoc getInitParameterNames()
82             {
83                 return new Properties JavaDoc().keys();
84             }
85         };
86
87         return new ServletContextConfiguration(context);
88     }
89
90     public void testAddPropertyDirect()
91     {
92         try
93         {
94             super.testAddPropertyDirect();
95             fail("addPropertyDirect should throw an UnsupportedException");
96         }
97         catch (UnsupportedOperationException JavaDoc e)
98         {
99             // ok
100
}
101     }
102
103     public void testClearProperty()
104     {
105         try
106         {
107             super.testClearProperty();
108             fail("testClearProperty should throw an UnsupportedException");
109         }
110         catch (UnsupportedOperationException JavaDoc e)
111         {
112             // ok
113
}
114     }
115
116 }
117
Popular Tags