01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package javax.servlet.http;
05:
06: import java.util.Enumeration;
07: import java.util.Hashtable;
08:
09: import javax.servlet.ServletContext;
10:
11: public class MockHttpSession implements HttpSession {
12:
13: private final Hashtable attributes = new Hashtable();
14: private long createMillis = 0;
15: private String id;
16: private long lastAccessTime;
17: private int maxIntactiveSeconds;
18: private boolean isNew;
19:
20: public MockHttpSession(String id) {
21: this .id = id;
22: }
23:
24: public Object getAttribute(String s) {
25: return attributes.get(s);
26: }
27:
28: public Enumeration getAttributeNames() {
29: return attributes.keys();
30: }
31:
32: public long getCreationTime() {
33: return createMillis;
34: }
35:
36: public String getId() {
37: return id;
38: }
39:
40: public long getLastAccessedTime() {
41: return lastAccessTime;
42: }
43:
44: public int getMaxInactiveInterval() {
45: return maxIntactiveSeconds;
46: }
47:
48: public ServletContext getServletContext() {
49: return null;
50: }
51:
52: public HttpSessionContext getSessionContext() {
53: return null;
54: }
55:
56: public Object getValue(String s) {
57: return getAttribute(s);
58: }
59:
60: public String[] getValueNames() {
61: return (String[]) attributes.keySet().toArray(
62: new String[attributes.size()]);
63: }
64:
65: public void invalidate() {
66: // NOTE: implement
67: }
68:
69: public boolean isNew() {
70: return isNew;
71: }
72:
73: public void putValue(String s, Object obj) {
74: setAttribute(s, obj);
75: }
76:
77: public void removeAttribute(String s) {
78: attributes.remove(s);
79: }
80:
81: public void removeValue(String s) {
82: removeAttribute(s);
83: }
84:
85: public void setAttribute(String s, Object obj) {
86: attributes.put(s, obj);
87: }
88:
89: public void setMaxInactiveInterval(int i) {
90: this.maxIntactiveSeconds = i;
91: }
92:
93: }
|