KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mockobjects > servlet > MockServletContext


1 package com.mockobjects.servlet;
2
3 import com.mockobjects.*;
4
5 import javax.servlet.RequestDispatcher JavaDoc;
6 import javax.servlet.Servlet JavaDoc;
7 import javax.servlet.ServletContext JavaDoc;
8 import java.io.InputStream JavaDoc;
9 import java.net.URL JavaDoc;
10 import java.util.Enumeration JavaDoc;
11 import java.util.HashMap JavaDoc;
12 import java.util.Set JavaDoc;
13
14 public class MockServletContext extends MockObject implements ServletContext JavaDoc {
15     private ReturnObjectBag returnAttributes = new ReturnObjectBag("attributes");
16     private Set JavaDoc resourcePaths;
17     private ReturnObjectList realPaths = new ReturnObjectList("real path");
18     private URL JavaDoc resource;
19     private HashMap JavaDoc initParameters = new HashMap JavaDoc();
20     private ExpectationValue expectedLogValue = new ExpectationValue("log");
21     private ExpectationValue expectedLogThrowable =
22         new ExpectationValue("log throwable");
23     private ExpectationValue requestDispatcherURI =
24         new ExpectationValue("RequestDispatcher URI");
25     private RequestDispatcher JavaDoc requestDispatcher;
26     private ExpectationSet attributes = new ExpectationSet("attributes");
27
28     public Enumeration JavaDoc getServlets() {
29         return null;
30     }
31
32     public void log(String JavaDoc string) {
33         expectedLogValue.setActual(string);
34     }
35
36     public void setExpectedLog(String JavaDoc string) {
37         expectedLogValue.setExpected(string);
38     }
39
40     public void setupGetResource(URL JavaDoc resource) {
41         this.resource = resource;
42     }
43
44     public URL JavaDoc getResource(String JavaDoc string) {
45         return resource;
46     }
47
48     public void setupGetResourcePaths(Set JavaDoc resourcePaths) {
49         this.resourcePaths = resourcePaths;
50     }
51
52     public Set JavaDoc getResourcePaths(String JavaDoc string) {
53         return resourcePaths;
54     }
55
56     public ServletContext JavaDoc getContext(String JavaDoc string) {
57         return null;
58     }
59
60     public int getMinorVersion() {
61         return -1;
62     }
63
64     public void removeAttribute(String JavaDoc string) {
65     }
66
67     public void log(String JavaDoc string, Throwable JavaDoc t) {
68         log(string);
69         expectedLogThrowable.setActual(t);
70     }
71
72     public void setExpectedLogThrowable(Throwable JavaDoc throwable) {
73         expectedLogThrowable.setExpected(throwable);
74     }
75
76     public void addRealPath(String JavaDoc realPath) {
77         this.realPaths.addObjectToReturn(realPath);
78     }
79
80     public String JavaDoc getRealPath(String JavaDoc string) {
81         return realPaths.nextReturnObject().toString();
82     }
83
84     public Enumeration JavaDoc getServletNames() {
85         return null;
86     }
87
88     public Servlet JavaDoc getServlet(String JavaDoc string) {
89         return null;
90     }
91
92     public void log(Exception JavaDoc exception, String JavaDoc string) {
93     }
94
95     public String JavaDoc getServerInfo() {
96         return null;
97     }
98
99     public void setExpectedRequestDispatcherURI(String JavaDoc uri) {
100         this.requestDispatcherURI.setExpected(uri);
101     }
102
103     public void setupGetRequestDispatcher(
104         RequestDispatcher JavaDoc requestDispatcher) {
105
106         this.requestDispatcher = requestDispatcher;
107     }
108
109     public RequestDispatcher JavaDoc getRequestDispatcher(String JavaDoc uri) {
110         requestDispatcherURI.setActual(uri);
111         return requestDispatcher;
112     }
113
114     public int getMajorVersion() {
115         return -1;
116     }
117
118     public Set JavaDoc getResourcePaths() {
119         return null;
120     }
121
122     public void setupGetAttribute(String JavaDoc string, Object JavaDoc object) {
123         returnAttributes.putObjectToReturn(string, object);
124     }
125
126     public String JavaDoc getMimeType(String JavaDoc string) {
127         return null;
128     }
129
130     public RequestDispatcher JavaDoc getNamedDispatcher(String JavaDoc string) {
131         return null;
132     }
133
134     public String JavaDoc getInitParameter(String JavaDoc paramName) {
135         return (String JavaDoc) initParameters.get(paramName);
136     }
137
138     public void setInitParameter(String JavaDoc paramName, String JavaDoc paramValue) {
139         initParameters.put(paramName, paramValue);
140     }
141
142     public Object JavaDoc getAttribute(String JavaDoc string) {
143         return returnAttributes.getNextReturnObject(string);
144     }
145
146     public Enumeration JavaDoc getAttributeNames() {
147         return null;
148     }
149
150     public String JavaDoc getServletContextName() {
151         return null;
152     }
153
154     public InputStream JavaDoc getResourceAsStream(String JavaDoc string) {
155         return null;
156     }
157
158     public Enumeration JavaDoc getInitParameterNames() {
159         return null;
160     }
161
162     public void addExpectedAttribute(String JavaDoc key, Object JavaDoc value) {
163         attributes.addExpected(new MapEntry(key, value));
164     }
165
166     public void setAttribute(String JavaDoc key, Object JavaDoc value) {
167         attributes.addActual(new MapEntry(key, value));
168     }
169 }
170
Popular Tags