Search in sources :

Example 96 with BridgeTest

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

the class Tests method prpUpdatedFromActionTest.

// Test is MultiRequest -- Render/Action
// Test # -- 5.74
@BridgeTest(test = "prpUpdatedFromActionTest")
public String prpUpdatedFromActionTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    Map<String, Object> requestMap = externalContext.getRequestMap();
    // are explicitly excluded -- test for presence/absence in render
    if (BridgeUtil.getPortletRequestPhase(facesContext) == Bridge.PortletPhase.ACTION_PHASE) {
        // Now verify that a change to a public render parameter is carried forward
        String currentValue = (String) requestMap.get("modelPRP");
        if (currentValue == null) {
            currentValue = "1";
        } else {
            currentValue = currentValue.concat("1");
        }
        // Config is setup to exclude this value from bridge request scope -- so only get carried forward
        // if received in render request
        requestMap.put("modelPRP", currentValue);
        // Stash copy of value in an attr that is carried forward to compare.
        requestMap.put("tck.compareModelPRPValue", currentValue);
        // action Navigation result
        return "prpUpdatedFromActionTest";
    } else {
        testBean.setTestComplete(true);
        // Values set by portlet at end of action
        String modelPRP = (String) externalContext.getRequestMap().get("modelPRP");
        String checkPRP = (String) externalContext.getRequestMap().get("tck.compareModelPRPValue");
        if (modelPRP == null) {
            testBean.setTestResult(false, "(Public) Render parameter set in action phase wasn't received/value pushed to its model in the header/render phase.");
            return Constants.TEST_FAILED;
        } else if ((checkPRP == null) || !modelPRP.equals(checkPRP)) {
            testBean.setTestResult(false, "(Public) Render parameter value set in action phase isn't set in the model in the render.  PRP model value: " + modelPRP + " but expected: " + checkPRP);
            return Constants.TEST_FAILED;
        } else {
            testBean.setTestResult(true, "(Public) Render parameter whose underlying model value was set during action phase was properly carried forward into the render.");
            return Constants.TEST_SUCCESS;
        }
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) ExternalContext(javax.faces.context.ExternalContext) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 97 with BridgeTest

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

the class Tests method ignoreCurrentViewIdModeChangeTest.

