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 jakarta.servlet.ServletContext;
27  import jakarta.servlet.http.HttpSession;
28  
29  import java.util.Enumeration;
30  import java.util.HashMap;
31  import java.util.Map;
32  
33  /**
34   * Simple Http Session.
35   */
36  public class SimpleHttpSession implements HttpSession {
37  
38      /** The attributes. */
39      private final Map<String, Object> attributes = new HashMap<>();
40  
41      @Override
42      public Object getAttribute(final String attributeName) {
43          return this.attributes.get(attributeName);
44      }
45  
46      @Override
47      public Enumeration<String> getAttributeNames() {
48          return null;
49      }
50  
51      @Override
52      public long getCreationTime() {
53          return 0;
54      }
55  
56      @Override
57      public String getId() {
58          return null;
59      }
60  
61      @Override
62      public long getLastAccessedTime() {
63          return 0;
64      }
65  
66      @Override
67      public int getMaxInactiveInterval() {
68          return 0;
69      }
70  
71      @Override
72      public ServletContext getServletContext() {
73          return null;
74      }
75  
76      @Override
77      public void invalidate() {
78          // Do Nothing
79      }
80  
81      @Override
82      public boolean isNew() {
83          return false;
84      }
85  
86      @Override
87      public void removeAttribute(final String attributeName) {
88          this.attributes.remove(attributeName);
89      }
90  
91      @Override
92      public void setAttribute(final String attributeName, final Object attributeValue) {
93          this.attributes.put(attributeName, attributeValue);
94      }
95  
96      @Override
97      public void setMaxInactiveInterval(final int arg0) {
98          // Do Nothing
99      }
100 }