use of com.liferay.faces.bridge.tck.annotation.BridgeTest in project liferay-faces-bridge-impl by liferay.
the class Tests method getRequestParameterPreserveParamsTest.
// Test is MultiRequest -- Test whether actionParameters are preserved into
// the Render if the config value is set.
// Test #6.46
@BridgeTest(test = "getRequestParameterPreserveParamsTest")
public String getRequestParameterPreserveParamsTest(TestBean testBean) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
// Now verify we have the form params that were passed to the action
Map<String, String> paramMap = externalContext.getRequestParameterMap();
if (BridgeUtil.getPortletRequestPhase(facesContext) == Bridge.PortletPhase.ACTION_PHASE) {
return "getRequestParameterPreserveParamsTest";
} else {
testBean.setTestComplete(true);
// loop through the Map and verify that 'value1' and 'value2' aren't there.
boolean foundField1 = false;
boolean foundField2 = false;
Set<Map.Entry<String, String>> set = paramMap.entrySet();
for (Iterator<Map.Entry<String, String>> params = set.iterator(); params.hasNext(); ) {
Map.Entry<String, String> e = params.next();
String key = e.getKey();
// Can't look up by key because JSF munges this id
if (key.indexOf("formDataField1") > -1)
foundField1 = true;
if (key.indexOf("formDataField2") > -1)
foundField2 = true;
}
if (!foundField1) {
testBean.setTestResult(false, "Failed Header Phase: externalContext.getRequestParameterMap() didn't properly preserve the value for the 'field1' form parameter.");
return Constants.TEST_FAILED;
} else if (!foundField2) {
testBean.setTestResult(false, "Failed Header Phase: externalContext.getRequestParameterMap() didn't properly preserve the value for the 'field2' form parameter.");
return Constants.TEST_FAILED;
} else {
testBean.setTestResult(true, "Passed Header Phase: The getRequestParameterMap Map correctly preserved the submitted form fields into the Header Phase.");
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 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 com.liferay.faces.bridge.tck.annotation.BridgeTest in project liferay-faces-bridge-impl by liferay.
the class InitParameterTests method getInitParameterMapTest.
/**
* getInitParameterMap Tests
*/
// Test #6.72
@BridgeTest(test = "getInitParameterMapTest")
public String getInitParameterMapTest(TestBean testBean) {
testBean.setTestComplete(true);
// Verify that the init parameters are the union of init-params from portlet.xml and context-params from
// web.xml.
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
PortletContext portletContext = (PortletContext) externalContext.getContext();
Map<String, String> externalContextInitParamMap = externalContext.getInitParameterMap();
ELContext elContext = facesContext.getELContext();
ELResolver elResolver = elContext.getELResolver();
PortletConfig portletConfig = (PortletConfig) elResolver.getValue(elContext, null, "portletConfig");
Enumeration<String> portletConfigInitParameterNames = portletConfig.getInitParameterNames();
List<String> initParamList = Collections.list(portletConfigInitParameterNames);
Enumeration<String> portletContextInitParameterNames = portletContext.getInitParameterNames();
while (portletContextInitParameterNames.hasMoreElements()) {
String portletContextInitParameterName = portletContextInitParameterNames.nextElement();
if (!initParamList.contains(portletContextInitParameterName)) {
initParamList.add(portletContextInitParameterName);
}
}
Enumeration<String> combinedInitParamNames = Collections.enumeration(initParamList);
if (!containsIdenticalInitParamEntries(externalContextInitParamMap, combinedInitParamNames, portletConfig)) {
testBean.setTestResult(false, "Failed: Portlet context initParams and the externalContext initParameterMap entries aren't identical.");
return Constants.TEST_FAILED;
}
// Verify that the init parameter map is immutable.
try {
externalContextInitParamMap.put("Test0Key", "Test0Value");
testBean.setTestResult(false, "Failed: ExternalContext's initParameterMap isn't immutable -- a put() suceeded.");
return Constants.TEST_FAILED;
} catch (Exception e) {
// Expected condition
}
// Verify that the param tckParam1 has the same value found in web.xml.
String tckParam1Value = externalContextInitParamMap.get("tckParam1");
if (!"web-xml-tck-param1-value".equals(tckParam1Value)) {
testBean.setTestResult(false, "Failed: ExternalContext's initParameterMap contained an incorrect value for tckParam1=[" + tckParam1Value + "].");
return Constants.TEST_FAILED;
}
// Verify that the param tckParam2 has the same value as the overridden one in portlet.xml.
String tckParam2Value = externalContextInitParamMap.get("tckParam2");
if (!"portlet-xml-tck-param2-value".equals(tckParam2Value)) {
testBean.setTestResult(false, "Failed: ExternalContext's initParameterMap contained an incorrect value for tckParam2=[" + tckParam2Value + "].");
return Constants.TEST_FAILED;
}
testBean.setTestResult(true, "The Map returned from initParameterMap is immutable.");
testBean.appendTestDetail("The initParameterMap Map correctly expresses attributes in the underlying context.");
testBean.appendTestDetail("The value of tckParam1 is the same as the context-param value in web.xml.");
testBean.appendTestDetail("The value of tckParam2 is the same as the overridden init-param value in portlet.xml.");
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 getResourceTest.
// Test #6.78
@BridgeTest(test = "getResourceTest")
public String getResourceTest(TestBean testBean) {
testBean.setTestComplete(true);
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
PortletContext pCtx = (PortletContext) externalContext.getContext();
try {
URL externalContextURL = externalContext.getResource("/images/liferay-logo.png");
URL pCtxURL = pCtx.getResource("/images/liferay-logo.png");
if ((externalContextURL == null) || (pCtxURL == null) || !pCtxURL.equals(externalContextURL)) {
testBean.setTestResult(false, "Failed: externalContext.getResource failed: URL returned from call through externalContext isn't the same as the one returned by the portletContext.");
return Constants.TEST_FAILED;
}
// Otherwise all out tests passed:
testBean.setTestResult(true, "URL returned from call through externalContext is the same as the one returned by the portletContext.");
return Constants.TEST_SUCCESS;
} catch (MalformedURLException e) {
testBean.setTestResult(false, "Failed: Unexpected MalformedURLException thrown when called getResource().");
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 getContextTest.
// Test #6.70
@BridgeTest(test = "getContextTest")
public String getContextTest(TestBean testBean) {
testBean.setTestComplete(true);
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
Object portletContext = externalContext.getContext();
if ((portletContext != null) && (portletContext instanceof PortletContext)) {
testBean.setTestResult(true, "externalContext.getContext() correctly returned an object of type PortletContext.");
} else {
testBean.setTestResult(false, "externalContext.getContext() didn't return an object of type PortletContext.");
}
if (testBean.getTestStatus()) {
return Constants.TEST_SUCCESS;
} else {
return Constants.TEST_FAILED;
}
}
Aggregations