1   /*
2    * Copyright 1999-2004 The Apache Software Foundation
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.commons.chain.web.servlet;
17  
18  
19  import org.apache.commons.chain.web.MockEnumeration;
20  
21  import javax.servlet.ServletContext;
22  import javax.servlet.http.HttpSession;
23  import javax.servlet.http.HttpSessionContext;
24  import java.util.Enumeration;
25  import java.util.HashMap;
26  
27  
28  
29  // Mock Object for HttpSession (Version 2.3)
30  public class MockHttpSession implements HttpSession {
31  
32  
33  
34      public MockHttpSession() {
35          super();
36      }
37  
38  
39      public MockHttpSession(ServletContext servletContext) {
40          super();
41          setServletContext(servletContext);
42      }
43  
44  
45  
46      protected HashMap attributes = new HashMap();
47      protected ServletContext servletContext = null;
48  
49  
50      // --------------------------------------------------------- Public Methods
51  
52  
53      public void setServletContext(ServletContext servletContext) {
54          this.servletContext = servletContext;
55      }
56  
57  
58      // ---------------------------------------------------- HttpSession Methods
59  
60  
61      public Object getAttribute(String name) {
62          return (attributes.get(name));
63      }
64  
65  
66      public Enumeration getAttributeNames() {
67          return (new MockEnumeration(attributes.keySet().iterator()));
68      }
69  
70  
71      public long getCreationTime() {
72          throw new UnsupportedOperationException();
73      }
74  
75  
76      public String getId() {
77          throw new UnsupportedOperationException();
78      }
79  
80  
81      public long getLastAccessedTime() {
82          throw new UnsupportedOperationException();
83      }
84  
85  
86      public int getMaxInactiveInterval() {
87          throw new UnsupportedOperationException();
88      }
89  
90  
91      public ServletContext getServletContext() {
92          return (this.servletContext);
93      }
94  
95  
96      public HttpSessionContext getSessionContext() {
97          throw new UnsupportedOperationException();
98      }
99  
100 
101     public Object getValue(String name) {
102         throw new UnsupportedOperationException();
103     }
104 
105 
106     public String[] getValueNames() {
107         throw new UnsupportedOperationException();
108     }
109 
110 
111     public void invalidate() {
112         throw new UnsupportedOperationException();
113     }
114 
115 
116     public boolean isNew() {
117         throw new UnsupportedOperationException();
118     }
119 
120 
121     public void putValue(String name, Object value) {
122         throw new UnsupportedOperationException();
123     }
124 
125 
126     public void removeAttribute(String name) {
127         attributes.remove(name);
128     }
129 
130 
131     public void removeValue(String name) {
132         throw new UnsupportedOperationException();
133     }
134 
135 
136     public void setAttribute(String name, Object value) {
137         if (value == null) {
138             attributes.remove(name);
139         } else {
140             attributes.put(name, value);
141         }
142     }
143 
144 
145     public void setMaxInactiveInterval(int interval) {
146         throw new UnsupportedOperationException();
147     }
148 
149 
150 }