001    // Copyright 2004, 2005 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry.test.mock;
016    
017    import java.util.Collections;
018    import java.util.Enumeration;
019    import java.util.HashMap;
020    import java.util.Map;
021    
022    import javax.servlet.ServletConfig;
023    import javax.servlet.ServletContext;
024    
025    /**
026     * An implementation of {@link javax.servlet.ServletConfig} used
027     * for Mock testing. 
028     *
029     * @author Howard Lewis Ship
030     * @since 4.0
031     */
032    
033    public class MockServletConfig implements ServletConfig, InitParameterHolder
034    {
035        private String _name;
036        private ServletContext _context;
037        private Map _initParameters = new HashMap();
038    
039        public MockServletConfig(String name, ServletContext context)
040        {
041            _name = name;
042            _context = context;
043        }
044    
045        public String getInitParameter(String name)
046        {
047            return (String) _initParameters.get(name);
048        }
049    
050        public Enumeration getInitParameterNames()
051        {
052            return Collections.enumeration(_initParameters.keySet());
053        }
054    
055        public ServletContext getServletContext()
056        {
057            return _context;
058        }
059    
060        public String getServletName()
061        {
062            return _name;
063        }
064    
065        public void setInitParameter(String name, String value)
066        {
067            _initParameters.put(name, value);
068        }
069    
070    }