View Javadoc

1   /*
2    * $Id: ServletContextAdapterTest.java 537191 2007-05-11 13:46:06Z apetrelli $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  package org.apache.tiles.web.util;
22  
23  import java.util.Enumeration;
24  import java.util.HashSet;
25  import java.util.Set;
26  
27  import org.apache.shale.test.mock.MockServletConfig;
28  import org.apache.shale.test.mock.MockServletContext;
29  
30  import junit.framework.TestCase;
31  
32  /***
33   * Tests {@link ServletContextAdapter}.
34   *
35   * @version $Rev: 537191 $ $Date: 2007-05-11 15:46:06 +0200 (ven, 11 mag 2007) $
36   */
37  public class ServletContextAdapterTest extends TestCase {
38  
39      /***
40       * The context to test.
41       */
42      private ServletContextAdapter context;
43  
44      /*** {@inheritDoc} */
45      @Override
46      protected void setUp() throws Exception {
47          MockServletContext rootContext = new MockServletContext();
48          rootContext.addInitParameter("initParameter1", "parameterValue1");
49          rootContext.addInitParameter("initParameter2", "parameterValue2");
50          MockServletConfig config = new MockServletConfig(rootContext);
51          config.addInitParameter("initParameter1", "newParameterValue1");
52          config.addInitParameter("newInitParameter", "newParameterValue2");
53          context = new ServletContextAdapter(config);
54      }
55  
56      /***
57       * Test init parameters.
58       */
59      @SuppressWarnings("unchecked")
60      public void testGetInitParameters() {
61          assertEquals(context.getInitParameter("initParameter1"), "newParameterValue1");
62          assertEquals(context.getInitParameter("initParameter2"), "parameterValue2");
63          assertEquals(context.getInitParameter("newInitParameter"), "newParameterValue2");
64  
65          Set<String> paramSet = new HashSet<String>();
66          paramSet.add("initParameter1");
67          paramSet.add("initParameter2");
68          paramSet.add("newInitParameter");
69          Enumeration<String> names = context.getInitParameterNames();
70          while (names.hasMoreElements()) {
71              String name = names.nextElement();
72              assertTrue(paramSet.contains(name));
73              paramSet.remove(name);
74          }
75  
76          assertTrue(paramSet.isEmpty());
77      }
78  
79  }