1   package com.atlassian.core.ofbiz.test.mock;
2   
3   import com.mockobjects.servlet.MockHttpServletRequest;
4   
5   import javax.servlet.http.Cookie;
6   import java.util.HashMap;
7   import java.util.Locale;
8   import java.util.Map;
9   
10  /**
11   * An extension of the MockHttpServletRequest which doesn't error when cookies are queried, and maintains a map
12   * of request attributes (unlike MockHttpServletRequest which requires you to set them up in advance).
13   */
14  public class MockAtlassianServletRequest extends MockHttpServletRequest {
15      Map requestAttributes = new HashMap();
16      private String scheme;
17      private String serverName;
18      private int serverPort;
19      private String contextPath;
20  
21      public Object getAttribute(String s) {
22          return requestAttributes.get(s);
23      }
24  
25      public void setAttribute(String s, Object o) {
26          requestAttributes.put(s, o);
27      }
28  
29      public Locale getLocale() {
30          return null;
31      }
32  
33      public Cookie[] getCookies() {
34          return new Cookie[0];
35      }
36  
37      public String getScheme() {
38          return scheme;
39      }
40  
41      public String getServerName() {
42          return serverName;
43      }
44  
45      public int getServerPort() {
46          return serverPort;
47      }
48  
49      public String getContextPath() {
50          return contextPath;
51      }
52  
53      public void setScheme(String scheme) {
54          this.scheme = scheme;
55      }
56  
57      public void setServerName(String serverName) {
58          this.serverName = serverName;
59      }
60  
61      public void setServerPort(int serverPort) {
62          this.serverPort = serverPort;
63      }
64  
65      public void setContextPath(String contextPath) {
66          this.contextPath = contextPath;
67      }
68  }