use of javax.portlet.StateAwareResponse in project liferay-faces-bridge-impl by liferay.
the class Tests method getRequestCharacterEncodingEventTest.
// Test is MultiRequest
// Test #6.124
@BridgeTest(test = "getRequestCharacterEncodingEventTest")
public String getRequestCharacterEncodingEventTest(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.getRequestCharacterEncoding() 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 getRequestHeaderMapEventTest.
// Test is MultiRequest
// Test #6.119
@BridgeTest(test = "getRequestHeaderMapEventTest")
public String getRequestHeaderMapEventTest(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 getRequestHeaderMap correctly threw an exception when written to.");
testBean.appendTestDetail("The getRequestHeaderMap Map correctly didn't contain the content-type property.");
testBean.appendTestDetail("The getRequestHeaderMap Map correctly didn't contain the content-length property.");
testBean.appendTestDetail("The getRequestHeaderMap Map correctly contained an Accept property with a value containing entries from the concatenation of request.getResponseContentTypes segmented by a comma.");
testBean.appendTestDetail("The getRequestHeaderMap Map correctly contained an Accept-Language property with a value equal to the concatenation of request.getLocales segmented by a comma.");
testBean.appendTestDetail("The getRequestHeaderMap 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 EncodeActionURLTests method encodeActionURLWithInvalidSecurityEventTest.
// Test is MultiRequest -- Render/Action
// Test #6.109
@BridgeTest(test = "encodeActionURLWithInvalidSecurityEventTest")
public String encodeActionURLWithInvalidSecurityEventTest(TestBean testBean) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
// This tests that we can encode an invalid security state in an actionURL done by navigation rule.
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 {
testBean.setTestComplete(true);
PortletRequest portletRequest = (PortletRequest) facesContext.getExternalContext().getRequest();
// Parameter/Mode encoded in the faces-config.xml target
if (portletRequest.isSecure()) {
testBean.setTestResult(false, "encodeActionURL incorrectly encoded an invalid portlet security state. The resulting request wasn't in the expected 'non-secure' mode.");
return Constants.TEST_FAILED;
}
// Check that the parameter came along too
String paramValue = facesContext.getExternalContext().getRequestParameterMap().get("param1");
if (paramValue == null) {
testBean.setTestResult(false, "encodeActionURL incorrectly encoded a portlet action URL containing an invalid security state and parameter. The resulting request didn't contain the expected 'param1' parameter.");
return Constants.TEST_FAILED;
}
if (!paramValue.equals("testValue")) {
testBean.setTestResult(false, "encodeActionURL incorrectly encoded a portlet action URL containing an invalid security state and parameter. The resulting request contained the wrong parameter value. Expected: testValue Received: " + paramValue);
return Constants.TEST_FAILED;
}
testBean.setTestResult(true, "encodeActionURL correctly encoded a portlet action URL ontaining an invalid security state and parameter.");
return Constants.TEST_SUCCESS;
}
}
use of javax.portlet.StateAwareResponse in project liferay-faces-bridge-impl by liferay.
the class EncodeActionURLTests method encodeActionURLWithParamEventTest.
// Test is MultiRequest -- Render/Action
// Test #6.110
@BridgeTest(test = "encodeActionURLWithParamEventTest")
public String encodeActionURLWithParamEventTest(TestBean testBean) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
// This tests that we can encode a new name=value parameter in an actionURL done by navigation rule.
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 {
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, "encodeActionURL correctly encoded a portlet action URL containing a parameter during the event phase.");
return Constants.TEST_SUCCESS;
} else {
if (paramValue == null) {
testBean.setTestResult(false, "encodeActionURL incorrectly encoded a portlet action URL containing a parameter during the event phase. The resulting request didn't contain the expected 'param1' parameter.");
} else {
testBean.setTestResult(false, "encodeActionURL incorrectly encoded a portlet action URL containing a parameter during the event phase. The resulting request contained the wrong parameter value. Expected: testValue Received: " + paramValue);
}
}
return Constants.TEST_FAILED;
}
}
use of javax.portlet.StateAwareResponse in project liferay-faces-bridge-impl by liferay.
the class EncodeActionURLTests method encodeActionURLWithWindowStateEventTest.
// Test is MultiRequest -- Render/Action
// Test #6.106
@BridgeTest(test = "encodeActionURLWithWindowStateEventTest")
public String encodeActionURLWithWindowStateEventTest(TestBean testBean) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
// This tests that we can encode a new window state in an actionURL done by navigation rule.
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 {
testBean.setTestComplete(true);
PortletRequest portletRequest = (PortletRequest) facesContext.getExternalContext().getRequest();
// Parameter/Mode encoded in the faces-config.xml target
WindowState windowState = portletRequest.getWindowState();
if ((windowState == null) || !windowState.toString().equalsIgnoreCase("maximized")) {
testBean.setTestResult(false, "encodeActionURL incorrectly encoded the new portlet window state. The resulting request wasn't in the expected 'maximized' mode.");
return Constants.TEST_FAILED;
}
// Check that the parameter came along too
String paramValue = facesContext.getExternalContext().getRequestParameterMap().get("param1");
if (paramValue == null) {
testBean.setTestResult(false, "encodeActionURL incorrectly encoded a portlet action URL containing a new window state and parameter. The resulting request didn't contain the expected 'param1' parameter.");
return Constants.TEST_FAILED;
}
if (!paramValue.equals("testValue")) {
testBean.setTestResult(false, "encodeActionURL incorrectly encoded a portlet action URL containing a new window state and parameter. The resulting request contained the wrong parameter value. Expected: testValue Received: " + paramValue);
return Constants.TEST_FAILED;
}
testBean.setTestResult(true, "encodeActionURL correctly encoded a portlet action URL containing a new window state and parameter.");
return Constants.TEST_SUCCESS;
}
}
Aggregations