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