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 package org.apache.commons.chain.web.servlet;
018
019
020 import javax.servlet.RequestDispatcher;
021 import javax.servlet.Servlet;
022 import javax.servlet.ServletContext;
023 import javax.servlet.ServletException;
024
025 import org.apache.commons.logging.Log;
026 import org.apache.commons.logging.LogFactory;
027
028 import java.io.InputStream;
029 import java.net.MalformedURLException;
030 import java.net.URL;
031 import java.util.Enumeration;
032 import java.util.Hashtable;
033 import java.util.Set;
034
035
036 // Mock Object for ServletContext (Version 2.3)
037 public class MockServletContext implements ServletContext {
038
039
040 private Log log = LogFactory.getLog(MockServletContext.class);
041 private Hashtable attributes = new Hashtable();
042 private Hashtable parameters = new Hashtable();
043
044
045 // --------------------------------------------------------- Public Methods
046
047
048 public void addInitParameter(String name, String value) {
049 parameters.put(name, value);
050 }
051
052
053 // ------------------------------------------------- ServletContext Methods
054
055
056 public Object getAttribute(String name) {
057 return (attributes.get(name));
058 }
059
060 public Enumeration getAttributeNames() {
061 return (attributes.keys());
062 }
063
064 public ServletContext getContext(String uripath) {
065 throw new UnsupportedOperationException();
066 }
067
068 public String getInitParameter(String name) {
069 return ((String) parameters.get(name));
070 }
071
072 public Enumeration getInitParameterNames() {
073 return (parameters.keys());
074 }
075
076 public int getMajorVersion() {
077 return (2);
078 }
079
080 public String getMimeType(String path) {
081 throw new UnsupportedOperationException();
082 }
083
084 public int getMinorVersion() {
085 return (3);
086 }
087
088 public RequestDispatcher getNamedDispatcher(String name) {
089 throw new UnsupportedOperationException();
090 }
091
092 public String getRealPath(String path) {
093 throw new UnsupportedOperationException();
094 }
095
096 public RequestDispatcher getRequestDispatcher(String path) {
097 throw new UnsupportedOperationException();
098 }
099
100 public URL getResource(String path) throws MalformedURLException {
101 throw new UnsupportedOperationException();
102 }
103
104 public InputStream getResourceAsStream(String path) {
105 throw new UnsupportedOperationException();
106 }
107
108 public Set getResourcePaths(String path) {
109 throw new UnsupportedOperationException();
110 }
111
112 public Servlet getServlet(String name) throws ServletException {
113 throw new UnsupportedOperationException();
114 }
115
116 public String getServletContextName() {
117 return ("MockServletContext");
118 }
119
120 public String getServerInfo() {
121 return ("MockServletContext");
122 }
123
124 public Enumeration getServlets() {
125 throw new UnsupportedOperationException();
126 }
127
128 public Enumeration getServletNames() {
129 throw new UnsupportedOperationException();
130 }
131
132 public void log(String message) {
133 log.info(message);
134 }
135
136 public void log(Exception exception, String message) {
137 log.error(message, exception);
138 }
139
140 public void log(String message, Throwable exception) {
141 log.error(message, exception);
142 }
143
144 public void removeAttribute(String name) {
145 attributes.remove(name);
146 }
147
148 public void setAttribute(String name, Object value) {
149 attributes.put(name, value);
150 }
151
152
153 }