1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts.mock;
22
23 import javax.servlet.ServletContext;
24 import javax.servlet.http.HttpSession;
25 import javax.servlet.http.HttpSessionContext;
26
27 import java.util.Enumeration;
28 import java.util.HashMap;
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 public class MockHttpSession implements HttpSession {
47
48
49
50
51
52 protected HashMap attributes = new HashMap();
53
54
55
56
57 protected ServletContext servletContext = null;
58
59
60 public MockHttpSession() {
61 super();
62 }
63
64 public MockHttpSession(ServletContext servletContext) {
65 super();
66 setServletContext(servletContext);
67 }
68
69
70 public void setServletContext(ServletContext servletContext) {
71 this.servletContext = servletContext;
72 }
73
74
75 public Object getAttribute(String name) {
76 return (attributes.get(name));
77 }
78
79 public Enumeration getAttributeNames() {
80 return (new MockEnumeration(attributes.keySet().iterator()));
81 }
82
83 public long getCreationTime() {
84 throw new UnsupportedOperationException();
85 }
86
87 public String getId() {
88 throw new UnsupportedOperationException();
89 }
90
91 public long getLastAccessedTime() {
92 throw new UnsupportedOperationException();
93 }
94
95 public int getMaxInactiveInterval() {
96 throw new UnsupportedOperationException();
97 }
98
99 public ServletContext getServletContext() {
100 return (this.servletContext);
101 }
102
103 public HttpSessionContext getSessionContext() {
104 throw new UnsupportedOperationException();
105 }
106
107 public Object getValue(String name) {
108 throw new UnsupportedOperationException();
109 }
110
111 public String[] getValueNames() {
112 throw new UnsupportedOperationException();
113 }
114
115 public void invalidate() {
116 throw new UnsupportedOperationException();
117 }
118
119 public boolean isNew() {
120 throw new UnsupportedOperationException();
121 }
122
123 public void putValue(String name, Object value) {
124 throw new UnsupportedOperationException();
125 }
126
127 public void removeAttribute(String name) {
128 attributes.remove(name);
129 }
130
131 public void removeValue(String name) {
132 throw new UnsupportedOperationException();
133 }
134
135 public void setAttribute(String name, Object value) {
136 if (value == null) {
137 attributes.remove(name);
138 } else {
139 attributes.put(name, value);
140 }
141 }
142
143 public void setMaxInactiveInterval(int interval) {
144 throw new UnsupportedOperationException();
145 }
146 }