Search in sources :

Example 1 with AnnotatedExcludedBean

use of com.liferay.faces.bridge.tck.beans.AnnotatedExcludedBean in project liferay-faces-bridge-impl by liferay.

the class Tests method excludedAttributesTest.

// Test is MultiRequest -- Render/Action
// Test #5.10
@BridgeTest(test = "excludedAttributesTest")
public String excludedAttributesTest(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) {
        // 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.IncludedAttr", REQUEST_ATTR_VALUE);
        requestMap.put("com.liferay.faces.bridge.tck.WildcardFacesConfigTest.include.IncludedAttr", REQUEST_ATTR_VALUE);
        requestMap.put("com.liferay.faces.bridge.tck.WildcardPortletXmlTest.include.IncludedAttr", REQUEST_ATTR_VALUE);
        // Add elements that should be excluded
        requestMap.put("com.liferay.faces.bridge.tck.ExcludeByAnnotation", new AnnotatedExcludedBean());
        requestMap.put("com.liferay.faces.bridge.tck.ExcludeByFacesConfigRef", REQUEST_ATTR_VALUE);
        requestMap.put("com.liferay.faces.bridge.tck.WildcardFacesConfigTest.ExcludeByFacesConfigRef", REQUEST_ATTR_VALUE);
        requestMap.put("com.liferay.faces.bridge.tck.ExcludeByPortletXmlRef", REQUEST_ATTR_VALUE);
        requestMap.put("com.liferay.faces.bridge.tck.WildcardPortletXmlTest.ExcludeByPortletXmlRef", REQUEST_ATTR_VALUE);
        // action Navigation result
        return "excludedAttributesTest";
    } else {
        testBean.setTestComplete(true);
        // Now verify that what should have been carried forward has and what shouldn't hasn't.
        String s = (String) requestMap.get("com.liferay.faces.bridge.tck.IncludedAttr");
        if ((s == null) || !s.equals(REQUEST_ATTR_VALUE)) {
            testBean.setTestResult(false, "Expected request attribute not retained: com.liferay.faces.bridge.tck.IncludedAttr.");
            return Constants.TEST_FAILED;
        }
        s = (String) requestMap.get("com.liferay.faces.bridge.tck.WildcardFacesConfigTest.include.IncludedAttr");
        if ((s == null) || !s.equals(REQUEST_ATTR_VALUE)) {
            testBean.setTestResult(false, "Expected request attribute not retained: com.liferay.faces.bridge.tck.WildcardFacesConfigTest.include.IncludedAttr.");
            return Constants.TEST_FAILED;
        }
        s = (String) requestMap.get("com.liferay.faces.bridge.tck.WildcardPortletXmlTest.include.IncludedAttr");
        if ((s == null) || !s.equals(REQUEST_ATTR_VALUE)) {
            testBean.setTestResult(false, "Expected request attribute not retained: com.liferay.faces.bridge.tck.WildcardPortletXmlTest.include.IncludedAttr.");
            return Constants.TEST_FAILED;
        }
        // Check elements that should be excluded
        Object o = requestMap.get("com.liferay.faces.bridge.tck.ExcludeByAnnotation");
        if (o != null) {
            testBean.setTestResult(false, "Attribute annotated (for exclusion) unexpectedly retained: com.liferay.faces.bridge.tck.ExcludeByAnnotation.");
            return Constants.TEST_FAILED;
        }
        o = requestMap.get("com.liferay.faces.bridge.tck.ExcludeByFacesConfigRef");
        if (o != null) {
            testBean.setTestResult(false, "Attribute annotated (for exclusion) unexpectedly retained: com.liferay.faces.bridge.tck.ExcludeByFacesConfigRef.");
            return Constants.TEST_FAILED;
        }
        o = requestMap.get("com.liferay.faces.bridge.tck.WildcardFacesConfigTest.ExcludeByFacesConfigRef");
        if (o != null) {
            testBean.setTestResult(false, "Attribute annotated (for exclusion) unexpectedly retained: com.liferay.faces.bridge.tck.WildcardFacesConfigTest.ExcludeByFacesConfigRef.");
            return Constants.TEST_FAILED;
        }
        o = requestMap.get("com.liferay.faces.bridge.tck.ExcludeByPortletXmlRef");
        if (o != null) {
            testBean.setTestResult(false, "Attribute annotated (for exclusion) unexpectedly retained: com.liferay.faces.bridge.tck.ExcludeByPortletXmlRef.");
            return Constants.TEST_FAILED;
        }
        o = requestMap.get("com.liferay.faces.bridge.tck.WildcardPortletXmlTest.ExcludeByPortletXmlRef");
        if (o != null) {
            testBean.setTestResult(false, "Attribute annotated (for exclusion) unexpectedly retained: com.liferay.faces.bridge.tck.WildcardPortletXmlTest.ExcludeByPortletXmlRef.");
            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) ExternalContext(javax.faces.context.ExternalContext) AnnotatedExcludedBean(com.liferay.faces.bridge.tck.beans.AnnotatedExcludedBean) UIViewRoot(javax.faces.component.UIViewRoot) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 2 with AnnotatedExcludedBean

use of com.liferay.faces.bridge.tck.beans.AnnotatedExcludedBean 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)

Aggregations

BridgeTest (com.liferay.faces.bridge.tck.annotation.BridgeTest)2 AnnotatedExcludedBean (com.liferay.faces.bridge.tck.beans.AnnotatedExcludedBean)2 UIViewRoot (javax.faces.component.UIViewRoot)2 ExternalContext (javax.faces.context.ExternalContext)2 FacesContext (javax.faces.context.FacesContext)2 FacesMessage (javax.faces.application.FacesMessage)1 PortalContext (javax.portlet.PortalContext)1 PortletConfig (javax.portlet.PortletConfig)1 PortletPreferences (javax.portlet.PortletPreferences)1 PortletRequest (javax.portlet.PortletRequest)1