Search in sources :

Example 66 with BridgeTest

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;
        }
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) ExternalContext(javax.faces.context.ExternalContext) Map(java.util.Map) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 67 with BridgeTest

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 "";
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) StateAwareResponse(javax.portlet.StateAwareResponse) ExternalContext(javax.faces.context.ExternalContext) QName(javax.xml.namespace.QName) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 68 with BridgeTest

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;
}
Also used : FacesContext(javax.faces.context.FacesContext) ELContext(javax.el.ELContext) ELResolver(javax.el.ELResolver) ExternalContext(javax.faces.context.ExternalContext) PortletConfig(javax.portlet.PortletConfig) PortletContext(javax.portlet.PortletContext) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 69 with BridgeTest

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;
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) MalformedURLException(java.net.MalformedURLException) ExternalContext(javax.faces.context.ExternalContext) PortletContext(javax.portlet.PortletContext) URL(java.net.URL) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 70 with BridgeTest

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;
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) ExternalContext(javax.faces.context.ExternalContext) PortletContext(javax.portlet.PortletContext) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Aggregations

BridgeTest (com.liferay.faces.bridge.tck.annotation.BridgeTest)204 FacesContext (javax.faces.context.FacesContext)201 ExternalContext (javax.faces.context.ExternalContext)166 PortletRequest (javax.portlet.PortletRequest)40 StateAwareResponse (javax.portlet.StateAwareResponse)26 QName (javax.xml.namespace.QName)26 Bridge (javax.portlet.faces.Bridge)19 Map (java.util.Map)17 PortletContext (javax.portlet.PortletContext)10 MimeResponse (javax.portlet.MimeResponse)9 RenderRequest (javax.portlet.RenderRequest)9 Enumeration (java.util.Enumeration)8 Locale (java.util.Locale)8 PortletMode (javax.portlet.PortletMode)7 WindowState (javax.portlet.WindowState)7 ELResolver (javax.el.ELResolver)6 IOException (java.io.IOException)5 ELContext (javax.el.ELContext)5 ViewHandler (javax.faces.application.ViewHandler)5 UIViewRoot (javax.faces.component.UIViewRoot)5