use of javax.portlet.StateAwareResponse 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;
}
}
}
use of javax.portlet.StateAwareResponse 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 "";
}
}
use of javax.portlet.StateAwareResponse in project liferay-faces-bridge-impl by liferay.
the class Tests method getResponseContentTypeEventTest.
// Test is MultiRequest
// Test #6.130
@BridgeTest(test = "getResponseContentTypeEventTest")
public String getResponseContentTypeEventTest(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.getResponseContentType() correctly returned null when called during the event phase.");
return Constants.TEST_SUCCESS;
} else {
testBean.setTestResult(false, eventMsg);
return Constants.TEST_FAILED;
}
} else {
return "";
}
}
use of javax.portlet.StateAwareResponse in project liferay-faces-bridge-impl by liferay.
the class Tests method getRequestHeaderValuesMapEventTest.
// Test is MultiRequest
// Test #6.119
@BridgeTest(test = "getRequestHeaderValuesMapEventTest")
public String getRequestHeaderValuesMapEventTest(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)) {
// All out tests passed:
testBean.setTestResult(true, "The immutable Map returned from getRequestHeaderValuesMap correctly threw an exception when written to.");
testBean.appendTestDetail("The getRequestHeaderValuesMap Map correctly didn't contain the content-type property.");
testBean.appendTestDetail("The getRequestHeaderValuesMap Map correctly didn't contain the content-length property.");
testBean.appendTestDetail("The getRequestHeaderValuesMap Map correctly contained an Accept property with a value containing entries from the concatenation of request.getResponseContentTypes segmented by a comma.");
testBean.appendTestDetail("The getRequestHeaderValuesMap Map correctly contained an Accept-Language property with a value equal to the concatenation of request.getLocales segmented by a comma.");
testBean.appendTestDetail("The getRequestHeaderValuesMap Map correctly contained all other properties returned by request.getProperties.");
return Constants.TEST_SUCCESS;
} else {
testBean.setTestResult(false, eventMsg);
return Constants.TEST_FAILED;
}
} else {
return "";
}
}
use of javax.portlet.StateAwareResponse 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;
}
}
}
Aggregations