1 19 package za.org.coefficient.util.testing; 20 21 import java.util.Enumeration ; 22 import java.util.Map ; 23 import java.util.Vector ; 24 25 import javax.servlet.ServletContext ; 26 import javax.servlet.http.HttpSession ; 27 import javax.servlet.http.HttpSessionContext ; 28 29 40 public class TestingHttpSession implements HttpSession { 41 42 private long created = System.currentTimeMillis(); 43 private Map data; 44 45 public TestingHttpSession(Map sessionData){ 46 this.data = sessionData; 47 } 48 49 52 public long getCreationTime() { 53 return created; 54 } 55 56 59 public String getId() { 60 return "sessionID"; 61 } 62 63 66 public long getLastAccessedTime() { 67 return System.currentTimeMillis() - 2000; 68 } 69 70 73 public ServletContext getServletContext() { 74 throw new UnsupportedOperationException (); 75 } 76 77 80 public void setMaxInactiveInterval(int arg0) { 81 throw new UnsupportedOperationException (); 82 } 83 84 87 public int getMaxInactiveInterval() { 88 return 99999; 89 } 90 91 94 public HttpSessionContext getSessionContext() { 95 throw new UnsupportedOperationException (); 96 } 97 98 101 public Object getAttribute(String arg0) { 102 return data.get(arg0); 103 } 104 105 108 public Object getValue(String arg0) { 109 return getAttribute(arg0); 110 } 111 112 115 public Enumeration getAttributeNames() { 116 return new Vector (data.keySet()).elements(); 117 } 118 119 122 public String [] getValueNames() { 123 return (String [])data.keySet().toArray(new String []{}); 124 } 125 126 129 public void setAttribute(String arg0, Object arg1) { 130 data.put(arg0, arg1); 131 } 132 133 136 public void putValue(String arg0, Object arg1) { 137 setAttribute(arg0, arg1); 138 139 } 140 141 144 public void removeAttribute(String arg0) { 145 data.remove(arg0); 146 } 147 148 151 public void removeValue(String arg0) { 152 removeAttribute(arg0); 153 } 154 155 158 public void invalidate() { 159 data.clear(); 160 } 161 162 165 public boolean isNew() { 166 return false; 167 } 168 169 } 170 | Popular Tags |