KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > portlet > TestPortletResponseRenderer


1 // Copyright 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.portlet;
16
17 import javax.portlet.ActionResponse;
18 import javax.portlet.PortletMode;
19 import javax.portlet.PortletRequest;
20 import javax.portlet.WindowState;
21
22 import org.apache.hivemind.test.HiveMindTestCase;
23 import org.apache.tapestry.IPage;
24 import org.apache.tapestry.IRequestCycle;
25 import org.apache.tapestry.services.ServiceConstants;
26 import org.easymock.MockControl;
27
28 /**
29  * Tests for {@link org.apache.tapestry.portlet.PortletResponseRenderer}.
30  *
31  * @author Howard M. Lewis Ship
32  * @since 4.0
33  */

34 public class TestPortletResponseRenderer extends HiveMindTestCase
35 {
36     private ActionResponse newResponse()
37     {
38         return (ActionResponse) newMock(ActionResponse.class);
39     }
40
41     private IPage newPage(String JavaDoc name)
42     {
43         MockControl control = newControl(IPage.class);
44         IPage page = (IPage) control.getMock();
45
46         page.getPageName();
47         control.setReturnValue(name);
48
49         return page;
50     }
51
52     private IRequestCycle newCycle(IPage page)
53     {
54         MockControl control = newControl(IRequestCycle.class);
55         IRequestCycle cycle = (IRequestCycle) control.getMock();
56
57         cycle.getPage();
58         control.setReturnValue(page);
59
60         return cycle;
61     }
62
63     public void testSuccess() throws Exception JavaDoc
64     {
65         IPage page = newPage("Frodo");
66         IRequestCycle cycle = newCycle(page);
67
68         MockControl requestc = newControl(PortletRequest.class);
69         PortletRequest request = (PortletRequest) requestc.getMock();
70
71         request.getPortletMode();
72         requestc.setReturnValue(PortletMode.VIEW);
73
74         request.getWindowState();
75         requestc.setReturnValue(WindowState.NORMAL);
76
77         ActionResponse response = newResponse();
78
79         response.setRenderParameter(ServiceConstants.SERVICE, PortletConstants.RENDER_SERVICE);
80         response.setRenderParameter(ServiceConstants.PAGE, "Frodo");
81         response.setRenderParameter(PortletConstants.PORTLET_MODE, "view");
82         response.setRenderParameter(PortletConstants.WINDOW_STATE, "normal");
83
84         replayControls();
85
86         PortletResponseRenderer renderer = new PortletResponseRenderer();
87         renderer.setResponse(response);
88         renderer.setRequest(request);
89
90         renderer.renderResponse(cycle);
91
92         verifyControls();
93     }
94 }
Popular Tags