Search in sources :

Example 46 with BridgeTest

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

the class Tests method illegalRedirectRenderTest.

// Test #6.66
@BridgeTest(test = "illegalRedirectRenderTest")
public String illegalRedirectRenderTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    testBean.setTestComplete(true);
    String viewId = facesContext.getViewRoot().getViewId();
    if (viewId.equals("/tests/singleRequestTest.xhtml")) {
        try {
            externalContext.redirect(facesContext.getApplication().getViewHandler().getResourceURL(facesContext, "/tests/NonJSFView.portlet"));
        } catch (IllegalStateException i) {
            testBean.setTestResult(true, "externalContext.redirect() during render correctly threw the IllegalStateException when redirecting to a nonFaces view.");
            return Constants.TEST_SUCCESS;
        } catch (Exception e) {
            testBean.setTestResult(false, "Calling externalContext.redirect() threw an unexpected exception: " + e.getMessage());
            return Constants.TEST_FAILED;
        }
        testBean.setTestResult(false, "externalContext.redirect() during render failed: it didn't throw an illegalStateException when redirecting to a nonfaces view.");
        return Constants.TEST_FAILED;
    } else {
        testBean.setTestResult(false, "externalContext.redirect() during render failed: we started out in an unexpected view: " + viewId);
        return Constants.TEST_FAILED;
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) ExternalContext(javax.faces.context.ExternalContext) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 47 with BridgeTest

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

the class Tests method redirectRenderTest.

// Test #6.65
@BridgeTest(test = "redirectRenderTest")
public String redirectRenderTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    String viewId = facesContext.getViewRoot().getViewId();
    if (viewId.equals("/tests/singleRequestTest.xhtml")) {
        String target = facesContext.getApplication().getViewHandler().getActionURL(facesContext, "/tests/redirectTestResultRenderCheck.xhtml");
        try {
            externalContext.redirect(target);
        } catch (Exception e) {
            testBean.setTestComplete(true);
            testBean.setTestResult(false, "Calling externalContext.redirect() threw an exception: " + e.getMessage());
            return Constants.TEST_FAILED;
        }
        return "";
    } else if (viewId.equals("/tests/redirectTestResultRenderCheck.xhtml")) {
        testBean.setTestComplete(true);
        testBean.setTestResult(true, "externalContext.redirect() during render worked correctly as we were redirected to the new view.");
        return Constants.TEST_SUCCESS;
    } else {
        testBean.setTestResult(false, "externalContext.redirect() during render failed as we ended up in an unexpected view: " + viewId);
        return Constants.TEST_FAILED;
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) ExternalContext(javax.faces.context.ExternalContext) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 48 with BridgeTest

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

the class Tests method redirectEventTest.

// Test #6.131
@BridgeTest(test = "redirectEventTest")
public String redirectEventTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    if (BridgeUtil.getPortletRequestPhase(facesContext) == Bridge.PortletPhase.ACTION_PHASE) {
        /* Test works as follows:
			 *    set attribute on request scope   raise event which will invoke redirect   when called during render --
			 * check we are at the new view and attribute is gone   i.e. request scope isn't preserved in case of
			 * redirect.
			 */
        externalContext.getRequestMap().put("myRedirectRequestObject", Boolean.TRUE);
        // 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);
        String viewId = facesContext.getViewRoot().getViewId();
        if (viewId.equals("/tests/redirectTestResultRenderCheck.xhtml")) {
            // now verify that the scope wasn't saved.
            if (externalContext.getRequestMap().get("myRedirectRequestObject") == null) {
                testBean.setTestResult(true, "externalContext.redirect() during event worked correctly as we were redirected to the new view without retaining request scoped beans.");
            } else {
                testBean.setTestResult(false, "externalContext.redirect() during event failed as though we were redirected to the new view the request scope was retained.");
            }
        } else {
            testBean.setTestResult(false, "externalContext.redirect() during event failed as we weren't redirected to the new view. The viewId should be /tests/redirectTestResultRenderCheck.xhtml but is: " + viewId);
        }
        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 49 with BridgeTest

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

the class Tests method getRequestPathInfoTest.

// Test is SingleRequest -- tests whether parameters encoded in the defaultViewId's
// queryString are exposed as request parameters.
// Test #6.54
@BridgeTest(test = "getRequestPathInfoTest")
public String getRequestPathInfoTest(TestBean testBean) {
    testBean.setTestComplete(true);
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    String pathInfo = externalContext.getRequestPathInfo();
    // the value should be null
    if (pathInfo == null) {
        testBean.setTestResult(true, "Passed Header Phase: externalContext.getRequestPathInfo() correctly returned a null value as the Faces servlet is extension mapped.");
        return Constants.TEST_SUCCESS;
    } else {
        testBean.setTestResult(false, "Failed Header Phase: externalContext.getRequestPathInfo() returned a non-null value though null was expected as the Faces servlet is extension mapped.");
        return Constants.TEST_FAILED;
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) ExternalContext(javax.faces.context.ExternalContext) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 50 with BridgeTest

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

the class Tests method getResponseCharacterEncodingEventTest.

// Test is MultiRequest
// Test #6.126
@BridgeTest(test = "getResponseCharacterEncodingEventTest")
public String getResponseCharacterEncodingEventTest(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.getResponseCharacterEncoding() correctly threw an IllegalStateException 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)

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