1 7 package com.inversoft.junit.internal.http; 8 9 10 import java.util.Enumeration ; 11 import java.util.HashMap ; 12 import java.util.Iterator ; 13 import java.util.Map ; 14 import javax.servlet.http.HttpSessionContext ; 15 import javax.servlet.ServletContext ; 16 import javax.servlet.http.HttpSession ; 17 18 19 26 public class MockHttpSession implements HttpSession { 27 28 private Map attributes; 29 private long creation; 30 private int interval; 31 private long lastAccessed; 32 private ServletContext context; 33 34 37 public MockHttpSession() { 38 attributes = new HashMap (); 39 creation = System.currentTimeMillis(); 40 interval = 1800; 41 lastAccessed = System.currentTimeMillis(); 42 context = new MockServletContext(); 43 } 44 45 47 public long getCreationTime() { 48 lastAccessed = System.currentTimeMillis(); 49 return creation; 50 } 51 52 54 public String getId() { 55 lastAccessed = System.currentTimeMillis(); 56 return "non-valid"; 57 } 58 59 61 public int getMaxInactiveInterval() { 62 lastAccessed = System.currentTimeMillis(); 63 return interval; 64 } 65 66 68 public void setMaxInactiveInterval(int interval) { 69 this.interval = interval; 70 lastAccessed = System.currentTimeMillis(); 71 } 72 73 75 public long getLastAccessedTime() { 76 lastAccessed = System.currentTimeMillis(); 77 return lastAccessed; 78 } 79 80 82 public ServletContext getServletContext() { 83 lastAccessed = System.currentTimeMillis(); 84 return context; 85 } 86 87 90 public HttpSessionContext getSessionContext() { 91 throw new UnsupportedOperationException (); 92 } 93 94 96 public Object getAttribute(String name) { 97 lastAccessed = System.currentTimeMillis(); 98 return attributes.get(name); 99 } 100 101 104 public Object getValue(String name) { 105 throw new UnsupportedOperationException (); 106 } 107 108 110 public void removeAttribute(String name) { 111 lastAccessed = System.currentTimeMillis(); 112 attributes.remove(name); 113 } 114 115 117 public Enumeration getAttributeNames() { 118 lastAccessed = System.currentTimeMillis(); 119 final Iterator iter = attributes.keySet().iterator(); 120 return new Enumeration () { 121 public boolean hasMoreElements() { 122 return iter.hasNext(); 123 } 124 public Object nextElement() { 125 return iter.next(); 126 } 127 }; 128 } 129 130 133 public String [] getValueNames() { 134 throw new UnsupportedOperationException (); 135 } 136 137 139 public void setAttribute(String name, Object value) { 140 lastAccessed = System.currentTimeMillis(); 141 attributes.put(name, value); 142 } 143 144 147 public void putValue(String name, Object value) { 148 throw new UnsupportedOperationException (); 149 } 150 151 154 public void removeValue(String A) { 155 throw new UnsupportedOperationException (); 156 } 157 158 160 public void invalidate() { 161 lastAccessed = System.currentTimeMillis(); 162 } 163 164 166 public boolean isNew() { 167 lastAccessed = System.currentTimeMillis(); 168 return false; 169 } 170 } 171 | Popular Tags |