    1   /*
    2    * Copyright 2002-2004 the original author or authors.
    3    *
    4    * Licensed under the Apache License, Version 2.0 (the "License");
    5    * you may not use this file except in compliance with the License.
    6    * You may obtain a copy of the License at
    7    *
    8    *      http://www.apache.org/licenses/LICENSE-2.0
    9    *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16
    17  package org.huihoo.jfox.soaf.util.filter;
    18
    19  import java.util.Enumeration;
    20  import java.util.Hashtable;
    21
    22  import javax.servlet.ServletConfig;
    23  import javax.servlet.ServletContext;
    24
    25  /***
    26   * Mock implementation of the ServletConfig interface.
    27   *
    28   * <p>Used for testing the web framework; typically not
    29   * necessary for testing application controllers.
    30   *
    31   * @author Rod Johnson
    32   * @author Juergen Hoeller
    33   * @since 1.0.2
    34   */
    35  public class MockServletConfig implements ServletConfig {
    36
    37  	private final ServletContext servletContext;
    38
    39  	private final String name;
    40
    41  	private final Hashtable initParameters = new Hashtable();
    42
    43
    44  	/***
    45  	 * Create new MockServletConfig with empty String as name.
    46  	 * @param servletContext the ServletContext that the servlet runs in
    47  	 */
    48  	public MockServletConfig(ServletContext servletContext) {
    49  		this(servletContext, "");
    50  	}
    51
    52  	/***
    53  	 * Create new MockServletConfig.
    54  	 * @param servletContext the ServletContext that the servlet runs in
    55  	 * @param name the name of the servlet
    56  	 */
    57  	public MockServletConfig(ServletContext servletContext, String name) {
    58  		this.servletContext = servletContext;
    59  		this.name = name;
    60  	}
    61
    62
    63  	public void addInitParameter(String name, String value) {
    64  		this.initParameters.put(name, value);
    65  	}
    66
    67  	public String getInitParameter(String name) {
    68  		return (String) this.initParameters.get(name);
    69  	}
    70
    71  	public Enumeration getInitParameterNames() {
    72  		return this.initParameters.keys();
    73  	}
    74
    75  	public ServletContext getServletContext() {
    76  		return servletContext;
    77  	}
    78
    79  	public String getServletName() {
    80  		return name;
    81  	}
    82
    83  }