org.apache.shale.test.mock.MockServletConfig Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.shale.test.mock;
import java.util.Enumeration;
import java.util.Hashtable;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
/**
* Mock implementation of ServletConfig
.
*
* $Id$
*/
public class MockServletConfig implements ServletConfig {
// ------------------------------------------------------------ Constructors
/**
* Construct a default instance.
*/
public MockServletConfig() {
}
/**
* Construct an instance associated with the specified
* servlet context.
*
* @param context The associated ServletContext
*/
public MockServletConfig(ServletContext context) {
setServletContext(context);
}
// ----------------------------------------------------- Mock Object Methods
/**
* Add a servlet initialization parameter.
*
* @param name Parameter name
* @param value Parameter value
*/
public void addInitParameter(String name, String value) {
parameters.put(name, value);
}
/**
* Set the servlet context for this application.
*
* @param context The new servlet context
*/
public void setServletContext(ServletContext context) {
this.context = context;
}
// ------------------------------------------------------ Instance Variables
private ServletContext context;
private Hashtable parameters = new Hashtable();
// --------------------------------------------------- ServletConfig Methods
/** {@inheritDoc} */
public String getInitParameter(String name) {
return (String) parameters.get(name);
}
/** {@inheritDoc} */
public Enumeration getInitParameterNames() {
return parameters.keys();
}
/** {@inheritDoc} */
public ServletContext getServletContext() {
return this.context;
}
/** {@inheritDoc} */
public String getServletName() {
return "MockServlet";
}
}