001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2007
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.tests.embedded.jsf.util;
034:
035: import javax.faces.context.ExternalContext;
036: import javax.servlet.RequestDispatcher;
037: import javax.servlet.Servlet;
038: import javax.servlet.ServletContext;
039: import javax.servlet.ServletException;
040: import java.io.IOException;
041: import java.io.InputStream;
042: import java.net.MalformedURLException;
043: import java.net.URL;
044: import java.security.Principal;
045: import java.util.*;
046:
047: /**
048: * Mock external faces context for unit testing. If your code needs a method,
049: * add a reasonable (dummy) implementation.
050: *
051: * @author Daniel Lichtenberger (daniel.lichtenberger@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
052: *
053: */
054: public class MockExternalContext extends ExternalContext {
055: public static class MockServletContext implements ServletContext {
056: public void setAttribute(String s, Object o) {
057: //To change body of implemented methods use File | Settings | File Templates.
058: }
059:
060: public void removeAttribute(String s) {
061: //To change body of implemented methods use File | Settings | File Templates.
062: }
063:
064: public String getServletContextName() {
065: return null; //To change body of implemented methods use File | Settings | File Templates.
066: }
067:
068: public String getContextPath() {
069: return null; //To change body of implemented methods use File | Settings | File Templates.
070: }
071:
072: public ServletContext getContext(String s) {
073: return null; //To change body of implemented methods use File | Settings | File Templates.
074: }
075:
076: public int getMajorVersion() {
077: return 0; //To change body of implemented methods use File | Settings | File Templates.
078: }
079:
080: public int getMinorVersion() {
081: return 0; //To change body of implemented methods use File | Settings | File Templates.
082: }
083:
084: public String getMimeType(String s) {
085: return null; //To change body of implemented methods use File | Settings | File Templates.
086: }
087:
088: public Set getResourcePaths(String s) {
089: return null; //To change body of implemented methods use File | Settings | File Templates.
090: }
091:
092: public URL getResource(String s) throws MalformedURLException {
093: return null; //To change body of implemented methods use File | Settings | File Templates.
094: }
095:
096: public InputStream getResourceAsStream(String s) {
097: return null; //To change body of implemented methods use File | Settings | File Templates.
098: }
099:
100: public RequestDispatcher getRequestDispatcher(String s) {
101: return null; //To change body of implemented methods use File | Settings | File Templates.
102: }
103:
104: public RequestDispatcher getNamedDispatcher(String s) {
105: return null; //To change body of implemented methods use File | Settings | File Templates.
106: }
107:
108: public Servlet getServlet(String s) throws ServletException {
109: return null; //To change body of implemented methods use File | Settings | File Templates.
110: }
111:
112: public Enumeration getServlets() {
113: return null; //To change body of implemented methods use File | Settings | File Templates.
114: }
115:
116: public Enumeration getServletNames() {
117: return null; //To change body of implemented methods use File | Settings | File Templates.
118: }
119:
120: public void log(String s) {
121: //To change body of implemented methods use File | Settings | File Templates.
122: }
123:
124: public void log(Exception e, String s) {
125: //To change body of implemented methods use File | Settings | File Templates.
126: }
127:
128: public void log(String s, Throwable throwable) {
129: //To change body of implemented methods use File | Settings | File Templates.
130: }
131:
132: public String getRealPath(String s) {
133: return null; //To change body of implemented methods use File | Settings | File Templates.
134: }
135:
136: public String getServerInfo() {
137: return null; //To change body of implemented methods use File | Settings | File Templates.
138: }
139:
140: public String getInitParameter(String s) {
141: return null; //To change body of implemented methods use File | Settings | File Templates.
142: }
143:
144: public Enumeration getInitParameterNames() {
145: return null; //To change body of implemented methods use File | Settings | File Templates.
146: }
147:
148: public Object getAttribute(String s) {
149: return null; //To change body of implemented methods use File | Settings | File Templates.
150: }
151:
152: public Enumeration getAttributeNames() {
153: return null; //To change body of implemented methods use File | Settings | File Templates.
154: }
155: }
156:
157: private Map requestParameterMap = new HashMap();
158: private Map requestMap = new HashMap();
159: private Map applicationMap = new HashMap();
160: private Map sessionMap = new HashMap();
161:
162: @Override
163: public void dispatch(String path) throws IOException {
164: throw new RuntimeException("not implemented");
165: }
166:
167: @Override
168: public String encodeActionURL(String url) {
169: throw new RuntimeException("not implemented");
170: }
171:
172: @Override
173: public String encodeNamespace(String name) {
174: throw new RuntimeException("not implemented");
175: }
176:
177: @Override
178: public String encodeResourceURL(String url) {
179: throw new RuntimeException("not implemented");
180: }
181:
182: @Override
183: public Map getApplicationMap() {
184: return applicationMap;
185: }
186:
187: @Override
188: public String getAuthType() {
189: throw new RuntimeException("not implemented");
190: }
191:
192: @Override
193: public Object getContext() {
194: return new MockServletContext();
195: }
196:
197: @Override
198: public String getInitParameter(String name) {
199: throw new RuntimeException("not implemented");
200: }
201:
202: @Override
203: public Map getInitParameterMap() {
204: throw new RuntimeException("not implemented");
205: }
206:
207: @Override
208: public String getRemoteUser() {
209: throw new RuntimeException("not implemented");
210: }
211:
212: @Override
213: public Object getRequest() {
214: throw new RuntimeException("not implemented");
215: }
216:
217: @Override
218: public String getRequestContextPath() {
219: throw new RuntimeException("not implemented");
220: }
221:
222: @Override
223: public Map getRequestCookieMap() {
224: throw new RuntimeException("not implemented");
225: }
226:
227: @Override
228: public Map getRequestHeaderMap() {
229: throw new RuntimeException("not implemented");
230: }
231:
232: @Override
233: public Map getRequestHeaderValuesMap() {
234: throw new RuntimeException("not implemented");
235: }
236:
237: @Override
238: public Locale getRequestLocale() {
239: throw new RuntimeException("not implemented");
240: }
241:
242: @Override
243: public Iterator getRequestLocales() {
244: throw new RuntimeException("not implemented");
245: }
246:
247: @Override
248: public Map getRequestMap() {
249: return requestMap;
250: }
251:
252: @Override
253: public Map getRequestParameterMap() {
254: return requestParameterMap;
255: }
256:
257: @Override
258: public Iterator getRequestParameterNames() {
259: return requestParameterMap.keySet().iterator();
260: }
261:
262: @Override
263: public Map getRequestParameterValuesMap() {
264: throw new RuntimeException("not implemented");
265: }
266:
267: @Override
268: public String getRequestPathInfo() {
269: throw new RuntimeException("not implemented");
270: }
271:
272: @Override
273: public String getRequestServletPath() {
274: throw new RuntimeException("not implemented");
275: }
276:
277: @Override
278: public URL getResource(String path) throws MalformedURLException {
279: throw new RuntimeException("not implemented");
280: }
281:
282: @Override
283: public InputStream getResourceAsStream(String path) {
284: throw new RuntimeException("not implemented");
285: }
286:
287: @Override
288: public Set getResourcePaths(String path) {
289: throw new RuntimeException("not implemented");
290: }
291:
292: @Override
293: public Object getResponse() {
294: throw new RuntimeException("not implemented");
295: }
296:
297: @Override
298: public Object getSession(boolean create) {
299: throw new RuntimeException("not implemented");
300: }
301:
302: @Override
303: public Map getSessionMap() {
304: return sessionMap;
305: }
306:
307: @Override
308: public Principal getUserPrincipal() {
309: throw new RuntimeException("not implemented");
310: }
311:
312: @Override
313: public boolean isUserInRole(String role) {
314: throw new RuntimeException("not implemented");
315: }
316:
317: @Override
318: public void log(String message, Throwable exception) {
319: throw new RuntimeException("not implemented");
320: }
321:
322: @Override
323: public void log(String message) {
324: throw new RuntimeException("not implemented");
325: }
326:
327: @Override
328: public void redirect(String url) throws IOException {
329: throw new RuntimeException("not implemented");
330: }
331:
332: }
|