001    // Copyright 2005 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.portlet;
016    
017    import static org.easymock.EasyMock.expect;
018    
019    import java.util.List;
020    
021    import org.apache.tapestry.web.WebSession;
022    import org.testng.annotations.Test;
023    
024    import javax.portlet.PortletSession;
025    
026    /**
027     * Tests for {@link org.apache.tapestry.portlet.PortletWebSession}.
028     * 
029     * @author Howard M. Lewis Ship
030     * @since 4.0
031     */
032    @Test
033    public class PortletWebSessionTest extends BasePortletWebTestCase
034    {
035    
036        public void testGetAttributeNames()
037        {
038            PortletSession session = newSession();
039    
040            expect(session.getAttributeNames()).andReturn(newEnumeration());
041    
042            replay();
043    
044            WebSession ws = new PortletWebSession(session);
045            
046            List l = ws.getAttributeNames();
047    
048            checkList(l);
049    
050            verify();
051        }
052    
053        private PortletSession newSession()
054        {
055            return newMock(PortletSession.class);
056        }
057    
058        public void testGetAttribute()
059        {
060            Object attribute = new Object();
061    
062            PortletSession session = newSession();
063    
064            expect(session.getAttribute("attr")).andReturn(attribute);
065            
066            replay();
067    
068            WebSession ws = new PortletWebSession(session);
069    
070            assertSame(attribute, ws.getAttribute("attr"));
071    
072            verify();
073        }
074    
075        public void testSetAttribute()
076        {
077            Object attribute = new Object();
078    
079            PortletSession session = newSession();
080    
081            session.setAttribute("name", attribute);
082    
083            replay();
084    
085            WebSession ws = new PortletWebSession(session);
086    
087            ws.setAttribute("name", attribute);
088    
089            verify();
090        }
091    
092        public void testGetId()
093        {
094            PortletSession session = newSession();
095    
096            expect(session.getId()).andReturn("abc");
097            
098            replay();
099    
100            WebSession ws = new PortletWebSession(session);
101    
102            assertEquals("abc", ws.getId());
103    
104            verify();
105        }
106    
107        public void testInvalidate()
108        {
109            PortletSession session = newSession();
110    
111            session.invalidate();
112    
113            replay();
114    
115            WebSession ws = new PortletWebSession(session);
116    
117            ws.invalidate();
118    
119            verify();
120        }
121    }