use of com.liferay.faces.bridge.tck.annotation.BridgeTest in project liferay-faces-bridge-impl by liferay.
the class EncodeActionURLTests method encodeActionURLPortletActionTest.
// Test is SingleRequest -- Render only
// Test #6.9
@BridgeTest(test = "encodeActionURLPortletActionTest")
public String encodeActionURLPortletActionTest(TestBean testBean) {
testBean.setTestComplete(true);
final String PORTLET_ACTION_TEST_STRING = "portlet:action?param1=value1¶m2=value2";
final String PORTLET_ACTION_TEST_STRING_XMLENCODED = "portlet:action?param1=value1&param2=value2";
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
MimeResponse response = (MimeResponse) externalContext.getResponse();
PortletURL portletURL = response.createActionURL();
portletURL.setParameter("param1", "value1");
portletURL.setParameter("param2", "value2");
StringWriter sw = new StringWriter(50);
String portletEncoded = null;
try {
portletURL.write(sw, true);
portletEncoded = sw.toString();
} catch (Exception e) {
portletEncoded = portletURL.toString();
}
// PortletContainers can return "URLs" with strict XML encoding -- as the bridge
// encoding depends on what is past in to it -- make sure we send in a string
// with the same encoding as compare string.
String bridgeEncoded = null;
if (EncodeURLTestUtil.isStrictXhtmlEncoded(portletEncoded)) {
bridgeEncoded = externalContext.encodeActionURL(PORTLET_ACTION_TEST_STRING_XMLENCODED);
} else {
bridgeEncoded = externalContext.encodeActionURL(PORTLET_ACTION_TEST_STRING);
}
if (bridgeEncoded.equals(portletEncoded)) {
testBean.setTestResult(true, "encodeActionURL correctly encoded a portlet action URL as an actionURL using the portlet: syntax.");
return Constants.TEST_SUCCESS;
} else {
testBean.setTestResult(false, "encodeActionURL incorrectly encoded a portlet action URL as an actionURL using the portlet: syntax. In encoding: " + PORTLET_ACTION_TEST_STRING + " the bridge returned: " + bridgeEncoded + " but the corresponding portletURL encoding returned: " + portletEncoded);
return Constants.TEST_FAILED;
}
}
use of com.liferay.faces.bridge.tck.annotation.BridgeTest in project liferay-faces-bridge-impl by liferay.
the class EncodeActionURLTests method encodeActionURLWithInvalidWindowStateEventTest.
// Test is MultiRequest -- Render/Action
// Test #6.107
@BridgeTest(test = "encodeActionURLWithInvalidWindowStateEventTest")
public String encodeActionURLWithInvalidWindowStateEventTest(TestBean testBean) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
// This tests that we can encode an invalid 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("normal")) {
testBean.setTestResult(false, "encodeActionURL incorrectly encoded the invalid window state. The resulting request should have ignored the invalid window state and remained in 'normal' 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 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 an invalid 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 by ignoring the invalid window state and properly encoding the parameter.");
return Constants.TEST_SUCCESS;
}
}
use of com.liferay.faces.bridge.tck.annotation.BridgeTest in project liferay-faces-bridge-impl by liferay.
the class EncodeActionURLTests method encodeActionURLWithSecurityEventTest.
// Test is MultiRequest -- Render/Action
// Test #6.108
@BridgeTest(test = "encodeActionURLWithSecurityEventTest")
public String encodeActionURLWithSecurityEventTest(TestBean testBean) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
// This tests that we can encode a new 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/Secure encoded in the faces-config.xml target
if (!portletRequest.isSecure()) {
testBean.setTestResult(false, "encodeActionURL incorrectly encoded the portlet security state. The resulting request wasn't in the expected '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 a new 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 a new 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 accessed in a secure state and parameter.");
return Constants.TEST_SUCCESS;
}
}
use of com.liferay.faces.bridge.tck.annotation.BridgeTest in project liferay-faces-bridge-impl by liferay.
the class EncodePartialActionURLTests method encodePartialActionURLTest.
@BridgeTest(test = "encodePartialActionURLTest")
public String encodePartialActionURLTest(TestBean testBean) {
// Test is invoked from resourceAjaxResult.xhtml which simply submits a form via Ajax.
FacesContext facesContext = FacesContext.getCurrentInstance();
// that means the form was submitted via Ajax with a URL that caused the bridge to invoke the JSF lifecycle.
if (BridgeUtil.getPortletRequestPhase(facesContext) == Bridge.PortletPhase.RESOURCE_PHASE) {
ExternalContext externalContext = facesContext.getExternalContext();
Map<String, String> requestParameterMap = externalContext.getRequestParameterMap();
String jsfBridgeAjax = requestParameterMap.get(Bridge.FACES_AJAX_PARAMETER);
if ("true".equals(jsfBridgeAjax)) {
String clientWindowParam = requestParameterMap.get(ResponseStateManager.CLIENT_WINDOW_URL_PARAM);
if (ClientWindowTestUtil.isClientWindowEnabled(externalContext)) {
String clientWindowId = ClientWindowTestUtil.getClientWindowId(externalContext);
if ((clientWindowParam != null) && (clientWindowParam.length() > 0)) {
if (clientWindowParam.equals(clientWindowId)) {
testBean.setTestResult(true, "encodePartialActionURL returned a URL that correctly caused the bridge to invoke the JSF lifecycle " + "in the RESOURCE_PHASE of the portlet lifecycle and the " + ResponseStateManager.CLIENT_WINDOW_URL_PARAM + " request parameter value=[" + clientWindowParam + "] is equal to ClientWindow.getId().");
} else {
testBean.setTestResult(false, "encodePartialActionURL returned a URL such that the " + ResponseStateManager.CLIENT_WINDOW_URL_PARAM + " request parameter value=[" + clientWindowParam + "] did NOT equal ClientWindow.getId()=[" + clientWindowId + "].");
}
} else {
testBean.setTestResult(false, "encodePartialActionURL returned a URL that contained a null value for the " + ResponseStateManager.CLIENT_WINDOW_URL_PARAM + " request parameter.");
}
} else {
if (clientWindowParam == null) {
testBean.setTestResult(true, "encodePartialActionURL returned a URL that correctly caused the bridge to invoke the JSF lifecycle " + "in the RESOURCE_PHASE of the portlet lifecycle.");
} else {
testBean.setTestResult(false, "encodePartialActionURL returned a URL that incorrectly included the " + ResponseStateManager.CLIENT_WINDOW_URL_PARAM + " request parameter with value=[" + clientWindowParam + "] even though the client window feature is disabled.");
}
}
} else {
testBean.setTestResult(false, "encodePartialActionURL returned a URL that did not contain the " + Bridge.FACES_AJAX_PARAMETER + " request parameter.");
}
testBean.setTestComplete(true);
if (testBean.getTestStatus()) {
return Constants.TEST_SUCCESS;
} else {
return Constants.TEST_FAILED;
}
} else {
return "";
}
}
use of com.liferay.faces.bridge.tck.annotation.BridgeTest in project liferay-faces-bridge-impl by liferay.
the class EncodeResourceURLTests method encodeResourceURLTest.
// Test is SingleRequest -- Render only
// Test #6.31
@BridgeTest(test = "encodeResourceURLTest")
public String encodeResourceURLTest(TestBean testBean) {
testBean.setTestComplete(true);
final String URL_TEST_STRING = "/myportal/resources/myImage.jpg";
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
String testURL = externalContext.encodeResourceURL(URL_TEST_STRING);
String verifyURL = ((PortletResponse) externalContext.getResponse()).encodeURL(URL_TEST_STRING).replace("&", "&");
if (testURL.equals(verifyURL)) {
testBean.setTestResult(true, "encodeResourceURL correctly encoded the resource as an external (App) resource.");
return Constants.TEST_SUCCESS;
} else {
testBean.setTestResult(false, "encodeResourceURL incorrectly encoded a resource as if it were a reference to a resource within this application. Generated: " + testURL + " but expected: " + verifyURL);
return Constants.TEST_FAILED;
}
}
Aggregations