Search in sources :

Example 6 with StateAwareResponse

use of javax.portlet.StateAwareResponse in project liferay-faces-bridge-impl by liferay.

the class EncodeActionURLTests method encodeActionURLJSFViewEventTest.

// Test is MultiRequest -- Render/Action
// Test #6.103
@BridgeTest(test = "encodeActionURLJSFViewEventTest")
public String encodeActionURLJSFViewEventTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    // "action" attribute).
    if (BridgeUtil.getPortletRequestPhase(facesContext) == Bridge.PortletPhase.ACTION_PHASE) {
        // Here in the ACTION_PHASE, publish an event so that in the EVENT_PHASE,
        // Ch6TestEventHander.handleEvent(FacesContext,Event) will return an EventNavigationResult with
        // action="encodeActionURLJSFViewEventTest". This will cause the FacesBridge navigation-handler to execute a
        // navigation-rule in order to navigate to a different view (in the EVENT_PHASE) by:
        // 
        // 1) Creating an action BridgeURL that encodes target viewId=multiRequestTestResultRenderCheck.xhtml (in
        // the RI, see the BridgeNavigationHandlerImpl.handleNavigation(FacesContext,String,String) method).
        // 
        // 2) Extracting portlet mode, window state, and render parameters (a.k.a. Portlet 3.0 "render state") from
        // the action BridgeURL and setting them on the StateAwareResponse (in the RI, see the
        // BridgeNavigationUtil.navigate(PortletRequest,StateAwareResponse,Map<String,String[]> method).
        // 
        // Note that the client window id "jsfwid" parameter is encoded on the actionURL in #1 and set as a render
        // parameter in #2 so that it will be picked up in the HEADER_PHASE.
        StateAwareResponse stateAwareResponse = (StateAwareResponse) externalContext.getResponse();
        stateAwareResponse.setEvent(new QName(Constants.EVENT_QNAME, Constants.EVENT_NAME), testBean.getTestName());
        // action Navigation result
        return Constants.TEST_SUCCESS;
    } else // Otherwise, if this method is reached in the HEADER_PHASE of the portlet lifecycle then the bridge executed a
    // navigation-rule to viewId=multiRequestTestResultRenderCheck.xhtml in order to display the test results. This
    // verifies that the action BridgeURL created in the EVENT_PHASE correctly encoded the viewId (and if client
    // window mode is enabled, the "jsfwid" parameter as well).
    {
        Map<String, String> requestParameterMap = externalContext.getRequestParameterMap();
        String clientWindowParam = requestParameterMap.get(ResponseStateManager.CLIENT_WINDOW_URL_PARAM);
        if (ClientWindowTestUtil.isClientWindowEnabled(externalContext)) {
            String clientWindowId = ClientWindowTestUtil.getClientWindowId(externalContext);
            if ((clientWindowParam != null) && (clientWindowParam.length() > 0)) {
                if (clientWindowParam.equals(clientWindowId)) {
                    testBean.setTestResult(true, "encodeActionURL correctly encoded the viewId in the EVENT_PHASE of the portlet " + "lifecycle and " + ResponseStateManager.CLIENT_WINDOW_URL_PARAM + " request parameter value=[" + clientWindowParam + "] is equal to ClientWindow.getId().");
                } else {
                    testBean.setTestResult(false, "encodeActionURL returned a URL such that the " + ResponseStateManager.CLIENT_WINDOW_URL_PARAM + " request parameter value=[" + clientWindowParam + "] did NOT equal ClientWindow.getId()=[" + clientWindowId + "].");
                }
            } else {
                testBean.setTestResult(false, "encodeActionURL returned a URL that contained a null value for the " + ResponseStateManager.CLIENT_WINDOW_URL_PARAM + " request parameter.");
            }
        } else {
            if (clientWindowParam == null) {
                testBean.setTestResult(true, "encodeActionURL correctly encoded the viewId in the EVENT_PHASE of the portlet lifecycle.");
            } else {
                testBean.setTestResult(false, "encodeActionURL returned a URL that incorrectly included the " + ResponseStateManager.CLIENT_WINDOW_URL_PARAM + " request parameter with value=[" + clientWindowParam + "] even though the client window feature is disabled.");
            }
        }
        testBean.setTestComplete(true);
        if (testBean.getTestStatus()) {
            return Constants.TEST_SUCCESS;
        } else {
            return Constants.TEST_FAILED;
        }
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) StateAwareResponse(javax.portlet.StateAwareResponse) ExternalContext(javax.faces.context.ExternalContext) QName(javax.xml.namespace.QName) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 7 with StateAwareResponse

