1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.shiro.web.session;
20
21 import static org.easymock.EasyMock.*;
22 import static org.junit.Assert.assertEquals;
23
24 import javax.servlet.http.HttpSession;
25
26 import org.easymock.Capture;
27 import org.junit.Before;
28 import org.junit.Test;
29
30 public class HttpServletSessionTest {
31
32 private HttpSession mockSession;
33
34 @Before
35 public void setUp() throws Exception {
36 this.mockSession = createMock(HttpSession.class);
37 }
38
39
40
41
42
43
44 @Test
45 public void testLongTimeout() throws Exception {
46 final int expectedTimeoutInSeconds = 30 * 24 * 60 * 60;
47 final long expectedLongValue = expectedTimeoutInSeconds * 1000L;
48
49 Capture<Integer> capturedInt = new Capture<Integer>();
50
51 mockSession.setMaxInactiveInterval(captureInt(capturedInt));
52 expect(mockSession.getMaxInactiveInterval()).andReturn(expectedTimeoutInSeconds);
53 replay(mockSession);
54
55 HttpServletSession servletSession = new HttpServletSession(mockSession, null);
56 servletSession.setTimeout(expectedLongValue);
57
58 long timeoutInMilliseconds = servletSession.getTimeout();
59
60 assertEquals(expectedLongValue, timeoutInMilliseconds);
61 assertEquals(expectedTimeoutInSeconds, capturedInt.getValue().intValue());
62 }
63 }