1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.chain.web.servlet;
18
19
20 import javax.servlet.RequestDispatcher;
21 import javax.servlet.Servlet;
22 import javax.servlet.ServletContext;
23 import javax.servlet.ServletException;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27
28 import java.io.InputStream;
29 import java.net.MalformedURLException;
30 import java.net.URL;
31 import java.util.Enumeration;
32 import java.util.Hashtable;
33 import java.util.Set;
34
35
36
37 public class MockServletContext implements ServletContext {
38
39
40 private Log log = LogFactory.getLog(MockServletContext.class);
41 private Hashtable attributes = new Hashtable();
42 private Hashtable parameters = new Hashtable();
43
44
45
46
47
48 public void addInitParameter(String name, String value) {
49 parameters.put(name, value);
50 }
51
52
53
54
55
56 public Object getAttribute(String name) {
57 return (attributes.get(name));
58 }
59
60 public Enumeration getAttributeNames() {
61 return (attributes.keys());
62 }
63
64 public ServletContext getContext(String uripath) {
65 throw new UnsupportedOperationException();
66 }
67
68 public String getInitParameter(String name) {
69 return ((String) parameters.get(name));
70 }
71
72 public Enumeration getInitParameterNames() {
73 return (parameters.keys());
74 }
75
76 public int getMajorVersion() {
77 return (2);
78 }
79
80 public String getMimeType(String path) {
81 throw new UnsupportedOperationException();
82 }
83
84 public int getMinorVersion() {
85 return (3);
86 }
87
88 public RequestDispatcher getNamedDispatcher(String name) {
89 throw new UnsupportedOperationException();
90 }
91
92 public String getRealPath(String path) {
93 throw new UnsupportedOperationException();
94 }
95
96 public RequestDispatcher getRequestDispatcher(String path) {
97 throw new UnsupportedOperationException();
98 }
99
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 }