1 5 package com.opensymphony.webwork.views.jsp; 6 7 import com.mockobjects.servlet.MockHttpServletRequest; 8 import junit.framework.AssertionFailedError; 9 10 import javax.servlet.http.HttpSession ; 11 import java.util.*; 12 13 14 20 public class WebWorkMockHttpServletRequest extends MockHttpServletRequest { 21 23 Locale locale = Locale.US; 24 private Map attributes = new HashMap(); 25 private Map parameterMap = new HashMap(); 26 private String context = ""; 27 private String pathInfo = ""; 28 private String queryString; 29 private String requestURI; 30 private String scheme; 31 private String serverName; 32 private int serverPort; 33 private String encoding; 34 35 37 public void setAttribute(String s, Object o) { 38 attributes.put(s, o); 39 } 40 41 public Object getAttribute(String s) { 42 return attributes.get(s); 43 } 44 45 public Enumeration getAttributeNames() { 46 Vector v = new Vector(); 47 v.addAll(attributes.keySet()); 48 49 return v.elements(); 50 } 51 52 public String getContextPath() { 53 return this.context; 54 } 55 56 public void setLocale(Locale locale) { 57 this.locale = locale; 58 } 59 60 public Locale getLocale() { 61 return locale; 62 } 63 64 public void setCharacterEncoding(String s) { 65 this.encoding = s; 66 } 67 68 public String getCharacterEncoding() { 69 return encoding; 70 } 71 72 public void setParameterMap(Map parameterMap) { 73 this.parameterMap = parameterMap; 74 } 75 76 public Map getParameterMap() { 77 return parameterMap; 78 } 79 80 public String getPathInfo() { 81 return pathInfo; 82 } 83 84 public void setQueryString(String queryString) { 85 this.queryString = queryString; 86 } 87 88 public String getQueryString() { 89 return queryString; 90 } 91 92 public void setRequestURI(String requestURI) { 93 this.requestURI = requestURI; 94 } 95 96 public String getRequestURI() { 97 return requestURI; 98 } 99 100 public void setScheme(String scheme) { 101 this.scheme = scheme; 102 } 103 104 public String getScheme() { 105 return scheme; 106 } 107 108 public void setServerName(String serverName) { 109 this.serverName = serverName; 110 } 111 112 public String getServerName() { 113 return serverName; 114 } 115 116 public void setServerPort(int serverPort) { 117 this.serverPort = serverPort; 118 } 119 120 public int getServerPort() { 121 return serverPort; 122 } 123 124 public HttpSession getSession() { 125 HttpSession session = null; 126 127 try { 128 session = super.getSession(); 129 } catch (AssertionFailedError e) { 130 } 132 133 if (session == null) { 134 session = new WebWorkMockHttpSession(); 135 setSession(session); 136 } 137 138 return session; 139 } 140 141 public void setupGetContext(String context) { 142 this.context = context; 143 } 144 145 public void setupGetPathInfo(String pathInfo) { 146 this.pathInfo = pathInfo; 147 } 148 } 149 | Popular Tags |