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 org.apache.tapestry.util.ContentType;
020    import org.testng.annotations.Test;
021    
022    import javax.portlet.PortletResponse;
023    
024    /**
025     * Tests for {@link org.apache.tapestry.portlet.PortletWebResponse}.
026     * 
027     * @author Howard M. Lewis Ship
028     * @since 4.0
029     */
030    @Test
031    public class TestPortletWebResponse extends BasePortletWebTestCase
032    {
033        private PortletResponse newResponse()
034        {
035            return newMock(PortletResponse.class);
036        }
037    
038        public void testGetOutputStreamUnsupported() throws Exception
039        {
040            PortletResponse response = newResponse();
041    
042            replay();
043    
044            PortletWebResponse pwr = new PortletWebResponse(response);
045    
046            try
047            {
048                pwr.getOutputStream(new ContentType("foo/bar"));
049                unreachable();
050            }
051            catch (UnsupportedOperationException ex)
052            {
053                // Expected.
054            }
055    
056            verify();
057        }
058    
059        public void testGetNamespace() throws Exception
060        {
061            PortletResponse response = newResponse();
062    
063            replay();
064    
065            PortletWebResponse pwr = new PortletWebResponse(response);
066    
067            assertEquals("", pwr.getNamespace());
068    
069            verify();
070        }
071    
072        public void testResetUnsupported()
073        {
074            PortletResponse response = newResponse();
075    
076            replay();
077    
078            PortletWebResponse pwr = new PortletWebResponse(response);
079    
080            try
081            {
082                pwr.reset();
083                unreachable();
084            }
085            catch (UnsupportedOperationException ex)
086            {
087                // Expected.
088            }
089    
090            verify();
091        }
092    
093        public void testSetDateHeaderUnsupported()
094        {
095            PortletResponse response = newResponse();
096    
097            replay();
098    
099            PortletWebResponse pwr = new PortletWebResponse(response);
100    
101            try
102            {
103                pwr.setDateHeader(null, 0);
104                unreachable();
105            }
106            catch (UnsupportedOperationException ex)
107            {
108                // Expected.
109            }
110    
111            verify();
112        }
113    
114        public void testSetHeaderUnsupported()
115        {
116            PortletResponse response = newResponse();
117    
118            replay();
119    
120            PortletWebResponse pwr = new PortletWebResponse(response);
121    
122            try
123            {
124                pwr.setHeader(null, null);
125                unreachable();
126            }
127            catch (UnsupportedOperationException ex)
128            {
129                // Expected.
130            }
131    
132            verify();
133        }
134    
135        public void testSetIntHeaderUnsupported()
136        {
137            PortletResponse response = newResponse();
138    
139            replay();
140    
141            PortletWebResponse pwr = new PortletWebResponse(response);
142    
143            try
144            {
145                pwr.setIntHeader(null, 0);
146                unreachable();
147            }
148            catch (UnsupportedOperationException ex)
149            {
150                // Expected.
151            }
152    
153            verify();
154        }
155    
156        public void testSendErrorUnsupported() throws Exception
157        {
158            PortletResponse response = newResponse();
159    
160            replay();
161    
162            PortletWebResponse pwr = new PortletWebResponse(response);
163    
164            try
165            {
166                pwr.sendError(99, "foo!");
167                unreachable();
168            }
169            catch (UnsupportedOperationException ex)
170            {
171                // Expected.
172            }
173    
174            verify();
175        }
176    
177        public void testEncodeURL()
178        {
179            PortletResponse response = newMock(PortletResponse.class);
180            
181            expect(response.encodeURL("/foo")).andReturn("/foo;encoded");
182            
183            replay();
184            
185            PortletWebResponse pwr = new PortletWebResponse(response);
186            
187            assertEquals("/foo;encoded", pwr.encodeURL("/foo"));
188    
189            verify();
190        }
191    }