1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.configuration.web;
19  
20  import org.apache.commons.configuration.AbstractConfiguration;
21  import org.apache.commons.configuration.TestAbstractConfiguration;
22  
23  import javax.servlet.FilterConfig;
24  import javax.servlet.ServletContext;
25  import java.util.Enumeration;
26  import java.util.Properties;
27  
28  /***
29   * Test case for the {@link ServletFilterConfiguration} class.
30   *
31   * @author Emmanuel Bourg
32   * @version $Revision: 515306 $, $Date: 2007-03-06 22:15:00 +0100 (Di, 06 Mrz 2007) $
33   */
34  public class TestServletFilterConfiguration extends TestAbstractConfiguration
35  {
36      protected AbstractConfiguration getConfiguration()
37      {
38          MockFilterConfig config = new MockFilterConfig();
39          config.setInitParameter("key1", "value1");
40          config.setInitParameter("key2", "value2");
41          config.setInitParameter("list", "value1, value2");
42          config.setInitParameter("listesc", "value1//,value2");
43  
44          return new ServletFilterConfiguration(config);
45      }
46  
47      protected AbstractConfiguration getEmptyConfiguration()
48      {
49          return new ServletFilterConfiguration(new MockFilterConfig());
50      }
51  
52      private class MockFilterConfig implements FilterConfig
53      {
54          private Properties parameters = new Properties();
55  
56          public String getFilterName()
57          {
58              return null;
59          }
60  
61          public ServletContext getServletContext()
62          {
63              return null;
64          }
65  
66          public String getInitParameter(String key)
67          {
68              return parameters.getProperty(key);
69          }
70  
71          public Enumeration getInitParameterNames()
72          {
73              return parameters.keys();
74          }
75  
76          public void setInitParameter(String key, String value)
77          {
78              parameters.setProperty(key, value);
79          }
80      }
81  
82      public void testAddPropertyDirect()
83      {
84          try
85          {
86              super.testAddPropertyDirect();
87              fail("addPropertyDirect should throw an UnsupportedException");
88          }
89          catch (UnsupportedOperationException e)
90          {
91              // ok
92          }
93      }
94  
95      public void testClearProperty()
96      {
97          try
98          {
99              super.testClearProperty();
100             fail("testClearProperty should throw an UnsupportedException");
101         }
102         catch (UnsupportedOperationException e)
103         {
104             // ok
105         }
106     }
107 
108 }