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;
}
}
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;
}
}
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;
}
}
}
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;
}
}
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 "";
}
}
Aggregations