Search in sources :

Example 11 with PortalContext

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);
}
Also used : PortalContext(javax.portlet.PortalContext) PortalContextBridgeImpl(com.liferay.faces.bridge.context.internal.PortalContextBridgeImpl) Test(org.junit.Test)

Example 12 with PortalContext

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;
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) AnnotatedExcludedBean(com.liferay.faces.bridge.tck.beans.AnnotatedExcludedBean) PortletRequest(javax.portlet.PortletRequest) ExternalContext(javax.faces.context.ExternalContext) PortalContext(javax.portlet.PortalContext) PortletConfig(javax.portlet.PortletConfig) PortletPreferences(javax.portlet.PortletPreferences) UIViewRoot(javax.faces.component.UIViewRoot) FacesMessage(javax.faces.application.FacesMessage) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 13 with PortalContext

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);
}
Also used : PortalContext(javax.portlet.PortalContext) PortalContextBridgeLiferayImpl(com.liferay.faces.bridge.ext.context.internal.PortalContextBridgeLiferayImpl)

Aggregations

PortalContext (javax.portlet.PortalContext)13 PortalContextBridgeLiferayImpl (com.liferay.faces.bridge.ext.context.internal.PortalContextBridgeLiferayImpl)5 BridgePortalContext (com.liferay.faces.bridge.context.BridgePortalContext)4 ExternalContext (javax.faces.context.ExternalContext)4 PortletRequest (javax.portlet.PortletRequest)4 UIViewRoot (javax.faces.component.UIViewRoot)3 PortalContextBridgeImpl (com.liferay.faces.bridge.context.internal.PortalContextBridgeImpl)2 Product (com.liferay.faces.util.product.Product)2 ArrayList (java.util.ArrayList)2 FacesContext (javax.faces.context.FacesContext)2 ResponseWriter (javax.faces.context.ResponseWriter)2 PortletContext (javax.portlet.PortletContext)2 Test (org.junit.Test)2 BridgeURI (com.liferay.faces.bridge.internal.BridgeURI)1 BridgeTest (com.liferay.faces.bridge.tck.annotation.BridgeTest)1 AnnotatedExcludedBean (com.liferay.faces.bridge.tck.beans.AnnotatedExcludedBean)1 FacesRequestParameterMap (com.liferay.faces.util.context.map.FacesRequestParameterMap)1 MultiPartFormData (com.liferay.faces.util.context.map.MultiPartFormData)1 ProductFactory (com.liferay.faces.util.product.ProductFactory)1 FacesURLEncoder (com.liferay.faces.util.render.FacesURLEncoder)1