KickJava   Java API By Example, From Geeks To Geeks.

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


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

33 public class TestServletFilterConfiguration extends TestAbstractConfiguration
34 {
35     protected AbstractConfiguration getConfiguration()
36     {
37         MockFilterConfig config = new MockFilterConfig();
38         config.setInitParameter("key1", "value1");
39         config.setInitParameter("key2", "value2");
40         config.setInitParameter("list", "value1, value2");
41
42         return new ServletFilterConfiguration(config);
43     }
44
45     protected AbstractConfiguration getEmptyConfiguration()
46     {
47         return new ServletFilterConfiguration(new MockFilterConfig());
48     }
49
50     private class MockFilterConfig implements FilterConfig JavaDoc
51     {
52         private Properties JavaDoc parameters = new Properties JavaDoc();
53
54         public String JavaDoc getFilterName()
55         {
56             return null;
57         }
58
59         public ServletContext JavaDoc getServletContext()
60         {
61             return null;
62         }
63
64         public String JavaDoc getInitParameter(String JavaDoc key)
65         {
66             return parameters.getProperty(key);
67         }
68
69         public Enumeration JavaDoc getInitParameterNames()
70         {
71             return parameters.keys();
72         }
73
74         public void setInitParameter(String JavaDoc key, String JavaDoc value)
75         {
76             parameters.setProperty(key, value);
77         }
78     }
79
80     public void testAddPropertyDirect()
81     {
82         try
83         {
84             super.testAddPropertyDirect();
85             fail("addPropertyDirect should throw an UnsupportedException");
86         }
87         catch (UnsupportedOperationException JavaDoc e)
88         {
89             // ok
90
}
91     }
92
93     public void testClearProperty()
94     {
95         try
96         {
97             super.testClearProperty();
98             fail("testClearProperty should throw an UnsupportedException");
99         }
100         catch (UnsupportedOperationException JavaDoc e)
101         {
102             // ok
103
}
104     }
105
106 }
107
Popular Tags