FileDocCategorySizeDatePackage
PortletUrlHelperTest.javaAPI DocExample5970Mon Jul 23 13:26:12 BST 2007org.apache.struts2.portlet.util

PortletUrlHelperTest

public class PortletUrlHelperTest extends TestCase

Fields Summary
javax.portlet.RenderResponse
renderResponse
javax.portlet.RenderRequest
renderRequest
javax.portlet.PortletURL
url
org.easymock.MockControl
renderResponseControl
org.easymock.MockControl
renderRequestControl
org.easymock.MockControl
portletUrlControl
Constructors Summary
Methods Summary
public voidsetUp()

        super.setUp();

        renderRequestControl = MockControl.createControl(RenderRequest.class);
        renderResponseControl = MockControl.createControl(RenderResponse.class);
        portletUrlControl = MockControl.createControl(PortletURL.class);

        renderRequest = (RenderRequest) renderRequestControl.getMock();
        renderResponse = (RenderResponse) renderResponseControl.getMock();
        url = (PortletURL) portletUrlControl.getMock();

        renderRequestControl.expectAndDefaultReturn(renderRequest
                .getPortletMode(), PortletMode.VIEW);
        renderRequestControl.expectAndDefaultReturn(renderRequest
                .getWindowState(), WindowState.NORMAL);

        Map modeNamespaceMap = new HashMap();
        modeNamespaceMap.put("view", "/view");
        modeNamespaceMap.put("edit", "/edit");
        modeNamespaceMap.put("help", "/help");

        Map context = new HashMap();
        context.put(PortletActionContext.REQUEST, renderRequest);
        context.put(PortletActionContext.RESPONSE, renderResponse);
        context.put(PortletActionContext.PHASE,
                PortletActionContext.RENDER_PHASE);
        context.put(PortletActionContext.MODE_NAMESPACE_MAP, modeNamespaceMap);

        ActionContext.setContext(new ActionContext(context));

    
public voidtestCreateActionUrl()

        renderResponseControl.expectAndReturn(renderResponse.createActionURL(),
                url);

        url.setPortletMode(PortletMode.VIEW);
        url.setWindowState(WindowState.NORMAL);
        url.setParameters(null);
        portletUrlControl.setMatcher(MockControl.ALWAYS_MATCHER);
        renderRequestControl.replay();
        renderResponseControl.replay();
        portletUrlControl.replay();
        PortletUrlHelper.buildUrl("testAction", null,
                new HashMap(), "action", null, null);
        portletUrlControl.verify();
        renderRequestControl.verify();
        renderResponseControl.verify();
    
public voidtestCreateRenderUrlWithDifferentPortletMode()

        renderResponseControl.expectAndReturn(renderResponse.createRenderURL(),
                url);

        url.setPortletMode(PortletMode.EDIT);
        url.setWindowState(WindowState.NORMAL);
        url.setParameters(null);
        portletUrlControl.setMatcher(MockControl.ALWAYS_MATCHER);
        renderRequestControl.replay();
        renderResponseControl.replay();
        portletUrlControl.replay();
        PortletUrlHelper.buildUrl("testAction", null,
                new HashMap(), null, "edit", null);
        portletUrlControl.verify();
        renderRequestControl.verify();
        renderResponseControl.verify();
    
public voidtestCreateRenderUrlWithDifferentWindowState()

        renderResponseControl.expectAndReturn(renderResponse.createRenderURL(),
                url);

        url.setPortletMode(PortletMode.VIEW);
        url.setWindowState(WindowState.MAXIMIZED);
        url.setParameters(null);
        portletUrlControl.setMatcher(MockControl.ALWAYS_MATCHER);
        renderRequestControl.replay();
        renderResponseControl.replay();
        portletUrlControl.replay();
        PortletUrlHelper.buildUrl("testAction", null,
                new HashMap(), null, null, "maximized");
        portletUrlControl.verify();
        renderRequestControl.verify();
        renderResponseControl.verify();
    
public voidtestCreateRenderUrlWithNoModeOrState()

        renderResponseControl.expectAndReturn(renderResponse.createRenderURL(),
                url);

        url.setPortletMode(PortletMode.VIEW);
        url.setWindowState(WindowState.NORMAL);
        url.setParameters(null);
        portletUrlControl.setMatcher(MockControl.ALWAYS_MATCHER);
        renderRequestControl.replay();
        renderResponseControl.replay();
        portletUrlControl.replay();
        PortletUrlHelper.buildUrl("testAction", null,
                new HashMap(), null, null, null);
        portletUrlControl.verify();
        renderRequestControl.verify();
        renderResponseControl.verify();