    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: 439648 $, $Date: 2006-09-02 22:42:10 +0200 (Sa, 02 Sep 2006) $
    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
    43          return new ServletFilterConfiguration(config);
    44      }
    45
    46      protected AbstractConfiguration getEmptyConfiguration()
    47      {
    48          return new ServletFilterConfiguration(new MockFilterConfig());
    49      }
    50
    51      private class MockFilterConfig implements FilterConfig
    52      {
    53          private Properties parameters = new Properties();
    54
    55          public String getFilterName()
    56          {
    57              return null;
    58          }
    59
    60          public ServletContext getServletContext()
    61          {
    62              return null;
    63          }
    64
    65          public String getInitParameter(String key)
    66          {
    67              return parameters.getProperty(key);
    68          }
    69
    70          public Enumeration getInitParameterNames()
    71          {
    72              return parameters.keys();
    73          }
    74
    75          public void setInitParameter(String key, String value)
    76          {
    77              parameters.setProperty(key, value);
    78          }
    79      }
    80
    81      public void testAddPropertyDirect()
    82      {
    83          try
    84          {
    85              super.testAddPropertyDirect();
    86              fail("addPropertyDirect should throw an UnsupportedException");
    87          }
    88          catch (UnsupportedOperationException 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 e)
    102         {
    103             // ok
    104         }
    105     }
    106
    107 }