use of javax.portlet.StateAwareResponse 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;
}
}
}
use of javax.portlet.StateAwareResponse 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;
}
}
}
use of javax.portlet.StateAwareResponse 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;
}
}
}
use of javax.portlet.StateAwareResponse in project gatein-portal by Meeds-io.
the class PortletRequestContext method setApplicationMode.
public void setApplicationMode(PortletMode mode) throws PortletModeException {
if (response_ instanceof StateAwareResponse) {
StateAwareResponse res = (StateAwareResponse) response_;
res.setPortletMode(mode);
} else {
throw new PortletModeException("The portlet don't support to set a portlet mode by current runtime environment", mode);
}
}
use of javax.portlet.StateAwareResponse in project liferay-faces-bridge-impl by liferay.
the class Tests method getRequestContentTypeEventTest.
// Test is MultiRequest
// Test #6.126
@BridgeTest(test = "getRequestContentTypeEventTest")
public String getRequestContentTypeEventTest(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.getRequestContentType() correctly returned null when called during the event phase.");
return Constants.TEST_SUCCESS;
} else {
testBean.setTestResult(false, eventMsg);
return Constants.TEST_FAILED;
}
} else {
return "";
}
}
Aggregations