FileDocCategorySizeDatePackage
PortletActionContextTest.javaAPI DocExample6985Mon Jul 23 13:26:12 BST 2007org.apache.struts2.portlet.context

PortletActionContextTest

public class PortletActionContextTest extends org.jmock.MockObjectTestCase

Fields Summary
org.jmock.Mock
mockRenderRequest
org.jmock.Mock
mockRenderResponse
org.jmock.Mock
mockPortletConfig
org.jmock.Mock
mockActionRequest
org.jmock.Mock
mockActionResponse
javax.portlet.RenderRequest
renderRequest
javax.portlet.RenderResponse
renderResponse
javax.portlet.ActionRequest
actionRequest
javax.portlet.ActionResponse
actionResponse
javax.portlet.PortletConfig
portletConfig
Map
context
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

        TestRunner.run(PortletActionContextTest.class);
    
public voidsetUp()


         
        super.setUp();
        mockRenderRequest = mock(RenderRequest.class);
        mockRenderResponse = mock(RenderResponse.class);
        mockActionRequest = mock(ActionRequest.class);
        mockActionResponse = mock(ActionResponse.class);
        mockPortletConfig = mock(PortletConfig.class);

        renderRequest = (RenderRequest)mockRenderRequest.proxy();
        renderResponse = (RenderResponse)mockRenderResponse.proxy();
        actionRequest = (ActionRequest)mockActionRequest.proxy();
        actionResponse = (ActionResponse)mockActionResponse.proxy();
        portletConfig = (PortletConfig)mockPortletConfig.proxy();


        ActionContext.setContext(new ActionContext(context));
    
public voidtearDown()

        ActionContext.setContext(null);
        super.tearDown();
    
public voidtestGetActionRequestAndResponse()

        context.put(PortletActionConstants.REQUEST, actionRequest);
        context.put(PortletActionConstants.RESPONSE, actionResponse);
        context.put(PortletActionConstants.PHASE, PortletActionConstants.EVENT_PHASE);
        assertSame(actionRequest, PortletActionContext.getActionRequest());
        assertSame(actionResponse, PortletActionContext.getActionResponse());
        assertSame(actionRequest, PortletActionContext.getRequest());
        assertSame(actionResponse, PortletActionContext.getResponse());
    
public voidtestGetActionRequestAndResponseInRenderPhase()

        context.put(PortletActionConstants.REQUEST, actionRequest);
        context.put(PortletActionConstants.RESPONSE, actionResponse);
        context.put(PortletActionConstants.PHASE, PortletActionConstants.RENDER_PHASE);
        try {
            PortletActionContext.getActionRequest();
            fail("Should throw IllegalStateException!");
        }
        catch(IllegalStateException e) {
            assertTrue(true);
        }
        try {
            PortletActionContext.getActionResponse();
            fail("Should throw IllegalStateException!");
        }
        catch(IllegalStateException e) {
            assertTrue(true);
        }
    
public voidtestGetDefaultActionForMode()

        ActionMapping mapping = new ActionMapping();
        context.put(PortletActionConstants.DEFAULT_ACTION_FOR_MODE, mapping);
        assertEquals(mapping, PortletActionContext.getDefaultActionForMode());
    
public voidtestGetNamespace()

        context.put(PortletActionConstants.PORTLET_NAMESPACE, "testNamespace");
        assertEquals("testNamespace", PortletActionContext.getPortletNamespace());
    
public voidtestGetPhase()

        context.put(PortletActionConstants.PHASE, PortletActionConstants.RENDER_PHASE);

        assertEquals(PortletActionConstants.RENDER_PHASE, PortletActionContext.getPhase());
    
public voidtestGetPortletConfig()

        context.put(PortletActionConstants.PORTLET_CONFIG, portletConfig);
        assertSame(portletConfig, PortletActionContext.getPortletConfig());
    
public voidtestGetRenderRequestAndResponse()

        context.put(PortletActionConstants.REQUEST, renderRequest);
        context.put(PortletActionConstants.RESPONSE, renderResponse);
        context.put(PortletActionConstants.PHASE, PortletActionConstants.RENDER_PHASE);
        assertSame(renderRequest, PortletActionContext.getRenderRequest());
        assertSame(renderResponse, PortletActionContext.getRenderResponse());
        assertSame(renderRequest, PortletActionContext.getRequest());
        assertSame(renderResponse, PortletActionContext.getResponse());
    
public voidtestGetRenderRequestAndResponseInEventPhase()

        context.put(PortletActionConstants.REQUEST, renderRequest);
        context.put(PortletActionConstants.RESPONSE, renderResponse);
        context.put(PortletActionConstants.PHASE, PortletActionConstants.EVENT_PHASE);
        try {
            PortletActionContext.getRenderRequest();
            fail("Should throw IllegalStateException!");
        }
        catch(IllegalStateException e) {
            assertTrue(true);
        }
        try {
            PortletActionContext.getRenderResponse();
            fail("Should throw IllegalStateException!");
        }
        catch(IllegalStateException e) {
            assertTrue(true);
        }
    
public voidtestIsEvent()

        context.put(PortletActionConstants.PHASE, PortletActionConstants.EVENT_PHASE);

        assertTrue(PortletActionContext.isEvent());
        assertFalse(PortletActionContext.isRender());
    
public voidtestIsRender()

        context.put(PortletActionConstants.PHASE, PortletActionConstants.RENDER_PHASE);

        assertTrue(PortletActionContext.isRender());
        assertFalse(PortletActionContext.isEvent());