001: // Copyright 2006, 2007 The Apache Software Foundation
002: //
003: // Licensed under the Apache License, Version 2.0 (the "License");
004: // you may not use this file except in compliance with the License.
005: // You may obtain a copy of the License at
006: //
007: // http://www.apache.org/licenses/LICENSE-2.0
008: //
009: // Unless required by applicable law or agreed to in writing, software
010: // distributed under the License is distributed on an "AS IS" BASIS,
011: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: // See the License for the specific language governing permissions and
013: // limitations under the License.
014:
015: package org.apache.tapestry.internal.services;
016:
017: import java.util.Arrays;
018: import java.util.Collections;
019: import java.util.Enumeration;
020:
021: import javax.servlet.http.HttpSession;
022:
023: import org.apache.tapestry.internal.test.InternalBaseTestCase;
024: import org.apache.tapestry.services.Session;
025: import org.testng.annotations.Test;
026:
027: public class SessionImplTest extends InternalBaseTestCase {
028: @Test
029: public void get_attribute_names() {
030: Enumeration e = Collections.enumeration(Arrays.asList("fred",
031: "barney"));
032: HttpSession hs = mockHttpSession();
033:
034: expect(hs.getAttributeNames()).andReturn(e);
035:
036: replay();
037:
038: Session session = new SessionImpl(hs);
039:
040: assertEquals(session.getAttributeNames(), Arrays.asList(
041: "barney", "fred"));
042:
043: verify();
044: }
045:
046: @Test
047: public void get_attribute_names_by_prefix() {
048: Enumeration e = Collections.enumeration(Arrays.asList("fred",
049: "barney", "fanny"));
050: HttpSession hs = mockHttpSession();
051:
052: expect(hs.getAttributeNames()).andReturn(e);
053:
054: replay();
055:
056: Session session = new SessionImpl(hs);
057:
058: assertEquals(session.getAttributeNames("f"), Arrays.asList(
059: "fanny", "fred"));
060:
061: verify();
062: }
063:
064: @Test
065: public void invalidate() {
066: HttpSession hs = mockHttpSession();
067:
068: hs.invalidate();
069:
070: replay();
071:
072: Session session = new SessionImpl(hs);
073:
074: session.invalidate();
075:
076: verify();
077: }
078:
079: @Test
080: public void set_max_inactive() {
081: HttpSession hs = mockHttpSession();
082: int seconds = 999;
083:
084: hs.setMaxInactiveInterval(seconds);
085:
086: replay();
087:
088: Session session = new SessionImpl(hs);
089:
090: session.setMaxInactiveInterval(seconds);
091:
092: verify();
093: }
094:
095: @Test
096: public void get_max_inactive() {
097: HttpSession hs = mockHttpSession();
098: int seconds = 999;
099:
100: expect(hs.getMaxInactiveInterval()).andReturn(seconds);
101:
102: replay();
103:
104: Session session = new SessionImpl(hs);
105:
106: assertEquals(session.getMaxInactiveInterval(), seconds);
107:
108: verify();
109: }
110: }
|