use of javax.portlet.StateAwareResponse in project liferay-faces-bridge-impl by liferay.

the class EncodeActionURLTests method encodeActionURLWithInvalidModeEventTest.

// Test is MultiRequest -- Render/Action
// Test #6.105
@BridgeTest(test = "encodeActionURLWithInvalidModeEventTest")
public String encodeActionURLWithInvalidModeEventTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    // This tests that we can encode an invalid mode in an actionURL done by navigation rule.
    if (BridgeUtil.getPortletRequestPhase(facesContext) == Bridge.PortletPhase.ACTION_PHASE) {
        // Create and raise the event
        StateAwareResponse stateAwareResponse = (StateAwareResponse) externalContext.getResponse();
        stateAwareResponse.setEvent(new QName(Constants.EVENT_QNAME, Constants.EVENT_NAME), testBean.getTestName());
        // action Navigation result
        return Constants.TEST_SUCCESS;
    } else {
        testBean.setTestComplete(true);
        PortletRequest portletRequest = (PortletRequest) facesContext.getExternalContext().getRequest();
        // Parameter/Mode encoded in the faces-config.xml target
        PortletMode portletMode = portletRequest.getPortletMode();
        if ((portletMode == null) || !portletMode.toString().equalsIgnoreCase("view")) {
            testBean.setTestResult(false, "encodeActionURL incorrectly encoded the invalid portlet mode.  The resulting request should have ignored the invalid mode and remained in 'view' mode.");
            return Constants.TEST_FAILED;
        }
        // Check that the parameter came along too
        String paramValue = facesContext.getExternalContext().getRequestParameterMap().get("param1");
        if (paramValue == null) {
            testBean.setTestResult(false, "encodeActionURL incorrectly encoded a portlet action URL containing an invalid mode and parameter.  The resulting request didn't contain the expected 'param1' parameter.");
            return Constants.TEST_FAILED;
        }
        if (!paramValue.equals("testValue")) {
            testBean.setTestResult(false, "encodeActionURL incorrectly encoded a portlet action URL containing an invalid mode and parameter.  The resulting request contained the wrong parameter value. Expected: testValue  Received: " + paramValue);
            return Constants.TEST_FAILED;
        }
        testBean.setTestResult(true, "encodeActionURL correctly encoded a portlet action URL by ignoring the invalid mode and properly encoding the parameter.");
        return Constants.TEST_SUCCESS;
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) StateAwareResponse(javax.portlet.StateAwareResponse) PortletRequest(javax.portlet.PortletRequest) ExternalContext(javax.faces.context.ExternalContext) QName(javax.xml.namespace.QName) PortletMode(javax.portlet.PortletMode) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 8 with StateAwareResponse

use of javax.portlet.StateAwareResponse in project liferay-faces-bridge-impl by liferay.

the class EncodeActionURLTests method encodeActionURLWithModeEventTest.

