Search in sources :

Example 21 with StateAwareResponse

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

the class Tests method getRequestCharacterEncodingEventTest.

// Test is MultiRequest
// Test #6.124
@BridgeTest(test = "getRequestCharacterEncodingEventTest")
public String getRequestCharacterEncodingEventTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    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 if (Bridge.PortletPhase.HEADER_PHASE.equals(BridgeUtil.getPortletRequestPhase(facesContext))) {
        testBean.setTestComplete(true);
        String eventMsg = (String) externalContext.getRequestMap().get("com.liferay.faces.bridge.tck.eventTestResult");
        if (eventMsg == null) {
            testBean.setTestResult(false, "Unexpected error:  the test's event handler wasn't called and hence the test didn't run.");
            return Constants.TEST_FAILED;
        // All out tests passed:
        } else if (eventMsg.equals(Constants.TEST_SUCCESS)) {
            testBean.setTestResult(true, "externalContext.getRequestCharacterEncoding() correctly returned null when called during the event phase.");
            return Constants.TEST_SUCCESS;
        } else {
            testBean.setTestResult(false, eventMsg);
            return Constants.TEST_FAILED;
        }
    } else {
        return "";
    }
}
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 22 with StateAwareResponse

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

the class Tests method getRequestHeaderMapEventTest.

// Test is MultiRequest
// Test #6.119
@BridgeTest(test = "getRequestHeaderMapEventTest")
public String getRequestHeaderMapEventTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    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 if (Bridge.PortletPhase.HEADER_PHASE.equals(BridgeUtil.getPortletRequestPhase(facesContext))) {
        testBean.setTestComplete(true);
        String eventMsg = (String) externalContext.getRequestMap().get("com.liferay.faces.bridge.tck.eventTestResult");
        if (eventMsg == null) {
            testBean.setTestResult(false, "Unexpected error:  the test's event handler wasn't called and hence the test didn't run.");
            return Constants.TEST_FAILED;
        // All out tests passed:
        } else if (eventMsg.equals(Constants.TEST_SUCCESS)) {
            // All out tests passed:
            testBean.setTestResult(true, "The immutable Map returned from getRequestHeaderMap correctly threw an exception when written to.");
            testBean.appendTestDetail("The getRequestHeaderMap Map correctly didn't contain the content-type property.");
            testBean.appendTestDetail("The getRequestHeaderMap Map correctly didn't contain the content-length property.");
            testBean.appendTestDetail("The getRequestHeaderMap Map correctly contained an Accept property with a value containing entries from the concatenation of request.getResponseContentTypes segmented by a comma.");
            testBean.appendTestDetail("The getRequestHeaderMap Map correctly contained an Accept-Language property with a value equal to the concatenation of request.getLocales segmented by a comma.");
            testBean.appendTestDetail("The getRequestHeaderMap Map correctly contained all other properties returned by request.getProperties.");
            return Constants.TEST_SUCCESS;
        } else {
            testBean.setTestResult(false, eventMsg);
            return Constants.TEST_FAILED;
        }
    } else {
        return "";
    }
}
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 23 with StateAwareResponse

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

the class EncodeActionURLTests method encodeActionURLWithInvalidSecurityEventTest.

// Test is MultiRequest -- Render/Action
// Test #6.109
@BridgeTest(test = "encodeActionURLWithInvalidSecurityEventTest")
public String encodeActionURLWithInvalidSecurityEventTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    // This tests that we can encode an invalid 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/Mode encoded in the faces-config.xml target
        if (portletRequest.isSecure()) {
            testBean.setTestResult(false, "encodeActionURL incorrectly encoded an invalid portlet security state.  The resulting request wasn't in the expected 'non-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 an invalid 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 an invalid 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 ontaining an invalid security 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)

Example 24 with StateAwareResponse

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

the class EncodeActionURLTests method encodeActionURLWithParamEventTest.

// Test is MultiRequest -- Render/Action
// Test #6.110
@BridgeTest(test = "encodeActionURLWithParamEventTest")
public String encodeActionURLWithParamEventTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    // This tests that we can encode a new name=value parameter 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);
        // Parameter encoded in the faces-config.xml target
        String paramValue = facesContext.getExternalContext().getRequestParameterMap().get("param1");
        if ((paramValue != null) && paramValue.equals("testValue")) {
            testBean.setTestResult(true, "encodeActionURL correctly encoded a portlet action URL containing a parameter during the event phase.");
            return Constants.TEST_SUCCESS;
        } else {
            if (paramValue == null) {
                testBean.setTestResult(false, "encodeActionURL incorrectly encoded a portlet action URL containing a parameter during the event phase.  The resulting request didn't contain the expected 'param1' parameter.");
            } else {
                testBean.setTestResult(false, "encodeActionURL incorrectly encoded a portlet action URL containing a parameter during the event phase.  The resulting request contained the wrong parameter value. Expected: testValue  Received: " + paramValue);
            }
        }
        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 25 with StateAwareResponse

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

the class EncodeActionURLTests method encodeActionURLWithWindowStateEventTest.

// Test is MultiRequest -- Render/Action
// Test #6.106
@BridgeTest(test = "encodeActionURLWithWindowStateEventTest")
public String encodeActionURLWithWindowStateEventTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    // This tests that we can encode a new 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("maximized")) {
            testBean.setTestResult(false, "encodeActionURL incorrectly encoded the new portlet window state.  The resulting request wasn't in the expected 'maximized' 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 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 a new 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 containing a new window state and 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)

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