001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    
018    package org.apache.commons.configuration.web;
019    
020    import javax.servlet.Servlet;
021    import javax.servlet.ServletConfig;
022    import javax.servlet.http.HttpServlet;
023    
024    import org.apache.commons.configuration.AbstractConfiguration;
025    import org.apache.commons.configuration.TestAbstractConfiguration;
026    import org.junit.Test;
027    
028    import com.mockobjects.servlet.MockServletConfig;
029    
030    /**
031     * Test case for the {@link ServletConfiguration} class.
032     *
033     * @author Emmanuel Bourg
034     * @version $Id: TestServletConfiguration.java 1222465 2011-12-22 21:32:56Z oheger $
035     */
036    public class TestServletConfiguration extends TestAbstractConfiguration
037    {
038        @Override
039        protected AbstractConfiguration getConfiguration()
040        {
041            final MockServletConfig config = new MockServletConfig();
042            config.setInitParameter("key1", "value1");
043            config.setInitParameter("key2", "value2");
044            config.setInitParameter("list", "value1, value2");
045            config.setInitParameter("listesc", "value1\\,value2");
046    
047            Servlet servlet = new HttpServlet() {
048                /**
049                 * Serial version UID.
050                 */
051                private static final long serialVersionUID = 1L;
052    
053                @Override
054                public ServletConfig getServletConfig()
055                {
056                    return config;
057                }
058            };
059    
060            return new ServletConfiguration(servlet);
061        }
062    
063        @Override
064        protected AbstractConfiguration getEmptyConfiguration()
065        {
066            return new ServletConfiguration(new MockServletConfig());
067        }
068    
069        @Override
070        @Test(expected = UnsupportedOperationException.class)
071        public void testAddPropertyDirect()
072        {
073            super.testAddPropertyDirect();
074        }
075    
076        @Override
077        @Test(expected = UnsupportedOperationException.class)
078        public void testClearProperty()
079        {
080           super.testClearProperty();
081        }
082    }