// Test is MultiRequest -- Render/Action
// Test #6.104
@BridgeTest(test = "encodeActionURLWithModeEventTest")
public String encodeActionURLWithModeEventTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    // This tests that we can encode a new mode in an actionURL done by navigation rule.
    if (BridgeUtil.getPortletRequestPhase(facesContext) == Bridge.PortletPhase.ACTION_PHASE) {
        // Create and raise the event
        StateAwareResponse stateAwareResponse = (StateAwareResponse) externalContext.getResponse();
        stateAwareResponse.setEvent(new QName(Constants.EVENT_QNAME, Constants.EVENT_NAME), testBean.getTestName());
        // action Navigation result
        return Constants.TEST_SUCCESS;
    } else {
        testBean.setTestComplete(true);
        PortletRequest portletRequest = (PortletRequest) facesContext.getExternalContext().getRequest();
        // Parameter/Mode encoded in the faces-config.xml target
        PortletMode portletMode = portletRequest.getPortletMode();
        if ((portletMode == null) || !portletMode.toString().equalsIgnoreCase("edit")) {
            testBean.setTestResult(false, "encodeActionURL incorrectly encoded the new portlet mode.  The resulting request wasn't in the expected 'edit' mode.");
            return Constants.TEST_FAILED;
        }
        // Check that the parameter came along too
        String paramValue = facesContext.getExternalContext().getRequestParameterMap().get("param1");
        if (paramValue == null) {
            testBean.setTestResult(false, "encodeActionURL incorrectly encoded a portlet action URL containing a new mode and parameter during the event phase.  The resulting request didn't contain the expected 'param1' parameter.");
            return Constants.TEST_FAILED;
        }
        if (!paramValue.equals("testValue")) {
            testBean.setTestResult(false, "encodeActionURL incorrectly encoded a portlet action URL containing a new mode and parameter during the event phase.  The resulting request contained the wrong parameter value. Expected: testValue  Received: " + paramValue);
            return Constants.TEST_FAILED;
        }
        testBean.setTestResult(true, "encodeActionURL correctly encoded a portlet action URL containing a new mode and parameter during the event phase.");
        return Constants.TEST_SUCCESS;
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) StateAwareResponse(javax.portlet.StateAwareResponse) PortletRequest(javax.portlet.PortletRequest) ExternalContext(javax.faces.context.ExternalContext) QName(javax.xml.namespace.QName) PortletMode(javax.portlet.PortletMode) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 9 with StateAwareResponse

use of javax.portlet.StateAwareResponse in project liferay-faces-bridge-impl by liferay.

the class EncodeActionURLTests method encodeActionURLWithInvalidWindowStateEventTest.

// Test is MultiRequest -- Render/Action
// Test #6.107
@BridgeTest(test = "encodeActionURLWithInvalidWindowStateEventTest")
public String encodeActionURLWithInvalidWindowStateEventTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    // This tests that we can encode an invalid window state in an actionURL done by navigation rule.
    if (BridgeUtil.getPortletRequestPhase(facesContext) == Bridge.PortletPhase.ACTION_PHASE) {
        // Create and raise the event
        StateAwareResponse stateAwareResponse = (StateAwareResponse) externalContext.getResponse();
        stateAwareResponse.setEvent(new QName(Constants.EVENT_QNAME, Constants.EVENT_NAME), testBean.getTestName());
        // action Navigation result
        return Constants.TEST_SUCCESS;
    } else {
        testBean.setTestComplete(true);
        PortletRequest portletRequest = (PortletRequest) facesContext.getExternalContext().getRequest();
        // Parameter/Mode encoded in the faces-config.xml target
        WindowState windowState = portletRequest.getWindowState();
        if ((windowState == null) || !windowState.toString().equalsIgnoreCase("normal")) {
            testBean.setTestResult(false, "encodeActionURL incorrectly encoded the invalid window state.  The resulting request should have ignored the invalid window state and remained in 'normal' mode.");
            return Constants.TEST_FAILED;
        }
        // Check that the parameter came along too
        String paramValue = facesContext.getExternalContext().getRequestParameterMap().get("param1");
        if (paramValue == null) {
            testBean.setTestResult(false, "encodeActionURL incorrectly encoded a portlet action URL containing an invalid window state and parameter.  The resulting request didn't contain the expected 'param1' parameter.");
            return Constants.TEST_FAILED;
        }
        if (!paramValue.equals("testValue")) {
            testBean.setTestResult(false, "encodeActionURL incorrectly encoded a portlet action URL containing an invalid window state and parameter.  The resulting request contained the wrong parameter value. Expected: testValue  Received: " + paramValue);
            return Constants.TEST_FAILED;
        }
        testBean.setTestResult(true, "encodeActionURL correctly encoded a portlet action URL by ignoring the invalid window state and properly encoding the parameter.");
        return Constants.TEST_SUCCESS;
    }
}
Also used : WindowState(javax.portlet.WindowState) FacesContext(javax.faces.context.FacesContext) StateAwareResponse(javax.portlet.StateAwareResponse) PortletRequest(javax.portlet.PortletRequest) ExternalContext(javax.faces.context.ExternalContext) QName(javax.xml.namespace.QName) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 10 with StateAwareResponse

