Search in sources :

Example 6 with BridgeTest

use of com.liferay.faces.bridge.tck.annotation.BridgeTest in project liferay-faces-bridge-impl by liferay.

the class TestsCDI1 method actionRequestAlternativeTest.

@BridgeTest(test = "actionRequestAlternativeTest")
public String actionRequestAlternativeTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    Bridge.PortletPhase portletPhase = BridgeUtil.getPortletRequestPhase(facesContext);
    if (portletPhase == Bridge.PortletPhase.ACTION_PHASE) {
        bridgeRequestScopedBean.setFoo(actionRequest.getClass().getSimpleName());
        return "multiRequestTestResultRenderCheck";
    } else if (portletPhase == Bridge.PortletPhase.HEADER_PHASE) {
        if ("ActionRequestTCKImpl".equals(bridgeRequestScopedBean.getFoo())) {
            testBean.setTestResult(true, "The bridge's alternative producer for ActionRequest was properly invoked");
            return Constants.TEST_SUCCESS;
        } else {
            testBean.setTestResult(false, "The bridge's alternative producer for ActionRequest was not invoked");
            return Constants.TEST_FAILED;
        }
    }
    testBean.setTestResult(false, "Unexpected portletPhase=" + portletPhase);
    return Constants.TEST_FAILED;
}
Also used : FacesContext(javax.faces.context.FacesContext) Bridge(javax.portlet.faces.Bridge) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 7 with BridgeTest

use of com.liferay.faces.bridge.tck.annotation.BridgeTest in project liferay-faces-bridge-impl by liferay.

the class TestsCDI1 method stateAwareResponseAlternativeTest.

@BridgeTest(test = "stateAwareResponseAlternativeTest")
public String stateAwareResponseAlternativeTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    Bridge.PortletPhase portletPhase = BridgeUtil.getPortletRequestPhase(facesContext);
    if (portletPhase == Bridge.PortletPhase.ACTION_PHASE) {
        bridgeRequestScopedBean.setFoo(stateAwareResponse.getClass().getSimpleName());
        return "multiRequestTestResultRenderCheck";
    } else if (portletPhase == Bridge.PortletPhase.HEADER_PHASE) {
        if ("ActionResponseTCKImpl".equals(bridgeRequestScopedBean.getFoo())) {
            testBean.setTestResult(true, "The bridge's alternative producer for StateAwareResponse was properly invoked");
            return Constants.TEST_SUCCESS;
        } else {
            testBean.setTestResult(false, "The bridge's alternative producer for StateAwareResponse was not invoked");
            return Constants.TEST_FAILED;
        }
    }
    testBean.setTestResult(false, "Unexpected portletPhase=" + portletPhase);
    return Constants.TEST_FAILED;
}
Also used : FacesContext(javax.faces.context.FacesContext) Bridge(javax.portlet.faces.Bridge) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 8 with BridgeTest

use of com.liferay.faces.bridge.tck.annotation.BridgeTest in project liferay-faces-bridge-impl by liferay.

the class TestsCDI1 method bridgeRequestScopedBeanTest.

@BridgeTest(test = "bridgeRequestScopedBeanTest")
public String bridgeRequestScopedBeanTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    Bridge.PortletPhase portletPhase = BridgeUtil.getPortletRequestPhase(facesContext);
    if (portletPhase == Bridge.PortletPhase.ACTION_PHASE) {
        bridgeRequestScopedBean.setFoo("setInActionPhase");
        return "multiRequestTestResultRenderCheck";
    } else if (portletPhase == Bridge.PortletPhase.HEADER_PHASE) {
        testBean.setTestComplete(true);
        if ("setInActionPhase".equals(bridgeRequestScopedBean.getFoo())) {
            testBean.setTestResult(true, "@BridgeRequestScoped is behaving like faces-config <managed-bean> <scope>request&lt/scope> (bridge request scope)");
            return Constants.TEST_SUCCESS;
        } else {
            testBean.setTestResult(false, "@BridgeRequestScoped is behaving like @PortletRequestScoped");
            return Constants.TEST_FAILED;
        }
    }
    testBean.setTestResult(false, "Unexpected portletPhase=" + portletPhase);
    return Constants.TEST_FAILED;
}
Also used : FacesContext(javax.faces.context.FacesContext) Bridge(javax.portlet.faces.Bridge) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 9 with BridgeTest

use of com.liferay.faces.bridge.tck.annotation.BridgeTest in project liferay-faces-bridge-impl by liferay.

the class Tests method portletRequestScopedBeanExtensionTest.

@BridgeTest(test = "portletRequestScopedBeanExtensionTest")
public String portletRequestScopedBeanExtensionTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    Bridge.PortletPhase portletPhase = BridgeUtil.getPortletRequestPhase(facesContext);
    if (portletPhase == Bridge.PortletPhase.ACTION_PHASE) {
        portletRequestScopedBeanExtension.setFoo("setInActionPhase");
        return "multiRequestTestResultRenderCheck";
    } else if (portletPhase == Bridge.PortletPhase.HEADER_PHASE) {
        testBean.setTestComplete(true);
        if ("setInActionPhase".equals(portletRequestScopedBeanExtension.getFoo())) {
            testBean.setTestResult(true, "@PortletRequestScoped is behaving like faces-config <managed-bean> <scope>request&lt/scope> (bridge request scope)");
            return Constants.TEST_SUCCESS;
        } else {
            testBean.setTestResult(false, "@PortletRequestScoped is behaving like Portlet 3.0 @PortletRequestScoped rather than @BridgeRequestScoped");
            return Constants.TEST_FAILED;
        }
    }
    testBean.setTestResult(false, "Unexpected portletPhase=" + portletPhase);
    return Constants.TEST_FAILED;
}
Also used : FacesContext(javax.faces.context.FacesContext) Bridge(javax.portlet.faces.Bridge) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 10 with BridgeTest

