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