use of javax.portlet.StateAwareResponse in project liferay-faces-bridge-impl by liferay.

the class EncodeActionURLTests method encodeActionURLWithSecurityEventTest.

// Test is MultiRequest -- Render/Action
// Test #6.108
@BridgeTest(test = "encodeActionURLWithSecurityEventTest")
public String encodeActionURLWithSecurityEventTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    // This tests that we can encode a new security state in an actionURL done by navigation rule.
    if (BridgeUtil.getPortletRequestPhase(facesContext) == Bridge.PortletPhase.ACTION_PHASE) {
        // Create and raise the event
        StateAwareResponse stateAwareResponse = (StateAwareResponse) externalContext.getResponse();
        stateAwareResponse.setEvent(new QName(Constants.EVENT_QNAME, Constants.EVENT_NAME), testBean.getTestName());
        // action Navigation result
        return Constants.TEST_SUCCESS;
    } else {
        testBean.setTestComplete(true);
        PortletRequest portletRequest = (PortletRequest) facesContext.getExternalContext().getRequest();
        // Parameter/Secure encoded in the faces-config.xml target
        if (!portletRequest.isSecure()) {
            testBean.setTestResult(false, "encodeActionURL incorrectly encoded the portlet security state.  The resulting request wasn't in the expected 'secure' mode.");
            return Constants.TEST_FAILED;
        }
        // Check that the parameter came along too
        String paramValue = facesContext.getExternalContext().getRequestParameterMap().get("param1");
        if (paramValue == null) {
            testBean.setTestResult(false, "encodeActionURL incorrectly encoded a portlet action URL containing a new security state and parameter.  The resulting request didn't contain the expected 'param1' parameter.");
            return Constants.TEST_FAILED;
        }
        if (!paramValue.equals("testValue")) {
            testBean.setTestResult(false, "encodeActionURL incorrectly encoded a portlet action URL containing a new security state and parameter.  The resulting request contained the wrong parameter value. Expected: testValue  Received: " + paramValue);
            return Constants.TEST_FAILED;
        }
        testBean.setTestResult(true, "encodeActionURL correctly encoded a portlet action URL accessed in a secure state and parameter.");
        return Constants.TEST_SUCCESS;
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) StateAwareResponse(javax.portlet.StateAwareResponse) PortletRequest(javax.portlet.PortletRequest) ExternalContext(javax.faces.context.ExternalContext) QName(javax.xml.namespace.QName) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Aggregations

StateAwareResponse (javax.portlet.StateAwareResponse)34 ExternalContext (javax.faces.context.ExternalContext)29 FacesContext (javax.faces.context.FacesContext)29 QName (javax.xml.namespace.QName)27 BridgeTest (com.liferay.faces.bridge.tck.annotation.BridgeTest)26 PortletRequest (javax.portlet.PortletRequest)9 ActionEvent (javax.faces.event.ActionEvent)3 PhaseEvent (javax.faces.event.PhaseEvent)3 Event (javax.portlet.Event)3 ELContext (javax.el.ELContext)2 ELResolver (javax.el.ELResolver)2 UIViewRoot (javax.faces.component.UIViewRoot)2 PortletMode (javax.portlet.PortletMode)2 PortletSession (javax.portlet.PortletSession)2 WindowState (javax.portlet.WindowState)2 Bridge (javax.portlet.faces.Bridge)2 BridgeURL (javax.portlet.faces.BridgeURL)2 BridgePortalContext (com.liferay.faces.bridge.context.BridgePortalContext)1 BridgeURI (com.liferay.faces.bridge.internal.BridgeURI)1 FacesURLEncoder (com.liferay.faces.util.render.FacesURLEncoder)1