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 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  import java.util.Map;
28  import java.util.Vector;
29  
30  public class MockHttpSession implements HttpSession {
31  
32    private Map<String, Object> attributes = new HashMap<>();
33  
34    @Override
35    public Object getAttribute(final String s) {
36      return attributes.get(s);
37    }
38  
39    @Override
40    public Enumeration<String> getAttributeNames() {
41      return new Vector(attributes.keySet()).elements();
42    }
43  
44    @Override
45    public long getCreationTime() {
46      return 0;
47    }
48  
49    @Override
50    public String getId() {
51      return null;
52    }
53  
54    @Override
55    public long getLastAccessedTime() {
56      return 0;
57    }
58  
59    @Override
60    public int getMaxInactiveInterval() {
61      return 0;
62    }
63  
64    /** @deprecated */
65    @Deprecated
66    @Override
67    public HttpSessionContext getSessionContext() {
68      return null;
69    }
70  
71    /** @deprecated */
72    @Deprecated
73    @Override
74    public Object getValue(final String s) {
75      return null;
76    }
77  
78    /** @deprecated */
79    @Deprecated
80    @Override
81    public String[] getValueNames() {
82      return new String[0];
83    }
84  
85    @Override
86    public void invalidate() {
87    }
88  
89    @Override
90    public boolean isNew() {
91      return false;
92    }
93  
94    /** @deprecated */
95    @Deprecated
96    @Override
97    public void putValue(final String s, final Object o) {
98    }
99  
100   @Override
101   public void removeAttribute(final String s) {
102     attributes.remove(s);
103   }
104 
105   @Override
106   public void removeValue(final String s) {
107   }
108 
109   @Override
110   public void setAttribute(final String s, final Object o) {
111     attributes.put(s, o);
112   }
113 
114   @Override
115   public void setMaxInactiveInterval(final int i) {
116   }
117 
118   @Override
119   public ServletContext getServletContext() {
120     return null;
121   }
122 }