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 attributes = new HashMap();
34  
35    @Override
36    public Object getAttribute(final String s) {
37      return attributes.get(s);
38    }
39  
40    @Override
41    public Enumeration 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    @Override
67    public HttpSessionContext getSessionContext() {
68      return null;
69    }
70  
71    @Override
72    public Object getValue(final String s) {
73      return null;
74    }
75  
76    @Override
77    public String[] getValueNames() {
78      return new String[0];
79    }
80  
81    @Override
82    public void invalidate() {
83    }
84  
85    @Override
86    public boolean isNew() {
87      return false;
88    }
89  
90    @Override
91    public void putValue(final String s, final Object o) {
92    }
93  
94    @Override
95    public void removeAttribute(final String s) {
96      attributes.remove(s);
97    }
98  
99    @Override
100   public void removeValue(final String s) {
101   }
102 
103   @Override
104   public void setAttribute(final String s, final Object o) {
105     attributes.put(s, o);
106   }
107 
108   @Override
109   public void setMaxInactiveInterval(final int i) {
110   }
111 
112   @Override
113   public ServletContext getServletContext() {
114     return null;
115   }
116 }