use of com.liferay.faces.bridge.tck.annotation.BridgeTest in project liferay-faces-bridge-impl by liferay.

the class EncodeActionURLResourceTests method encodeActionURLWithModeResourceTest.

// Test is MultiRequest -- Render/Action
// Test #6.112
@BridgeTest(test = "encodeActionURLWithModeResourceTest")
public String encodeActionURLWithModeResourceTest(TestBean testBean) {
    // Somewhat of a weird test -- we can't test this directly in that there isn't a way to encode an JSF view
    // actionURL into the response of the resource and have it clicked on.  We also can't generate such an url and
    // compare against the one generated by the underlying response because encodeActionURL will encode the JSF view
    // into the returned string in a manner that is bridge impl specific (so we can't account for this encoding). So
    // instead, perform the same encoding in both other phased request and the resource request.  If they are the
    // same then the test passes.  This works (indirectly) because we have an existing test that verifies this
    // encoding during a render/action phase.  So the presumption is if it works for render/action and you get the
    // same url during from the encoding during a resource then all is good.
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    Map<String, Object> requestMap = externalContext.getRequestMap();
    Map<String, Object> sessionMap = externalContext.getSessionMap();
    final String ENCODE_ACTIONURL_TEST_STRING = "/tests/viewLink.jsf?javax.portlet.faces.PortletMode=edit&param1=testValue";
    // ensure this url is prefixed by the ContextPath as all encode routines expect this for things starting with /
    String testString = externalContext.getRequestContextPath() + ENCODE_ACTIONURL_TEST_STRING;
    if (BridgeUtil.getPortletRequestPhase(facesContext) == Bridge.PortletPhase.RESOURCE_PHASE) {
        // mark the resource request as having occurred so the button changes names appropriately
        requestMap.put("com.liferay.faces.bridge.tck.pprSubmitted", Boolean.TRUE);
        // Now run the test
        testBean.setTestComplete(true);
        // PortletContainers can return "URLs" with strict XML encoding -- as the bridge
        // encoding depends on what is past in to it -- make sure we send in a string
        // with the same encoding as compare string.
        String resourceEncoded = externalContext.encodeActionURL(testString);
        String otherPhaseEncoded = (String) sessionMap.get("com.liferay.faces.bridge.tck.encodedURL");
        // remove it for future/other tests
        sessionMap.remove("com.liferay.faces.bridge.tck.encodedURL");
        if (otherPhaseEncoded == null) {
            testBean.setTestResult(false, "test failed because it relies on comparing the encoded result with one generated during a prior phase, however the one generated from the prior phase isn't there.");
            return Constants.TEST_FAILED;
        } else if (resourceEncoded.equals(otherPhaseEncoded)) {
            testBean.setTestResult(true, "encodeActionURL correctly encoded a JSF View url with mode as an actionURL during a resource request.");
            return Constants.TEST_SUCCESS;
        } else {
            testBean.setTestResult(false, "encodeActionURL incorrectly encoded a JSF View url with mode as an actionURL during a resource request.  In encoding: " + testString + " the bridge returned: " + resourceEncoded + " but the corresponding portletURL encoding returned: " + otherPhaseEncoded);
            return Constants.TEST_FAILED;
        }
    }
    // Otherwise -- no output
    if (sessionMap.get("com.liferay.faces.bridge.tck.encodedURL") == null) {
        sessionMap.put("com.liferay.faces.bridge.tck.encodedURL", externalContext.encodeActionURL(testString));
    }
    return "";
}
Also used : FacesContext(javax.faces.context.FacesContext) ExternalContext(javax.faces.context.ExternalContext) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Aggregations

BridgeTest (com.liferay.faces.bridge.tck.annotation.BridgeTest)204 FacesContext (javax.faces.context.FacesContext)201 ExternalContext (javax.faces.context.ExternalContext)166 PortletRequest (javax.portlet.PortletRequest)40 StateAwareResponse (javax.portlet.StateAwareResponse)26 QName (javax.xml.namespace.QName)26 Bridge (javax.portlet.faces.Bridge)19 Map (java.util.Map)17 PortletContext (javax.portlet.PortletContext)10 MimeResponse (javax.portlet.MimeResponse)9 RenderRequest (javax.portlet.RenderRequest)9 Enumeration (java.util.Enumeration)8 Locale (java.util.Locale)8 PortletMode (javax.portlet.PortletMode)7 WindowState (javax.portlet.WindowState)7 ELResolver (javax.el.ELResolver)6 IOException (java.io.IOException)5 ELContext (javax.el.ELContext)5 ViewHandler (javax.faces.application.ViewHandler)5 UIViewRoot (javax.faces.component.UIViewRoot)5