Search in sources :

Example 91 with BridgeTest

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

the class Tests method portletNamingContainerClientIdTest.

// Test is SingleRequest -- Render
// Test #6.91
@BridgeTest(test = "portletNamingContainerClientIdTest")
public String portletNamingContainerClientIdTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    UIViewRoot uiViewRoot = facesContext.getViewRoot();
    String namespace = ((MimeResponse) facesContext.getExternalContext().getResponse()).getNamespace();
    testBean.setTestComplete(true);
    if (uiViewRoot.getClass().getAnnotation(PortletNamingContainer.class) != null) {
        if (uiViewRoot.getContainerClientId(facesContext).indexOf(namespace) >= 0) {
            testBean.setTestResult(true, "UIViewRoot getClientContainerId includes the portlet namespace id.");
            return Constants.TEST_SUCCESS;
        } else {
            testBean.setTestResult(false, "UIViewRoot getClientContainerId doesn not includes the portlet namespace id.");
            return Constants.TEST_FAILED;
        }
    } else {
        testBean.setTestResult(false, "UIViewRoot is not annotated with javax.portlet.faces.annotation.PortletNamingContainer.");
        return Constants.TEST_FAILED;
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) PortletNamingContainer(javax.portlet.faces.annotation.PortletNamingContainer) MimeResponse(javax.portlet.MimeResponse) UIViewRoot(javax.faces.component.UIViewRoot) PortletNamingContainerUIViewRoot(javax.portlet.faces.component.PortletNamingContainerUIViewRoot) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 92 with BridgeTest

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

the class Tests method eventScopeNotRestoredModeChangedTest.

// Test is MultiRequest -- Render/Action
// Test # -- 5.50
@BridgeTest(test = "eventScopeNotRestoredModeChangedTest")
public String eventScopeNotRestoredModeChangedTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    // are explicitly excluded -- test for presence/absence in render
    if (BridgeUtil.getPortletRequestPhase(facesContext) == Bridge.PortletPhase.ACTION_PHASE) {
        // Clear settings from previous run of the test
        externalContext.getSessionMap().put(Ch5TestEventHandler.EVENT_RECEIVED, null);
        externalContext.getSessionMap().put(Ch5TestEventHandler.EVENT_TEST_FAILED, null);
        // Place a request attr in scope so we can make sure its not there later
        externalContext.getRequestMap().put(Ch5TestEventHandler.EVENTATTR, testBean.getTestName());
        // 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 "eventScopeNotRestoredModeChangedTest";
    } else {
        testBean.setTestComplete(true);
        // Values set by portlet at end of action
        Event event = (Event) externalContext.getSessionMap().get(Ch5TestEventHandler.EVENT_RECEIVED);
        String failedMsg = (String) externalContext.getSessionMap().get(Ch5TestEventHandler.EVENT_TEST_FAILED);
        String payload = (String) externalContext.getRequestMap().get(Ch5TestEventHandler.EVENTATTR);
        if (event == null) {
            testBean.setTestResult(false, "Raised event wasn't received.");
            return Constants.TEST_FAILED;
        } else if (failedMsg != null) {
            testBean.setTestResult(false, failedMsg);
            return Constants.TEST_FAILED;
        } else if (payload != null) {
            testBean.setTestResult(false, "Event navigation indicated a mode change but the request scope was preserved.");
            return Constants.TEST_FAILED;
        } else {
            testBean.setTestResult(true, "Request scope not preserved after event navigation indicated a mode change.");
            return Constants.TEST_SUCCESS;
        }
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) StateAwareResponse(javax.portlet.StateAwareResponse) ExternalContext(javax.faces.context.ExternalContext) QName(javax.xml.namespace.QName) ActionEvent(javax.faces.event.ActionEvent) PhaseEvent(javax.faces.event.PhaseEvent) Event(javax.portlet.Event) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 93 with BridgeTest

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

the class Tests method facesContextReleasedActionTest.

// Test is MultiRequest -- Render/Action
// Test #5.25
@BridgeTest(test = "facesContextReleasedActionTest")
public String facesContextReleasedActionTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    // are explicitly excluded -- test for presence/absence in render
    if (BridgeUtil.getPortletRequestPhase(facesContext) == Bridge.PortletPhase.ACTION_PHASE) {
        // action Navigation result
        return "facesContextReleasedActionTest";
    } else {
        testBean.setTestComplete(true);
        // Values set by portlet at end of action
        boolean result = ((Boolean) externalContext.getSessionMap().get("org.apache.portlet.faces.tck.testResult")).booleanValue();
        testBean.setTestResult(result, (String) externalContext.getSessionMap().get("org.apache.portlet.faces.tck.testDetail"));
        if (result) {
            return Constants.TEST_SUCCESS;
        } else {
            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 94 with BridgeTest

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

the class Tests method viewIdWithParam_2_Test.

// Test is MultiRequest -- Render/Action
// Test #5.20 (second test of 2) -- viewId set in the default viewId (initparam)
@BridgeTest(test = "viewIdWithParam_2_Test")
public String viewIdWithParam_2_Test(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    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, "Bridge correctly included parameter from viewId querystring when using default viewId.");
        return Constants.TEST_SUCCESS;
    } else {
        if (paramValue == null) {
            testBean.setTestResult(false, "Bridge didn't included parameter from viewId querystring when using default viewId.");
        } else {
            testBean.setTestResult(false, "Bridge didn't properly include parameter from viewId querystring when using default viewId.  The resulting request contained the wrong parameter value. Expected: testValue  Received: " + paramValue);
        }
    }
    return Constants.TEST_FAILED;
}
Also used : FacesContext(javax.faces.context.FacesContext) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 95 with BridgeTest

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

the class Tests method scopeNotRestoredResourceTest.

// Test is MultiRequest -- Render/Action
// Test # -- 5.65
@BridgeTest(test = "scopeNotRestoredResourceTest")
public String scopeNotRestoredResourceTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    Map<String, Object> requestMap = externalContext.getRequestMap();
    if (BridgeUtil.getPortletRequestPhase(facesContext) == Bridge.PortletPhase.ACTION_PHASE) {
        // set a request scoped attr and then continue
        requestMap.put("testAttr", testBean.getTestName());
        return "scopeNotRestoredResourceTest";
    }
    // are explicitly excluded -- test for presence/absence in render
    if (BridgeUtil.getPortletRequestPhase(facesContext) == Bridge.PortletPhase.RESOURCE_PHASE) {
        String s = (String) requestMap.get("testAttr");
        if (s == null) {
            testBean.setTestResult(true, "Resource request correctly executed without restoring request scope.");
            return Constants.TEST_SUCCESS;
        } else {
            testBean.setTestResult(false, "Resource request incorrectly has restored the request scope.");
            return Constants.TEST_FAILED;
        }
    } else {
        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