001: package servletunit;
002:
003: // StrutsTestCase - a JUnit extension for testing Struts actions
004: // within the context of the ActionServlet.
005: // Copyright (C) 2002 Deryl Seale
006: //
007: // This library is free software; you can redistribute it and/or
008: // modify it under the terms of the Apache Software License as
009: // published by the Apache Software Foundation; either version 1.1
010: // of the License, or (at your option) any later version.
011: //
012: // This library is distributed in the hope that it will be useful,
013: // but WITHOUT ANY WARRANTY; without even the implied warranty of
014: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: // Apache Software Foundation Licens for more details.
016: //
017: // You may view the full text here: http://www.apache.org/LICENSE.txt
018:
019: import javax.servlet.ServletConfig;
020: import javax.servlet.ServletContext;
021: import java.util.Enumeration;
022: import java.util.Hashtable;
023:
024: /**
025: * This class simulates a ServletConfig.
026: */
027:
028: public class ServletConfigSimulator implements ServletConfig {
029:
030: private Hashtable parameters;
031: private ServletContext context;
032:
033: public ServletConfigSimulator() {
034: parameters = new Hashtable();
035: context = new ServletContextSimulator();
036: }
037:
038: /**
039: * Returns a <code>String</code> containing the value of the
040: * named initialization parameter, or <code>null</code> if
041: * the parameter does not exist.
042: *
043: * @param name a <code>String</code> specifying the name
044: * of the initialization parameter
045: *
046: * @return a <code>String</code> containing the value
047: * of the initialization parameter
048: *
049: */
050: public String getInitParameter(String name) {
051: return (String) parameters.get(name);
052: }
053:
054: /**
055: * Returns the names of the servlet's initialization parameters
056: * as an <code>Enumeration</code> of <code>String</code> objects,
057: * or an empty <code>Enumeration</code> if the servlet has
058: * no initialization parameters.
059: *
060: * @return an <code>Enumeration</code> of <code>String</code>
061: * objects containing the names of the servlet's
062: * initialization parameters
063: *
064: *
065: *
066: */
067: public Enumeration getInitParameterNames() {
068: return parameters.keys();
069: }
070:
071: /**
072: * Returns a reference to the {@link ServletContext} in which the caller
073: * is executing.
074: *
075: *
076: * @return a {@link ServletContext} object, used
077: * by the caller to interact with its servlet
078: * container
079: *
080: * @see ServletContext
081: *
082: */
083: public ServletContext getServletContext() {
084: return context;
085: }
086:
087: /**
088: * Returns the name of this servlet instance.
089: * The name may be provided via server administration, assigned in the
090: * web application deployment descriptor, or for an unregistered (and thus
091: * unnamed) servlet instance it will be the servlet's class name.
092: *
093: * @return the String "ActionServlet"
094: *
095: *
096: *
097: */
098: public String getServletName() {
099: return "ActionServlet";
100: }
101:
102: /**
103: * Sets a named initialization parameter with the supplied
104: * <code>String</code> value.
105: *
106: * @param key a <code>String</code> specifying the name
107: * of the initialization parameter
108: *
109: * @param value a <code>String</code> value for this initialization
110: * parameter
111: *
112: */
113: public void setInitParameter(String key, String value) {
114: parameters.put(key, value);
115: }
116:
117: }
|