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 javax.servlet.ServletRequest;
22  
23  import com.mockobjects.servlet.MockHttpServletRequest;
24  import org.apache.commons.collections.iterators.IteratorEnumeration;
25  import org.apache.commons.configuration.AbstractConfiguration;
26  import org.apache.commons.configuration.BaseConfiguration;
27  import org.apache.commons.configuration.Configuration;
28  import org.apache.commons.configuration.TestAbstractConfiguration;
29  
30  /***
31   * Test case for the {@link ServletRequestConfiguration} class.
32   *
33   * @author Emmanuel Bourg
34   * @version $Revision: 439648 $, $Date: 2006-09-02 22:42:10 +0200 (Sa, 02 Sep 2006) $
35   */
36  public class TestServletRequestConfiguration extends TestAbstractConfiguration
37  {
38      protected AbstractConfiguration getConfiguration()
39      {
40          final Configuration configuration = new BaseConfiguration();
41          configuration.setProperty("key1", "value1");
42          configuration.setProperty("key2", "value2");
43          configuration.addProperty("list", "value1");
44          configuration.addProperty("list", "value2");
45  
46          ServletRequest request = new MockHttpServletRequest()
47          {
48              public String[] getParameterValues(String key)
49              {
50                  return configuration.getStringArray(key);
51              }
52  
53              public Enumeration getParameterNames()
54              {
55                  return new IteratorEnumeration(configuration.getKeys());
56              }
57          };
58  
59          return new ServletRequestConfiguration(request);
60      }
61  
62      protected AbstractConfiguration getEmptyConfiguration()
63      {
64          final Configuration configuration = new BaseConfiguration();
65  
66          ServletRequest request = new MockHttpServletRequest()
67          {
68              public String getParameter(String key)
69              {
70                  return null;
71              }
72  
73              public Enumeration getParameterNames()
74              {
75                  return new IteratorEnumeration(configuration.getKeys());
76              }
77          };
78  
79          return new ServletRequestConfiguration(request);
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 }