001: /*
002: * Created on Mar 10, 2006
003: *
004: * TODO To change the template for this generated file go to
005: * Window - Preferences - Java - Code Style - Code Templates
006: */
007: package com.opensymphony.webwork.portlet.util;
008:
009: import java.util.HashMap;
010: import java.util.Map;
011:
012: import javax.portlet.PortletMode;
013: import javax.portlet.PortletURL;
014: import javax.portlet.RenderRequest;
015: import javax.portlet.RenderResponse;
016: import javax.portlet.WindowState;
017:
018: import junit.framework.TestCase;
019:
020: import org.easymock.MockControl;
021:
022: import com.opensymphony.webwork.portlet.context.PortletActionContext;
023: import com.opensymphony.xwork.ActionContext;
024:
025: /**
026: * @author Nils-Helge Garli
027: *
028: * TODO To change the template for this generated type comment go to Window -
029: * Preferences - Java - Code Style - Code Templates
030: */
031: public class PortletUrlHelperTest extends TestCase {
032:
033: RenderResponse renderResponse;
034:
035: RenderRequest renderRequest;
036:
037: PortletURL url;
038:
039: MockControl renderResponseControl;
040:
041: MockControl renderRequestControl;
042:
043: MockControl portletUrlControl;
044:
045: public void setUp() throws Exception {
046: super .setUp();
047:
048: renderRequestControl = MockControl
049: .createControl(RenderRequest.class);
050: renderResponseControl = MockControl
051: .createControl(RenderResponse.class);
052: portletUrlControl = MockControl.createControl(PortletURL.class);
053:
054: renderRequest = (RenderRequest) renderRequestControl.getMock();
055: renderResponse = (RenderResponse) renderResponseControl
056: .getMock();
057: url = (PortletURL) portletUrlControl.getMock();
058:
059: renderRequestControl.expectAndDefaultReturn(renderRequest
060: .getPortletMode(), PortletMode.VIEW);
061: renderRequestControl.expectAndDefaultReturn(renderRequest
062: .getWindowState(), WindowState.NORMAL);
063:
064: Map modeNamespaceMap = new HashMap();
065: modeNamespaceMap.put("view", "/view");
066: modeNamespaceMap.put("edit", "/edit");
067: modeNamespaceMap.put("help", "/help");
068:
069: Map context = new HashMap();
070: context.put(PortletActionContext.REQUEST, renderRequest);
071: context.put(PortletActionContext.RESPONSE, renderResponse);
072: context.put(PortletActionContext.PHASE,
073: PortletActionContext.RENDER_PHASE);
074: context.put(PortletActionContext.MODE_NAMESPACE_MAP,
075: modeNamespaceMap);
076:
077: ActionContext.setContext(new ActionContext(context));
078:
079: }
080:
081: public void testCreateRenderUrlWithNoModeOrState() throws Exception {
082: renderResponseControl.expectAndReturn(renderResponse
083: .createRenderURL(), url);
084:
085: url.setPortletMode(PortletMode.VIEW);
086: url.setWindowState(WindowState.NORMAL);
087: url.setParameters(null);
088: portletUrlControl.setMatcher(MockControl.ALWAYS_MATCHER);
089: renderRequestControl.replay();
090: renderResponseControl.replay();
091: portletUrlControl.replay();
092: String urlStr = PortletUrlHelper.buildUrl("testAction", null,
093: new HashMap(), null, null, null);
094: portletUrlControl.verify();
095: renderRequestControl.verify();
096: renderResponseControl.verify();
097: }
098:
099: public void testCreateRenderUrlWithDifferentPortletMode()
100: throws Exception {
101: renderResponseControl.expectAndReturn(renderResponse
102: .createRenderURL(), url);
103:
104: url.setPortletMode(PortletMode.EDIT);
105: url.setWindowState(WindowState.NORMAL);
106: url.setParameters(null);
107: portletUrlControl.setMatcher(MockControl.ALWAYS_MATCHER);
108: renderRequestControl.replay();
109: renderResponseControl.replay();
110: portletUrlControl.replay();
111: String urlStr = PortletUrlHelper.buildUrl("testAction", null,
112: new HashMap(), null, "edit", null);
113: portletUrlControl.verify();
114: renderRequestControl.verify();
115: renderResponseControl.verify();
116: }
117:
118: public void testCreateRenderUrlWithDifferentWindowState()
119: throws Exception {
120: renderResponseControl.expectAndReturn(renderResponse
121: .createRenderURL(), url);
122:
123: url.setPortletMode(PortletMode.VIEW);
124: url.setWindowState(WindowState.MAXIMIZED);
125: url.setParameters(null);
126: portletUrlControl.setMatcher(MockControl.ALWAYS_MATCHER);
127: renderRequestControl.replay();
128: renderResponseControl.replay();
129: portletUrlControl.replay();
130: String urlStr = PortletUrlHelper.buildUrl("testAction", null,
131: new HashMap(), null, null, "maximized");
132: portletUrlControl.verify();
133: renderRequestControl.verify();
134: renderResponseControl.verify();
135: }
136:
137: public void testCreateActionUrl() throws Exception {
138: renderResponseControl.expectAndReturn(renderResponse
139: .createActionURL(), url);
140:
141: url.setPortletMode(PortletMode.VIEW);
142: url.setWindowState(WindowState.NORMAL);
143: url.setParameters(null);
144: portletUrlControl.setMatcher(MockControl.ALWAYS_MATCHER);
145: renderRequestControl.replay();
146: renderResponseControl.replay();
147: portletUrlControl.replay();
148: String urlStr = PortletUrlHelper.buildUrl("testAction", null,
149: new HashMap(), "action", null, null);
150: portletUrlControl.verify();
151: renderRequestControl.verify();
152: renderResponseControl.verify();
153: }
154:
155: }
|