use of com.liferay.faces.bridge.tck.annotation.BridgeTest in project liferay-faces-bridge-impl by liferay.
the class Tests method getRequestLocalesTest.
// Test #6.77
@BridgeTest(test = "getRequestLocalesTest")
public String getRequestLocalesTest(TestBean testBean) {
testBean.setTestComplete(true);
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
RenderRequest request = (RenderRequest) externalContext.getRequest();
Iterator<Locale> locales = externalContext.getRequestLocales();
Enumeration<Locale> requestLocales = request.getLocales();
while (requestLocales.hasMoreElements() && locales.hasNext()) {
Locale requestLocale = requestLocales.nextElement();
Locale locale = locales.next();
if (!locale.equals(requestLocale)) {
testBean.setTestResult(false, "Failed: Portlet request locales and the externalContext getRequestLocales entries aren't identical.");
return Constants.TEST_FAILED;
}
}
if (requestLocales.hasMoreElements() || locales.hasNext()) {
testBean.setTestResult(false, "Failed: Size of Portlet request locales enumeration and the externalContext getRequestLocales Iterator aren't identical.");
return Constants.TEST_FAILED;
}
// Otherwise all out tests passed:
testBean.setTestResult(true, "The Iterator returned from externalContext.getRequestLocales contains identical entries as the request.getLocales.");
return Constants.TEST_SUCCESS;
}
use of com.liferay.faces.bridge.tck.annotation.BridgeTest in project liferay-faces-bridge-impl by liferay.
the class Tests method getResourceAsStreamTest.
// Test #6.79
@BridgeTest(test = "getResourceAsStreamTest")
public String getResourceAsStreamTest(TestBean testBean) {
testBean.setTestComplete(true);
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
PortletContext pCtx = (PortletContext) externalContext.getContext();
InputStream externalContextStream = externalContext.getResourceAsStream("/images/liferay-logo.png");
InputStream pCtxStream = pCtx.getResourceAsStream("/images/liferay-logo.png");
if ((externalContextStream == null) || (pCtxStream == null)) {
testBean.setTestResult(false, "Failed: externalContext.getResourceAsStream failed: returned InputStream is unexpectedly null.");
return Constants.TEST_FAILED;
}
// compare the bytes in each stream
byte[] stream1 = new byte[1024];
byte[] stream2 = new byte[1024];
boolean done = false;
boolean success = true;
try {
while (!done) {
try {
int c1 = externalContextStream.read(stream1);
int c2 = pCtxStream.read(stream2);
if (c1 < 1024)
done = true;
if ((c1 != c2) || !Arrays.equals(stream1, stream2)) {
success = false;
done = true;
}
} catch (IOException e) {
testBean.setTestResult(false, "Failed: Unexpected IOException thrown when reading stream: " + e.getMessage());
return Constants.TEST_FAILED;
} catch (Throwable t) {
testBean.setTestResult(false, "Failed: Unexpected Throwable thrown when reading stream: " + t.getMessage());
return Constants.TEST_FAILED;
}
}
} finally {
try {
externalContextStream.close();
pCtxStream.close();
} catch (IOException e) {
// ignore
}
}
if (success) {
testBean.setTestResult(true, "Stream returned from call through externalContext is the same as the one returned by the portletContext.");
return Constants.TEST_SUCCESS;
} else {
testBean.setTestResult(false, "Stream returned from call through externalContext is different than the one returned by the portletContext.");
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 getResourcePathsTest.
// Test #6.80
@BridgeTest(test = "getResourcePathsTest")
public String getResourcePathsTest(TestBean testBean) {
testBean.setTestComplete(true);
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
PortletContext pCtx = (PortletContext) externalContext.getContext();
Set<String> externalContextSet = externalContext.getResourcePaths("/tests/");
Set<String> pCtxSet = pCtx.getResourcePaths("/tests/");
if ((pCtxSet == null) || (externalContextSet == null)) {
testBean.setTestResult(false, "Failed: externalContext.getResourcePaths failed: returned path Set is unexpectedly null.");
return Constants.TEST_FAILED;
} else if (pCtxSet.equals(externalContextSet)) {
testBean.setTestResult(true, "Path set returned from call through externalContext is the same as the one returned by the portletContext.");
return Constants.TEST_SUCCESS;
} else {
testBean.setTestResult(false, "Path set returned from call through externalContext is different than the one returned by the portletContext.");
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 getSessionMapTest.
// Test #6.83
@BridgeTest(test = "getSessionMapTest")
public String getSessionMapTest(TestBean testBean) {
testBean.setTestComplete(true);
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
// Test the following:
// 1. Map is immutable
// 2. Map contains the same entries as in the underlying session
Map<String, Object> sessionMap = externalContext.getSessionMap();
PortletSession portletSession = ((PortletRequest) externalContext.getRequest()).getPortletSession();
Enumeration<String> requestSessionAttrNames = portletSession.getAttributeNames();
// Test for mutability
try {
sessionMap.put("TestKey", "TestValue");
} catch (Exception e) {
testBean.setTestResult(false, "The Map returned from getSessionMap is immutable.");
return "getSessionMapTest";
}
if (containsIdenticalSessionEntries(sessionMap, requestSessionAttrNames, portletSession)) {
testBean.setTestResult(true, "externalContext.getSessionMap() correctly contains same attributes as the underlying portlet session.");
return Constants.TEST_SUCCESS;
} else {
testBean.setTestResult(false, "externalContext.getSessionMap() incorrectly contains different attributes than the underlying portlet session.");
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 getSessionTest.
// Test #6.82
@BridgeTest(test = "getSessionTest")
public String getSessionTest(TestBean testBean) {
testBean.setTestComplete(true);
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
if (portletRequest.getPortletSession(true).equals(externalContext.getSession(true))) {
testBean.setTestResult(true, "externalContext.getSession() correctly returned the same session object as the underlying portletRequest.");
return Constants.TEST_SUCCESS;
} else {
testBean.setTestResult(false, "externalContext.getSession() incorrectly returned a different session object than the underlying portletRequest.");
return Constants.TEST_FAILED;
}
}
Aggregations