001: /*
002: * $Id: PortletUrlHelperTest.java 569304 2007-08-24 09:12:20Z nilsga $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts2.portlet.util;
022:
023: import java.util.HashMap;
024: import java.util.Map;
025:
026: import javax.portlet.PortletMode;
027: import javax.portlet.PortletURL;
028: import javax.portlet.RenderRequest;
029: import javax.portlet.RenderResponse;
030: import javax.portlet.WindowState;
031:
032: import junit.framework.TestCase;
033:
034: import org.apache.struts2.portlet.context.PortletActionContext;
035: import org.easymock.MockControl;
036:
037: import com.opensymphony.xwork2.ActionContext;
038:
039: /**
040: */
041: public class PortletUrlHelperTest extends TestCase {
042:
043: RenderResponse renderResponse;
044:
045: RenderRequest renderRequest;
046:
047: PortletURL url;
048:
049: MockControl renderResponseControl;
050:
051: MockControl renderRequestControl;
052:
053: MockControl portletUrlControl;
054:
055: public void setUp() throws Exception {
056: super .setUp();
057:
058: renderRequestControl = MockControl
059: .createControl(RenderRequest.class);
060: renderResponseControl = MockControl
061: .createControl(RenderResponse.class);
062: portletUrlControl = MockControl.createControl(PortletURL.class);
063:
064: renderRequest = (RenderRequest) renderRequestControl.getMock();
065: renderResponse = (RenderResponse) renderResponseControl
066: .getMock();
067: url = (PortletURL) portletUrlControl.getMock();
068:
069: renderRequestControl.expectAndDefaultReturn(renderRequest
070: .getPortletMode(), PortletMode.VIEW);
071: renderRequestControl.expectAndDefaultReturn(renderRequest
072: .getWindowState(), WindowState.NORMAL);
073:
074: Map modeNamespaceMap = new HashMap();
075: modeNamespaceMap.put("view", "/view");
076: modeNamespaceMap.put("edit", "/edit");
077: modeNamespaceMap.put("help", "/help");
078:
079: Map context = new HashMap();
080: context.put(PortletActionContext.REQUEST, renderRequest);
081: context.put(PortletActionContext.RESPONSE, renderResponse);
082: context.put(PortletActionContext.PHASE,
083: PortletActionContext.RENDER_PHASE);
084: context.put(PortletActionContext.MODE_NAMESPACE_MAP,
085: modeNamespaceMap);
086:
087: ActionContext.setContext(new ActionContext(context));
088:
089: }
090:
091: public void testCreateRenderUrlWithNoModeOrState() throws Exception {
092: renderResponseControl.expectAndReturn(renderResponse
093: .createRenderURL(), url);
094:
095: url.setPortletMode(PortletMode.VIEW);
096: url.setWindowState(WindowState.NORMAL);
097: url.setParameters(null);
098: portletUrlControl.setMatcher(MockControl.ALWAYS_MATCHER);
099: renderRequestControl.replay();
100: renderResponseControl.replay();
101: portletUrlControl.replay();
102: PortletUrlHelper.buildUrl("testAction", null, null,
103: new HashMap(), null, null, null);
104: portletUrlControl.verify();
105: renderRequestControl.verify();
106: renderResponseControl.verify();
107: }
108:
109: public void testCreateRenderUrlWithDifferentPortletMode()
110: throws Exception {
111: renderResponseControl.expectAndReturn(renderResponse
112: .createRenderURL(), url);
113:
114: url.setPortletMode(PortletMode.EDIT);
115: url.setWindowState(WindowState.NORMAL);
116: url.setParameters(null);
117: portletUrlControl.setMatcher(MockControl.ALWAYS_MATCHER);
118: renderRequestControl.replay();
119: renderResponseControl.replay();
120: portletUrlControl.replay();
121: PortletUrlHelper.buildUrl("testAction", null, null,
122: new HashMap(), null, "edit", null);
123: portletUrlControl.verify();
124: renderRequestControl.verify();
125: renderResponseControl.verify();
126: }
127:
128: public void testCreateRenderUrlWithDifferentWindowState()
129: throws Exception {
130: renderResponseControl.expectAndReturn(renderResponse
131: .createRenderURL(), url);
132:
133: url.setPortletMode(PortletMode.VIEW);
134: url.setWindowState(WindowState.MAXIMIZED);
135: url.setParameters(null);
136: portletUrlControl.setMatcher(MockControl.ALWAYS_MATCHER);
137: renderRequestControl.replay();
138: renderResponseControl.replay();
139: portletUrlControl.replay();
140: PortletUrlHelper.buildUrl("testAction", null, null,
141: new HashMap(), null, null, "maximized");
142: portletUrlControl.verify();
143: renderRequestControl.verify();
144: renderResponseControl.verify();
145: }
146:
147: public void testCreateActionUrl() throws Exception {
148: renderResponseControl.expectAndReturn(renderResponse
149: .createActionURL(), url);
150:
151: url.setPortletMode(PortletMode.VIEW);
152: url.setWindowState(WindowState.NORMAL);
153: url.setParameters(null);
154: portletUrlControl.setMatcher(MockControl.ALWAYS_MATCHER);
155: renderRequestControl.replay();
156: renderResponseControl.replay();
157: portletUrlControl.replay();
158: PortletUrlHelper.buildUrl("testAction", null, null,
159: new HashMap(), "action", null, null);
160: portletUrlControl.verify();
161: renderRequestControl.verify();
162: renderResponseControl.verify();
163: }
164:
165: }
|