View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.internal.mock.servlet;
21  
22  import org.apache.commons.collections.iterators.IteratorEnumeration;
23  
24  import javax.servlet.ServletContext;
25  import javax.servlet.http.HttpSession;
26  import javax.servlet.http.HttpSessionContext;
27  import java.util.Enumeration;
28  import java.util.HashMap;
29  import java.util.Map;
30  
31  public class MockHttpSession implements HttpSession {
32  
33    private Map<String, Object> attributes = new HashMap<String, Object>();
34  
35    @Override
36    public Object getAttribute(final String s) {
37      return attributes.get(s);
38    }
39  
40    @Override
41    public Enumeration<String> getAttributeNames() {
42      return new IteratorEnumeration(attributes.keySet().iterator());
43    }
44  
45    @Override
46    public long getCreationTime() {
47      return 0;
48    }
49  
50    @Override
51    public String getId() {
52      return null;
53    }
54  
55    @Override
56    public long getLastAccessedTime() {
57      return 0;
58    }
59  
60    @Override
61    public int getMaxInactiveInterval() {
62      return 0;
63    }
64  
65    /** @deprecated */
66    @Deprecated
67    @Override
68    public HttpSessionContext getSessionContext() {
69      return null;
70    }
71  
72    /** @deprecated */
73    @Deprecated
74    @Override
75    public Object getValue(final String s) {
76      return null;
77    }
78  
79    /** @deprecated */
80    @Deprecated
81    @Override
82    public String[] getValueNames() {
83      return new String[0];
84    }
85  
86    @Override
87    public void invalidate() {
88    }
89  
90    @Override
91    public boolean isNew() {
92      return false;
93    }
94  
95    /** @deprecated */
96    @Deprecated
97    @Override
98    public void putValue(final String s, final Object o) {
99    }
100 
101   @Override
102   public void removeAttribute(final String s) {
103     attributes.remove(s);
104   }
105 
106   @Override
107   public void removeValue(final String s) {
108   }
109 
110   @Override
111   public void setAttribute(final String s, final Object o) {
112     attributes.put(s, o);
113   }
114 
115   @Override
116   public void setMaxInactiveInterval(final int i) {
117   }
118 
119   @Override
120   public ServletContext getServletContext() {
121     return null;
122   }
123 }