View Javadoc
1   /*
2    * $Source$
3    * $Revision$
4    *
5    * Copyright (C) 2009 Tim Pizey
6    *
7    * Part of Melati (http://melati.org), a framework for the rapid
8    * development of clean, maintainable web applications.
9    *
10   * Melati is free software; Permission is granted to copy, distribute
11   * and/or modify this software under the terms either:
12   *
13   * a) the GNU General Public License as published by the Free Software
14   *    Foundation; either version 2 of the License, or (at your option)
15   *    any later version,
16   *
17   *    or
18   *
19   * b) any version of the Melati Software License, as published
20   *    at http://melati.org
21   *
22   * You should have received a copy of the GNU General Public License and
23   * the Melati Software License along with this program;
24   * if not, write to the Free Software Foundation, Inc.,
25   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA to obtain the
26   * GNU General Public License and visit http://melati.org to obtain the
27   * Melati Software License.
28   *
29   * Feel free to contact the Developers of Melati (http://melati.org),
30   * if you would like to work out a different arrangement than the options
31   * outlined here.  It is our intention to allow Melati to be used by as
32   * wide an audience as possible.
33   *
34   * This program is distributed in the hope that it will be useful,
35   * but WITHOUT ANY WARRANTY; without even the implied warranty of
36   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37   * GNU General Public License for more details.
38   *
39   * Contact details for copyright holder:
40   *
41   *     Tim Pizey <timp At paneris.org>
42   *     http://paneris.org/~timp
43   */
44  
45  package org.melati.servlet.test;
46  
47  import java.util.Enumeration;
48  import java.util.Hashtable;
49  
50  import javax.servlet.ServletContext;
51  import javax.servlet.http.HttpSession;
52  import javax.servlet.http.HttpSessionContext;
53  
54  /**
55   * @author timp
56   * @since  26 Feb 2009
57   *
58   */
59  @SuppressWarnings("deprecation")
60  public class MockHttpSession implements HttpSession {
61    
62    private Hashtable<String,Object> values;
63  
64    /**
65     * Constructor.
66     */
67    public MockHttpSession() {
68      values = new Hashtable<String,Object>();
69    }
70  
71    /**
72     * {@inheritDoc}
73     * @see javax.servlet.http.HttpSession#getAttribute(java.lang.String)
74     */
75    public Object getAttribute(String name) {
76      return values.get(name);
77      }
78  
79    /**
80     * {@inheritDoc}
81     * @see javax.servlet.http.HttpSession#getAttributeNames()
82     */
83    public Enumeration<String> getAttributeNames() {
84      throw new RuntimeException("TODO No one else has ever called this method."
85          + " Do you really want to start now?");
86  
87    }
88  
89    /**
90     * {@inheritDoc}
91     * @see javax.servlet.http.HttpSession#getCreationTime()
92     */
93    public long getCreationTime() {
94      throw new RuntimeException("TODO No one else has ever called this method."
95          + " Do you really want to start now?");
96  
97    }
98  
99    /**
100    * {@inheritDoc}
101    * @see javax.servlet.http.HttpSession#getId()
102    */
103   public String getId() {
104     return "1";
105   }
106 
107   /**
108    * {@inheritDoc}
109    * @see javax.servlet.http.HttpSession#getLastAccessedTime()
110    */
111   public long getLastAccessedTime() {
112     throw new RuntimeException("TODO No one else has ever called this method."
113         + " Do you really want to start now?");
114 
115   }
116 
117   /**
118    * {@inheritDoc}
119    * @see javax.servlet.http.HttpSession#getMaxInactiveInterval()
120    */
121   public int getMaxInactiveInterval() {
122     throw new RuntimeException("TODO No one else has ever called this method."
123         + " Do you really want to start now?");
124 
125   }
126 
127   /**
128    * {@inheritDoc}
129    * @see javax.servlet.http.HttpSession#getServletContext()
130    */
131   public ServletContext getServletContext() {
132     throw new RuntimeException("TODO No one else has ever called this method."
133         + " Do you really want to start now?");
134 
135   }
136 
137   /**
138    * {@inheritDoc}
139    * @see javax.servlet.http.HttpSession#getSessionContext()
140    */
141   public HttpSessionContext getSessionContext() {
142     throw new RuntimeException("TODO No one else has ever called this method."
143         + " Do you really want to start now?");
144   }
145 
146   /**
147    * {@inheritDoc}
148    * @see javax.servlet.http.HttpSession#getValue(java.lang.String)
149    */
150   public Object getValue(String name) {
151     throw new RuntimeException("TODO No one else has ever called this method."
152         + " Do you really want to start now?");
153 
154   }
155 
156   /**
157    * {@inheritDoc}
158    * @see javax.servlet.http.HttpSession#getValueNames()
159    */
160   public String[] getValueNames() {
161     throw new RuntimeException("TODO No one else has ever called this method."
162         + " Do you really want to start now?");
163 
164   }
165 
166   /**
167    * {@inheritDoc}
168    * @see javax.servlet.http.HttpSession#invalidate()
169    */
170   public void invalidate() {
171     throw new RuntimeException("TODO No one else has ever called this method."
172         + " Do you really want to start now?");
173 
174   }
175 
176   /**
177    * {@inheritDoc}
178    * @see javax.servlet.http.HttpSession#isNew()
179    */
180   public boolean isNew() {
181     throw new RuntimeException("TODO No one else has ever called this method."
182         + " Do you really want to start now?");
183 
184   }
185 
186   /**
187    * {@inheritDoc}
188    * @see javax.servlet.http.HttpSession#putValue(java.lang.String, java.lang.Object)
189    */
190   public void putValue(String name, Object value) {
191     throw new RuntimeException("TODO No one else has ever called this method."
192         + " Do you really want to start now?");
193 
194   }
195 
196   /**
197    * {@inheritDoc}
198    * @see javax.servlet.http.HttpSession#removeAttribute(java.lang.String)
199    */
200   public void removeAttribute(String name) {
201     values.remove(name);
202   }
203 
204   /**
205    * {@inheritDoc}
206    * @see javax.servlet.http.HttpSession#removeValue(java.lang.String)
207    */
208   public void removeValue(String name) {
209     throw new RuntimeException("TODO No one else has ever called this method."
210         + " Do you really want to start now?");
211 
212   }
213 
214   /**
215    * {@inheritDoc}
216    * @see javax.servlet.http.HttpSession#setAttribute(java.lang.String, java.lang.Object)
217    */
218   public void setAttribute(String name, Object value) {
219     values.put(name, value);
220   }
221 
222   /**
223    * {@inheritDoc}
224    * @see javax.servlet.http.HttpSession#setMaxInactiveInterval(int)
225    */
226   public void setMaxInactiveInterval(int interval) {
227     throw new RuntimeException("TODO No one else has ever called this method."
228         + " Do you really want to start now?");
229 
230   }
231 
232 }