View Javadoc

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 java.util.Enumeration;
21  import java.util.Properties;
22  
23  import javax.servlet.FilterConfig;
24  import javax.servlet.ServletContext;
25  
26  import org.apache.commons.configuration.AbstractConfiguration;
27  import org.apache.commons.configuration.TestAbstractConfiguration;
28  import org.junit.Test;
29  
30  /**
31   * Test case for the {@link ServletFilterConfiguration} class.
32   *
33   * @author Emmanuel Bourg
34   * @version $Id: TestServletFilterConfiguration.java 1222465 2011-12-22 21:32:56Z oheger $
35   */
36  public class TestServletFilterConfiguration extends TestAbstractConfiguration
37  {
38      @Override
39      protected AbstractConfiguration getConfiguration()
40      {
41          MockFilterConfig config = new MockFilterConfig();
42          config.setInitParameter("key1", "value1");
43          config.setInitParameter("key2", "value2");
44          config.setInitParameter("list", "value1, value2");
45          config.setInitParameter("listesc", "value1\\,value2");
46  
47          return new ServletFilterConfiguration(config);
48      }
49  
50      @Override
51      protected AbstractConfiguration getEmptyConfiguration()
52      {
53          return new ServletFilterConfiguration(new MockFilterConfig());
54      }
55  
56      private class MockFilterConfig implements FilterConfig
57      {
58          private Properties parameters = new Properties();
59  
60          public String getFilterName()
61          {
62              return null;
63          }
64  
65          public ServletContext getServletContext()
66          {
67              return null;
68          }
69  
70          public String getInitParameter(String key)
71          {
72              return parameters.getProperty(key);
73          }
74  
75          public Enumeration<?> getInitParameterNames()
76          {
77              return parameters.keys();
78          }
79  
80          public void setInitParameter(String key, String value)
81          {
82              parameters.setProperty(key, value);
83          }
84      }
85  
86      @Override
87      @Test(expected = UnsupportedOperationException.class)
88      public void testAddPropertyDirect()
89      {
90          super.testAddPropertyDirect();
91      }
92  
93      @Override
94      @Test(expected = UnsupportedOperationException.class)
95      public void testClearProperty()
96      {
97          super.testClearProperty();
98      }
99  }