use of javax.portlet.PortalContext in project liferay-faces-bridge-impl by liferay.
the class BridgePortalContextTest method testBridgePortalContext.
@Test
public void testBridgePortalContext() {
// PortalContextBridgeImpl should delegate to the portlet container to determine if the optional
// MARKUP_HEAD_ELEMENT feature is supported.
boolean markupHeadElementSupport = true;
PortalContext portalContextBridgeImpl = new PortalContextBridgeImpl(new PortletRequestMockImpl(markupHeadElementSupport));
Assert.assertEquals("true", portalContextBridgeImpl.getProperty(PortalContext.MARKUP_HEAD_ELEMENT_SUPPORT));
testBridgePortalContextAddToHeadSupport(portalContextBridgeImpl, markupHeadElementSupport);
// PortalContextBridgeImpl should delegate to the portlet container to determine if the optional
// MARKUP_HEAD_ELEMENT feature is supported.
markupHeadElementSupport = false;
portalContextBridgeImpl = new PortalContextBridgeImpl(new PortletRequestMockImpl(markupHeadElementSupport));
Assert.assertNull(portalContextBridgeImpl.getProperty(PortalContext.MARKUP_HEAD_ELEMENT_SUPPORT));
testBridgePortalContextAddToHeadSupport(portalContextBridgeImpl, markupHeadElementSupport);
}
use of javax.portlet.PortalContext in project liferay-faces-bridge-impl by liferay.
the class Tests method requestScopeContentsTest.
// Test is MultiRequest -- Render/Action
// Test #5.1
@BridgeTest(test = "requestScopeContentsTest")
public String requestScopeContentsTest(TestBean testBean) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
UIViewRoot uiViewRoot = facesContext.getViewRoot();
Map<String, Object> requestMap = externalContext.getRequestMap();
// are explicitly excluded -- test for presence/absence in render
if (BridgeUtil.getPortletRequestPhase(facesContext) == Bridge.PortletPhase.ACTION_PHASE) {
// mark the test as compelte -- put in session in case the bridge fails in preserving the request scope
externalContext.getSessionMap().put("com.liferay.faces.bridge.tck.testComplete", Boolean.TRUE);
// Add elements that should be preserved: Messages need to be added after InvokeApplication (i.e. once
// navigation has occurred -- so we attach to the right ViewRoot The lifecycleListener is in the portlet
// that drives this test
requestMap.put("com.liferay.faces.bridge.tck.TestRequestScope_a", REQUEST_ATTR_VALUE);
// Add elements that should be excluded
requestMap.put("com.liferay.faces.bridge.tck.TestRequestScope_b", new AnnotatedExcludedBean());
// Don't need to add additional excludedAttributes tests as they are covered in chapter 6 tests
PortletConfig portletConfig = (PortletConfig) facesContext.getELContext().getELResolver().getValue(facesContext.getELContext(), null, "portletConfig");
if (portletConfig == null) {
throw new IllegalStateException("Unable to acquire the portletConfig!");
}
requestMap.put("com.liferay.faces.bridge.tck.PortletConfig", portletConfig);
requestMap.put("com.liferay.faces.bridge.tck.PortletContext", externalContext.getContext());
requestMap.put("com.liferay.faces.bridge.tck.PortletRequest", externalContext.getRequest());
requestMap.put("com.liferay.faces.bridge.tck.PortletResponse", externalContext.getResponse());
requestMap.put("com.liferay.faces.bridge.tck.PortletSession", externalContext.getSession(true));
PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
PortletPreferences prefs = portletRequest.getPreferences();
requestMap.put("com.liferay.faces.bridge.tck.PortletPreferences", prefs);
PortalContext pc = portletRequest.getPortalContext();
requestMap.put("com.liferay.faces.bridge.tck.PortalContext", pc);
requestMap.put("com.liferay.faces.bridge.tck.FacesContext", facesContext);
requestMap.put("com.liferay.faces.bridge.tck.ExternalContext", externalContext);
// Note: no way to test the servlet objects
requestMap.put("javax.portlet.TestRequestScope", REQUEST_ATTR_VALUE);
requestMap.put("javax.portlet.faces.TestRequestScope", REQUEST_ATTR_VALUE);
requestMap.put("javax.faces.TestRequestScope", REQUEST_ATTR_VALUE);
requestMap.put("javax.servlet.TestRequestScope", REQUEST_ATTR_VALUE);
requestMap.put("javax.servlet.include.TestRequestScope", REQUEST_ATTR_VALUE);
// action Navigation result
return "requestScopeContentsTest";
} else {
if (externalContext.getSessionMap().get("com.liferay.faces.bridge.tck.testComplete") == null) {
return "Test is still in progress ...";
} else {
externalContext.getSessionMap().remove("com.liferay.faces.bridge.tck.testComplete");
testBean.setTestComplete(true);
}
// Now verify that what should have been carried forward has and what shouldn't hasn't.
// Check for the message we aded
boolean found1 = false;
boolean found2 = false;
for (Iterator<FacesMessage> i = facesContext.getMessages(uiViewRoot.getClientId(facesContext)); i.hasNext(); ) {
FacesMessage message = i.next();
if (message.getSummary().equals(MESSAGE_VALUE1) && !found2) {
found1 = true;
} else if (message.getSummary().equals(MESSAGE_VALUE2) && found1) {
found2 = true;
}
}
if (!found1 || !found2) {
testBean.setTestResult(false, "Messages added to UIViewRoot not retained as expected. Either there weren't preserved or they weren't preserved in the correct order.");
return Constants.TEST_FAILED;
}
String s = (String) requestMap.get("com.liferay.faces.bridge.tck.TestRequestScope_a");
if ((s == null) || !s.equals(REQUEST_ATTR_VALUE)) {
testBean.setTestResult(false, "Expected request attribute not retained: com.liferay.faces.bridge.tck.TestRequestScope_a.");
return Constants.TEST_FAILED;
}
// Add elements that should be excluded
Object o = requestMap.get("com.liferay.faces.bridge.tck.TestRequestScope_b");
if (o != null) {
testBean.setTestResult(false, "Attribute annotated (for exclusion) unexpectedly retained: com.liferay.faces.bridge.tck.TestRequestScope_b.");
return Constants.TEST_FAILED;
}
o = requestMap.get("com.liferay.faces.bridge.tck.PortletConfig");
if (o != null) {
testBean.setTestResult(false, "Attribute containing PortletConfig unexpectedly retained: com.liferay.faces.bridge.tck.PortletConfig.");
return Constants.TEST_FAILED;
}
o = requestMap.get("com.liferay.faces.bridge.tck.PortletContext");
if (o != null) {
testBean.setTestResult(false, "Attribute containing PortletContext unexpectedly retained: com.liferay.faces.bridge.tck.PortletContext.");
return Constants.TEST_FAILED;
}
o = requestMap.get("com.liferay.faces.bridge.tck.PortletRequest");
if (o != null) {
testBean.setTestResult(false, "Attribute containing PortletRequest unexpectedly retained: com.liferay.faces.bridge.tck.PortletRequest.");
return Constants.TEST_FAILED;
}
o = requestMap.get("com.liferay.faces.bridge.tck.PortletResponse");
if (o != null) {
testBean.setTestResult(false, "Attribute containing PortletResponse unexpectedly retained: com.liferay.faces.bridge.tck.PortletResponse.");
return Constants.TEST_FAILED;
}
o = requestMap.get("com.liferay.faces.bridge.tck.PortletSession");
if (o != null) {
testBean.setTestResult(false, "Attribute containing PortletSession unexpectedly retained: com.liferay.faces.bridge.tck.PortletSession.");
return Constants.TEST_FAILED;
}
o = requestMap.get("com.liferay.faces.bridge.tck.PortletPreferences");
if (o != null) {
testBean.setTestResult(false, "Attribute containing PortletPreferences unexpectedly retained: com.liferay.faces.bridge.tck.PortletPreferences.");
return Constants.TEST_FAILED;
}
o = requestMap.get("com.liferay.faces.bridge.tck.PortalContext");
if (o != null) {
testBean.setTestResult(false, "Attribute containing PortalContext unexpectedly retained: com.liferay.faces.bridge.tck.PortalContext.");
return Constants.TEST_FAILED;
}
o = requestMap.get("com.liferay.faces.bridge.tck.FacesContext");
if (o != null) {
testBean.setTestResult(false, "Attribute containing FacesContext unexpectedly retained: com.liferay.faces.bridge.tck.FacesContext.");
return Constants.TEST_FAILED;
}
o = requestMap.get("com.liferay.faces.bridge.tck.ExternalContext");
if (o != null) {
testBean.setTestResult(false, "Attribute containing ExternalContext unexpectedly retained: com.liferay.faces.bridge.tck.ExternalContext.");
return Constants.TEST_FAILED;
}
// Note: no way to test the servlet objects
o = requestMap.get("javax.portlet.TestRequestScope");
if (o != null) {
testBean.setTestResult(false, "Attribute in the javax.portlet namesapce unexpectedly retained: javax.portlet.TestRequestScope.");
return Constants.TEST_FAILED;
}
o = requestMap.get("javax.portlet.faces.TestRequestScope");
if (o != null) {
testBean.setTestResult(false, "Attribute in the javax.portlet.faces namesapce unexpectedly retained: javax.portlet.faces.TestRequestScope.");
return Constants.TEST_FAILED;
}
o = requestMap.get("javax.faces.TestRequestScope");
if (o != null) {
testBean.setTestResult(false, "Attribute in the javax.faces namesapce unexpectedly retained: javax.faces.TestRequestScope.");
return Constants.TEST_FAILED;
}
o = requestMap.get("javax.servlet.TestRequestScope");
if (o != null) {
testBean.setTestResult(false, "Attribute in the javax.servlet namesapce unexpectedly retained: javax.servlet.TestRequestScope.");
return Constants.TEST_FAILED;
}
o = requestMap.get("javax.servlet.include.TestRequestScope");
if (o != null) {
testBean.setTestResult(false, "Attribute in the javax.servlet.include namesapce unexpectedly retained: javax.servlet.include.TestRequestScope.");
return Constants.TEST_FAILED;
}
testBean.setTestResult(true, "Correctly retained expected attributes and excluded expected attributes.");
return Constants.TEST_SUCCESS;
}
}
use of javax.portlet.PortalContext in project liferay-faces-bridge-ext by liferay.
the class BridgePortletRequestFactoryLiferayImpl method getResourceRequest.
@Override
public ResourceRequest getResourceRequest(ResourceRequest resourceRequest, ResourceResponse resourceResponse, PortletConfig portletConfig, BridgeConfig bridgeConfig) {
resourceRequest = getWrapped().getResourceRequest(resourceRequest, resourceResponse, portletConfig, bridgeConfig);
PortalContext portalContext = new PortalContextBridgeLiferayImpl(resourceRequest);
return new ResourceRequestBridgeLiferayImpl(resourceRequest, resourceResponse.getNamespace(), portletConfig, portalContext);
}
Aggregations