View Javadoc
1   /*
2    * MIT License
3    *
4    * Copyright (c) 2010-2024 The Waffle Project Contributors: https://github.com/Waffle/waffle/graphs/contributors
5    *
6    * Permission is hereby granted, free of charge, to any person obtaining a copy
7    * of this software and associated documentation files (the "Software"), to deal
8    * in the Software without restriction, including without limitation the rights
9    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10   * copies of the Software, and to permit persons to whom the Software is
11   * furnished to do so, subject to the following conditions:
12   *
13   * The above copyright notice and this permission notice shall be included in all
14   * copies or substantial portions of the Software.
15   *
16   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22   * SOFTWARE.
23   */
24  package waffle.mock.http;
25  
26  import com.google.errorprone.annotations.InlineMe;
27  
28  import java.util.Enumeration;
29  import java.util.HashMap;
30  import java.util.Map;
31  
32  import javax.servlet.ServletContext;
33  import javax.servlet.http.HttpSession;
34  import javax.servlet.http.HttpSessionContext;
35  
36  /**
37   * Simple Http Session.
38   */
39  public class SimpleHttpSession implements HttpSession {
40  
41      /** The attributes. */
42      private final Map<String, Object> attributes = new HashMap<>();
43  
44      @Override
45      public Object getAttribute(final String attributeName) {
46          return this.attributes.get(attributeName);
47      }
48  
49      @Override
50      public Enumeration<String> getAttributeNames() {
51          return null;
52      }
53  
54      @Override
55      public long getCreationTime() {
56          return 0;
57      }
58  
59      @Override
60      public String getId() {
61          return null;
62      }
63  
64      @Override
65      public long getLastAccessedTime() {
66          return 0;
67      }
68  
69      @Override
70      public int getMaxInactiveInterval() {
71          return 0;
72      }
73  
74      @Override
75      public ServletContext getServletContext() {
76          return null;
77      }
78  
79      /**
80       * Simply remove this if it is ever actually removed from servlet-api
81       *
82       * @deprecated Remove this once servlet does.
83       */
84      @Deprecated
85      @InlineMe(replacement = "null")
86      @Override
87      public final HttpSessionContext getSessionContext() {
88          return null;
89      }
90  
91      /**
92       * Simply remove this if it is ever actually removed from servlet-api
93       *
94       * @deprecated Remove this once servlet does.
95       */
96      @Deprecated
97      @InlineMe(replacement = "null")
98      @Override
99      public final Object getValue(final String arg0) {
100         return null;
101     }
102 
103     /**
104      * Simply remove this if it is ever actually removed from servlet-api
105      *
106      * @deprecated Remove this once servlet does.
107      */
108     @Deprecated
109     @InlineMe(replacement = "new String[0]")
110     @Override
111     public final String[] getValueNames() {
112         return new String[0];
113     }
114 
115     @Override
116     public void invalidate() {
117         // Do Nothing
118     }
119 
120     @Override
121     public boolean isNew() {
122         return false;
123     }
124 
125     /**
126      * Simply remove this if it is ever actually removed from servlet-api
127      *
128      * @deprecated Remove this once servlet does.
129      */
130     @Deprecated
131     @Override
132     public void putValue(final String arg0, final Object arg1) {
133         // Do Nothing
134     }
135 
136     @Override
137     public void removeAttribute(final String attributeName) {
138         this.attributes.remove(attributeName);
139     }
140 
141     /**
142      * Simply remove this if it is ever actually removed from servlet-api
143      *
144      * @deprecated Remove this once servlet does.
145      */
146     @Deprecated
147     @Override
148     public void removeValue(final String arg0) {
149         // Do Nothing
150     }
151 
152     @Override
153     public void setAttribute(final String attributeName, final Object attributeValue) {
154         this.attributes.put(attributeName, attributeValue);
155     }
156 
157     @Override
158     public void setMaxInactiveInterval(final int arg0) {
159         // Do Nothing
160     }
161 }