// Test is MultiRequest -- Render/Action
// Test #5.19
@BridgeTest(test = "ignoreCurrentViewIdModeChangeTest")
public String ignoreCurrentViewIdModeChangeTest(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 "ignoreCurrentViewIdModeChangeTest";
    } else {
        // If redisplay hasn't been invoked yet -- merely return
        if (externalContext.getRequestParameterMap().get("org.apache.portlet.faces.tck.redisplay") == null) {
            return "ignoreCurrentViewIdModeChangeTest";
        }
        // We should now be in the default view for edit Mode
        String viewId = facesContext.getViewRoot().getViewId();
        testBean.setTestComplete(true);
        if (viewId.equals("/tests/multiRequestTestResultRenderCheck.xhtml")) {
            testBean.setTestResult(true, "Second render correctly used the default view because there was a mode change.");
            return Constants.TEST_SUCCESS;
        } else {
            testBean.setTestResult(false, "Second render incorrectly rerendered existing view though there was a view change.");
            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 98 with BridgeTest

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

the class Tests method eventPhaseListenerTest.

// Test is SingleRequest -- Render/Action
// Test #5.33 --
@BridgeTest(test = "eventPhaseListenerTest")
public String eventPhaseListenerTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    Map<String, Object> requestMap = externalContext.getRequestMap();
    if (BridgeUtil.getPortletRequestPhase(facesContext) == Bridge.PortletPhase.ACTION_PHASE) {
        StateAwareResponse stateAwareResponse = (StateAwareResponse) externalContext.getResponse();
        stateAwareResponse.setEvent(new QName(Constants.EVENT_QNAME, Constants.EVENT_NAME), testBean.getTestName());
        // action Navigation result
        return "eventPhaseListenerTest";
    } else {
        testBean.setTestComplete(true);
        // Phase Listener (below) has set these attributes
        PhaseId lastBeforePhaseId = (PhaseId) requestMap.get("org.apache.portlet.faces.tck.lastBeforePhase");
        PhaseId lastAfterPhaseId = (PhaseId) requestMap.get("org.apache.portlet.faces.tck.lastAfterPhase");
        if ((lastBeforePhaseId == null) || (lastAfterPhaseId == null)) {
            testBean.setTestResult(false, "Event incorrectly didn't invoke either or both the RESTORE_VIEW before/after listener.  Its also possible the event wasn't received.");
            return Constants.TEST_FAILED;
        } else if ((lastBeforePhaseId == PhaseId.RESTORE_VIEW) && (lastAfterPhaseId == PhaseId.RESTORE_VIEW)) {
            testBean.setTestResult(true, "Event properly invoked the RESTORE_VIEW phase including calling its before/after listeners and didnt' execute any other action phases.");
            return Constants.TEST_SUCCESS;
        } else {
            testBean.setTestResult(false, "Event incorrectly executed an action phase/listener post RESTORE_VIEW: lastBeforePhase: " + lastBeforePhaseId.toString() + " lastAfterPhase: " + lastAfterPhaseId.toString());
            return Constants.TEST_FAILED;
        }
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) PhaseId(javax.faces.event.PhaseId) StateAwareResponse(javax.portlet.StateAwareResponse) ExternalContext(javax.faces.context.ExternalContext) QName(javax.xml.namespace.QName) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 99 with BridgeTest

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

the class Tests method eventControllerTest.

// Test is MultiRequest -- Render/Action
// Test # -- 5.54, 5.55, 5.56, 5.57. 5.58
@BridgeTest(test = "eventControllerTest")
public String eventControllerTest(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: Done here because this render doesn't happen in scope so
        // second rendition doesn't keep the test result -- rather rerenders
        externalContext.getSessionMap().put(Ch5TestEventHandler.EVENT_RECEIVED, null);
        externalContext.getSessionMap().put(Ch5TestEventHandler.EVENT_TEST_FAILED, null);
        // Set a render parameter so we can verify its there after the event
        StateAwareResponse stateAwareResponse = (StateAwareResponse) externalContext.getResponse();
        stateAwareResponse.setRenderParameter("tck.renderParam", "value");
        // Create and raise the event
        stateAwareResponse.setEvent(new QName(Constants.EVENT_QNAME, Constants.EVENT_NAME), testBean.getTestName());
        // action Navigation result
        return "eventControllerTest";
    } else {
        testBean.setTestComplete(true);
        // Values set by portlet at end of action
        Boolean eventPhaseCheck = (Boolean) externalContext.getRequestMap().get("tck.eventPhaseCheck");
        String modelPRP = (String) externalContext.getRequestMap().get("modelPRP");
        String checkPRP = (String) externalContext.getRequestMap().get("tck.compareModelPRPValue");
        // Verify the render parameter set in action is still there
        String param = (String) externalContext.getRequestParameterMap().get("tck.renderParam");
        if (eventPhaseCheck == null) {
            testBean.setTestResult(false, "Registered Event handler wasn't called to handle raised event.");
            return Constants.TEST_FAILED;
        } else if (!eventPhaseCheck.booleanValue()) {
            testBean.setTestResult(false, "Expected EVENT_PHASE request attribute not set during event processing.");
            return Constants.TEST_FAILED;
        } else if (param == null) {
            testBean.setTestResult(false, "Render parameter set in action phase not carried forward through the event phase into the header/render phase.");
            return Constants.TEST_FAILED;
        } else if (!param.equals("value")) {
            testBean.setTestResult(false, "(Private) Render parameter set in action phase carried forward through the event phase into the header/render phase but with an unexpected value.  Received: " + param + " but expected: value");
            return Constants.TEST_FAILED;
        } else if (modelPRP == null) {
            testBean.setTestResult(false, "(Public) Render parameter set in event phase wasn't received/value pushed to its model in the header/render phase.");
            return Constants.TEST_FAILED;
        } else if ((checkPRP == null) || !modelPRP.equals(checkPRP)) {
            testBean.setTestResult(false, "(Public) Render parameter value set in event phase isn't set in the model in the render.  PRP model value: " + modelPRP + " but expected: " + checkPRP);
            return Constants.TEST_FAILED;
        } else {
            testBean.setTestResult(true, "Event controller tests passed.<br>Registered event handler called and its navigational result processed corectly.");
            testBean.appendTestDetail("EVENT_PHASE attribute correctly set during event processing.");
            testBean.appendTestDetail("(Private) Render parameter set during action phase was properly carried forward from the event phase.");
            testBean.appendTestDetail("(Public) Render parameter whose underlying model value was set during event phase was properly carried forward into the render.");
            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) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 100 with BridgeTest

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

the class Tests method facesContextReleasedEventTest.

// Test is MultiRequest -- Render/Action
// Test #5.59
@BridgeTest(test = "facesContextReleasedEventTest")
public String facesContextReleasedEventTest(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) {
        // 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 "facesContextReleasedEventTest";
    } 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) 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