Search in sources :

Example 86 with BridgeTest

use of com.liferay.faces.bridge.tck.annotation.BridgeTest in project liferay-faces-bridge-impl by liferay.

the class Tests method getSessionMaxInactiveIntervalTest.

// Test 6.157
@BridgeTest(test = "getSessionMaxInactiveIntervalTest")
public String getSessionMaxInactiveIntervalTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    PortletSession portletSession = (PortletSession) externalContext.getSession(true);
    if (portletSession.getMaxInactiveInterval() == externalContext.getSessionMaxInactiveInterval()) {
        testBean.setTestResult(true, "ExternalContext.getSessionMaxInactiveInterval() returned the correct value");
        return Constants.TEST_SUCCESS;
    }
    testBean.setTestResult(false, "ExternalContext.getSessionMaxInactiveInterval() returned an incorrect value");
    return Constants.TEST_FAILED;
}
Also used : FacesContext(javax.faces.context.FacesContext) PortletSession(javax.portlet.PortletSession) ExternalContext(javax.faces.context.ExternalContext) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 87 with BridgeTest

use of com.liferay.faces.bridge.tck.annotation.BridgeTest in project liferay-faces-bridge-impl by liferay.

the class Tests method isSecureTest.

// Test 6.159
@BridgeTest(test = "isSecureTest")
public String isSecureTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    if (externalContext.isSecure()) {
        testBean.setTestResult(true, "ExternalContext.isSecure() returned the correct value");
        return Constants.TEST_SUCCESS;
    }
    testBean.setTestResult(false, "ExternalContext.isSecure() returned an incorrect value");
    return Constants.TEST_FAILED;
}
Also used : FacesContext(javax.faces.context.FacesContext) ExternalContext(javax.faces.context.ExternalContext) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 88 with BridgeTest

use of com.liferay.faces.bridge.tck.annotation.BridgeTest in project liferay-faces-bridge-impl by liferay.

the class Tests method getApplicationContextPathTest.

// Test 6.160
@BridgeTest(test = "getApplicationContextPathTest")
public String getApplicationContextPathTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    Map<String, Object> applicationMap = externalContext.getApplicationMap();
    String tckInitApplicationContextPath = (String) applicationMap.get("tckInitApplicationContextPath");
    if (externalContext.getApplicationContextPath().equals(tckInitApplicationContextPath)) {
        testBean.setTestResult(true, "ExternalContext.getApplicationContextPath() returned the correct value");
        return Constants.TEST_SUCCESS;
    }
    testBean.setTestResult(false, "ExternalContext.getApplicationContextPath() returned an incorrect value");
    return Constants.TEST_FAILED;
}
Also used : FacesContext(javax.faces.context.FacesContext) ExternalContext(javax.faces.context.ExternalContext) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 89 with BridgeTest

use of com.liferay.faces.bridge.tck.annotation.BridgeTest in project liferay-faces-bridge-impl by liferay.

the class Tests method clientWindowTest.

// Test 6.162
@BridgeTest(test = "clientWindowTest")
public String clientWindowTest(TestBean testBean) {
    testBean.setTestComplete(true);
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    ClientWindow origClientWindow = externalContext.getClientWindow();
    ClientWindow clientWindow = new ClientWindowTCKImpl(origClientWindow);
    externalContext.setClientWindow(clientWindow);
    if (clientWindow.equals(externalContext.getClientWindow())) {
        testBean.setTestResult(true, "externalContext.getClientWindow() correctly returned the same value that was passed to ExternalContext.setClientWindow(ClientWindow).");
    } else {
        testBean.setTestResult(false, "externalContext.getClientWindow() incorrectly returned a different value than was passed to ExternalContext.setClientWindow(ClientWindow).");
    }
    externalContext.setClientWindow(origClientWindow);
    if (testBean.getTestStatus()) {
        return Constants.TEST_SUCCESS;
    } else {
        return Constants.TEST_FAILED;
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) ExternalContext(javax.faces.context.ExternalContext) ClientWindow(javax.faces.lifecycle.ClientWindow) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 90 with BridgeTest

use of com.liferay.faces.bridge.tck.annotation.BridgeTest in project liferay-faces-bridge-impl by liferay.

the class Tests method JSF_ELTest.

/**
 * Testing JSF EL - implicits are in alpha order.
 *
 * @param   testBean  the bean for testing
 *
 * @return
 */
@BridgeTest(test = "JSF_ELTest")
public String JSF_ELTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    Object request = externalContext.getRequest();
    Map<String, Object> requestMap = externalContext.getRequestMap();
    Object response = externalContext.getResponse();
    ELContext elContext = facesContext.getELContext();
    ELResolver facesResolver = elContext.getELResolver();
    // Test that each implicit object is accessible and has the right value in
    // both the action phase and header phase
    PortletConfig portletConfig = (PortletConfig) requestMap.get(PortletConfig.class.getName());
    if (BridgeUtil.getPortletRequestPhase(facesContext) == Bridge.PortletPhase.ACTION_PHASE) {
        // ActionRequest
        try {
            // First ensure there are entries in the various scopes
            ensureScopeEntries(externalContext);
            // JSF IMPLICIT OBJECTS:
            // application -> ExternalContext.getContext();
            testImplicitObject(testBean, facesResolver, facesContext, "application", externalContext.getContext());
            // applicationScope -> externalContext.getApplicationMap()
            testImplicitObject(testBean, facesResolver, facesContext, "applicationScope", externalContext.getApplicationMap());
            // cookie -> externalContext.getRequestCookieMap()
            testImplicitObject(testBean, facesResolver, facesContext, "cookie", externalContext.getRequestCookieMap());
            // facesContext -> the FacesContext for this request
            testImplicitObject(testBean, facesResolver, facesContext, "facesContext", facesContext);
            // header -> externalContext.getRequestHeaderMap()
            testImplicitObject(testBean, facesResolver, facesContext, "header", externalContext.getRequestHeaderMap());
            // headerValues -> externalContext.getRequestHeaderValuesMap()
            testImplicitObject(testBean, facesResolver, facesContext, "headerValues", externalContext.getRequestHeaderValuesMap());
            // initParam -> externalContext.getInitParameterMap()
            testImplicitObject(testBean, facesResolver, facesContext, "initParam", externalContext.getInitParameterMap());
            // param -> externalContext.getRequestParameterMap()
            testImplicitObject(testBean, facesResolver, facesContext, "param", externalContext.getRequestParameterMap());
            // paramValues -> externalContext.getRequestParameterValuesMap()
            testImplicitObject(testBean, facesResolver, facesContext, "paramValues", externalContext.getRequestParameterValuesMap());
            // request -> externalContext.getRequest()
            testImplicitObject(testBean, facesResolver, facesContext, "request", request);
            // requestScope -> externalContext.getRequestScope()
            testImplicitObject(testBean, facesResolver, facesContext, "requestScope", requestMap);
            // session -> externalContext.getSession()
            testImplicitObject(testBean, facesResolver, facesContext, "session", externalContext.getSession(true));
            // sessionScope -> externalContext.getSessionMap()
            testImplicitObject(testBean, facesResolver, facesContext, "sessionScope", externalContext.getSessionMap());
            // view -> facesContext.getViewRoot()
            testImplicitObject(testBean, facesResolver, facesContext, "view", facesContext.getViewRoot());
            // PORTLET IMPLICIT OBJECTS:
            // actionRequest -> externalContext.getRequest()
            Object elActionRequest = testImplicitObject(testBean, facesResolver, facesContext, "actionRequest", request);
            testDecoratedActionRequest(testBean, elActionRequest);
            // actionResponse -> externalContext.getResponse()
            Object elActionResponse = testImplicitObject(testBean, facesResolver, facesContext, "actionResponse", response);
            testDecoratedActionResponse(testBean, elActionResponse);
            // httpSessionScope:  mutable Map containing PortletSession attribute/values at APPLICATION_SCOPE.
            testHttpSessionScope(testBean, facesResolver, facesContext, "httpSessionScope", (PortletSession) externalContext.getSession(true));
            // mutablePortletPreferencesValues: mutable Map of type Map<String,
            // javax.portlet.faces.preference.Preference>.
            testMutablePortletPreferencesValues(testBean, facesResolver, facesContext, "mutablePortletPreferencesValues", ((PortletRequest) request).getPreferences().getMap());
            // portletConfig -> object of type javax.portlet.PortletConfig
            testImplicitObject(testBean, facesResolver, facesContext, "portletConfig", portletConfig);
            testDecoratedPortletConfig(testBean, portletConfig);
            // portletPreferences -> ExternalContext.getRequest().getPreferences() object.
            Object elPortletPreferences = testImplicitObject(testBean, facesResolver, facesContext, "portletPreferences", ((PortletRequest) request).getPreferences());
            testDecoratedPortletPreferences(testBean, elPortletPreferences);
            // portletPreferencesValues -> ExternalContext.getRequest()).getPreferences().getMap().
            testPortletPreferencesValues(testBean, facesResolver, facesContext, ((PortletRequest) request));
            // portletSession -> ExternalContext.getSession()
            Object elPortletSession = testImplicitObject(testBean, facesResolver, facesContext, "portletSession", externalContext.getSession(true));
            testDecoratedPortletSession(testBean, elPortletSession);
            // portletSessionScope -> ExternalContext.getSessionMap().
            testImplicitObject(testBean, facesResolver, facesContext, "portletSessionScope", externalContext.getSessionMap());
        } catch (Throwable t) {
            testBean.setTestResult(false, "JSF EL failure in action request: " + t.getCause().toString());
        }
        return "JSF_ELTest";
    } else // HeaderRequest / RenderRequest
    {
        try {
            // JSF IMPLICIT OBJECTS:
            // application -> ExternalContext.getContext();
            testImplicitObject(testBean, facesResolver, facesContext, "application", externalContext.getContext());
            // applicationScope -> externalContext.getApplicationMap()
            testImplicitObject(testBean, facesResolver, facesContext, "applicationScope", externalContext.getApplicationMap());
            // cookie -> externalContext.getRequestCookieMap()
            testImplicitObject(testBean, facesResolver, facesContext, "cookie", externalContext.getRequestCookieMap());
            // facesContext -> the FacesContext for this request
            testImplicitObject(testBean, facesResolver, facesContext, "facesContext", facesContext);
            // header -> externalContext.getRequestHeaderMap()
            testImplicitObject(testBean, facesResolver, facesContext, "header", externalContext.getRequestHeaderMap());
            // headerValues -> externalContext.getRequestHeaderValuesMap()
            testImplicitObject(testBean, facesResolver, facesContext, "headerValues", externalContext.getRequestHeaderValuesMap());
            // initParam -> externalContext.getInitParameterMap()
            testImplicitObject(testBean, facesResolver, facesContext, "initParam", externalContext.getInitParameterMap());
            // param -> externalContext.getRequestParameterMap()
            testImplicitObject(testBean, facesResolver, facesContext, "param", externalContext.getRequestParameterMap());
            // paramValues -> externalContext.getRequestParameterValuesMap()
            testImplicitObject(testBean, facesResolver, facesContext, "paramValues", externalContext.getRequestParameterValuesMap());
            // request -> externalContext.getRequest()
            testImplicitObject(testBean, facesResolver, facesContext, "request", request);
            testDecoratedHeaderRequest(testBean, request);
            // requestScope -> externalContext.getRequestScope()
            testImplicitObject(testBean, facesResolver, facesContext, "requestScope", requestMap);
            // session -> externalContext.getSession()
            testImplicitObject(testBean, facesResolver, facesContext, "session", externalContext.getSession(true));
            // sessionScope -> externalContext.getSessionMap()
            testImplicitObject(testBean, facesResolver, facesContext, "sessionScope", externalContext.getSessionMap());
            // view -> facesContext.getViewRoot()
            testImplicitObject(testBean, facesResolver, facesContext, "view", facesContext.getViewRoot());
            // PORTLET IMPLICIT OBJECTS:
            // httpSessionScope:  mutable Map containing PortletSession attribute/values at APPLICATION_SCOPE.
            testHttpSessionScope(testBean, facesResolver, facesContext, "httpSessionScope", (PortletSession) externalContext.getSession(true));
            // mutablePortletPreferencesValues: mutable Map of type Map<String,
            // javax.portlet.faces.preference.Preference>.
            testMutablePortletPreferencesValues(testBean, facesResolver, facesContext, "mutablePortletPreferencesValues", ((PortletRequest) request).getPreferences().getMap());
            // portletConfig -> object of type javax.portlet.PortletConfig
            testImplicitObject(testBean, facesResolver, facesContext, "portletConfig", portletConfig);
            testDecoratedPortletConfig(testBean, portletConfig);
            // portletPreferences -> ExternalContext.getRequest().getPreferences() object.
            testImplicitObject(testBean, facesResolver, facesContext, "portletPreferences", ((PortletRequest) request).getPreferences());
            // portletPreferencesValues -> ExternalContext.getRequest()).getPreferences().getMap().
            testPortletPreferencesValues(testBean, facesResolver, facesContext, (PortletRequest) request);
            // portletSession -> ExternalContext.getSession()
            testImplicitObject(testBean, facesResolver, facesContext, "portletSession", externalContext.getSession(true));
            // portletSessionScope -> ExternalContext.getSessionMap().
            testImplicitObject(testBean, facesResolver, facesContext, "portletSessionScope", externalContext.getSessionMap());
            // renderRequest -> object of type javax.portlet.RenderRequest
            Object elRenderRequest = testImplicitObject(testBean, facesResolver, facesContext, "renderRequest", request);
            testDecoratedRenderRequest(testBean, elRenderRequest);
            // renderResponse -> object of type javax.portlet.RenderResponse
            Object elRenderResponse = testImplicitObject(testBean, facesResolver, facesContext, "renderResponse", externalContext.getResponse());
            testDecoratedRenderResponse(testBean, elRenderResponse);
            // headerRequest -> object of type javax.portlet.HeaderRequest
            testImplicitObject(testBean, facesResolver, facesContext, "headerRequest", request);
            // headerResponse -> object of type javax.portlet.HeaderResponse
            Object elHeaderResponse = testImplicitObject(testBean, facesResolver, facesContext, "headerResponse", response);
            testDecoratedHeaderResponse(testBean, elHeaderResponse);
        } catch (Throwable t) {
            fail(testBean, "JSF EL failure in render request: " + t.getCause().toString());
        }
        // Get the Bridge Implementation's configured resolver so that the entire chain isn't consulted for this
        // part of the test. Isolating the Bridge Impl's resolver removes issues that can occur with other resolvers
        // and prevents false positives or negatives (due to other resolvers fulfilling the spec requirements).
        ELResolver bridgeImplELResolver = getBridgeImplELResolver(externalContext);
        elContext = new ELContextTestImpl(elContext, bridgeImplELResolver);
        // Test ELResolver.getType()
        try {
            bridgeImplELResolver.getType(elContext, null, null);
            fail(testBean, "PropertyNotFoundException not thrown when calling getType(elContext, null, null). ");
        } catch (PropertyNotFoundException e) {
        // Passed.
        }
        Map<String, Class<?>> expectedElResolverFeatureDescriptorTypes = getExpectedElResolverFeatureDescriptorTypes(externalContext);
        Set<Map.Entry<String, Class<?>>> entrySet = expectedElResolverFeatureDescriptorTypes.entrySet();
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("getType() did not return null and/or elContext.setPropertyResolved(true) wasn't called for the following values: ");
        boolean first = true;
        for (Map.Entry<String, Class<?>> entry : entrySet) {
            String name = entry.getKey();
            if ((bridgeImplELResolver.getType(elContext, null, name) != null) || !elContext.isPropertyResolved()) {
                if (!first) {
                    stringBuilder.append(", ");
                }
                stringBuilder.append(name);
                first = false;
            }
        }
        if (!first) {
            stringBuilder.append(". ");
            fail(testBean, stringBuilder.toString());
        }
        // Test ELResolver.setValue()
        try {
            bridgeImplELResolver.setValue(elContext, null, null, "facesContext");
            fail(testBean, "PropertyNotFoundException not thrown when calling setValue(elContext, null, null, value). ");
        } catch (PropertyNotFoundException e) {
        // Passed.
        }
        Set<String> keySet = expectedElResolverFeatureDescriptorTypes.keySet();
        stringBuilder.setLength(0);
        stringBuilder.append("setValue(elContext, null, name, value) did not throw PropertyNotWritableException when name was set to the following values: ");
        first = true;
        for (String name : keySet) {
            if ((name.endsWith("Request") || name.endsWith("Response")) && !(name.startsWith("render") || name.startsWith("header"))) {
                // Cannot test EL keywords for different portlet phases.
                continue;
            }
            Object originalValue = bridgeImplELResolver.getValue(elContext, null, name);
            try {
                bridgeImplELResolver.setValue(elContext, null, name, name);
                // Reset the original value so other parts of the test don't fail.
                bridgeImplELResolver.setValue(elContext, null, name, originalValue);
                if (!first) {
                    stringBuilder.append(", ");
                }
                stringBuilder.append(name);
                first = false;
            } catch (PropertyNotWritableException e) {
            // Passed.
            }
        }
        if (!first) {
            stringBuilder.append(". ");
            fail(testBean, stringBuilder.toString());
        }
        // Test ELResolver.isReadOnly()
        elContext.isPropertyResolved();
        if (!bridgeImplELResolver.isReadOnly(elContext, "facesContext", null) || elContext.isPropertyResolved()) {
            fail(testBean, "isReadOnly() did not return true and/or ELContext.setPropertyResolved(true) was called when base was non-null. ");
        }
        try {
            bridgeImplELResolver.isReadOnly(elContext, null, null);
            fail(testBean, "PropertyNotFoundException not thrown when calling isReadOnly(elContext, null, null). ");
        } catch (PropertyNotFoundException e) {
        // Passed.
        }
        stringBuilder.setLength(0);
        stringBuilder.append("isReadOnly(elContext, null, name) did not return true and/or call elContext.setPropertyResolved() when name was set to the following values: ");
        first = true;
        for (String name : keySet) {
            if (!bridgeImplELResolver.isReadOnly(elContext, null, name) || !elContext.isPropertyResolved()) {
                if (!first) {
                    stringBuilder.append(", ");
                }
                stringBuilder.append(name);
                first = false;
            }
        }
        if (!first) {
            stringBuilder.append(". ");
            fail(testBean, stringBuilder.toString());
        }
        if (bridgeImplELResolver.getFeatureDescriptors(elContext, "facesContext") != null) {
            fail(testBean, "ELResolver.getFeatureDescriptors() did not return null when passed a non-null value for base. ");
        }
        Iterator<FeatureDescriptor> iterator = bridgeImplELResolver.getFeatureDescriptors(elContext, null);
        Map<String, FeatureDescriptor> featureDescriptors = new HashMap<String, FeatureDescriptor>();
        while (iterator.hasNext()) {
            FeatureDescriptor featureDescriptor = iterator.next();
            featureDescriptors.put(featureDescriptor.getName(), featureDescriptor);
        }
        featureDescriptors = Collections.unmodifiableMap(featureDescriptors);
        stringBuilder.setLength(0);
        stringBuilder.append("The following EL key words had invalid feature descriptors:<br />");
        first = true;
        for (Map.Entry<String, Class<?>> entry : entrySet) {
            String name = entry.getKey();
            FeatureDescriptor featureDescriptor = featureDescriptors.get(name);
            if (!isFeatureDescriptorValid(name, featureDescriptor, entry.getValue())) {
                if (!first) {
                    stringBuilder.append(",<br />");
                }
                stringBuilder.append(name);
                stringBuilder.append(" (expected ELResolver.TYPE \"");
                stringBuilder.append(expectedElResolverFeatureDescriptorTypes.get(name));
                stringBuilder.append("\")");
                first = false;
            }
        }
        if (!first) {
            stringBuilder.append(".<br />ELResolver.RESOLVABLE_AT_DESIGN_TIME must be Boolean.TRUE. getName() and getDisplayName() must return the same value. getShortDescription() must not be null. isExpert() and isHidden() must return false. isPreferred() must return true. ");
            fail(testBean, stringBuilder.toString());
        }
        // Test ELResolver.getCommonPropertyType()
        if (bridgeImplELResolver.getCommonPropertyType(elContext, "facesContext") != null) {
            fail(testBean, "ELResolver.getCommonPropertyType() did not return null when base was non-null. ");
        }
        if (!String.class.equals(bridgeImplELResolver.getCommonPropertyType(elContext, null))) {
            fail(testBean, "ELResolver.getCommonPropertyType() did not return String.class when base was null. ");
        }
        if (!testBean.isTestComplete()) {
            // Things completed successfully
            testBean.setTestComplete(true);
            testBean.setTestResult(true, "JSF EL impicit objects correctly resolved in both action and header/render phases.");
            return Constants.TEST_SUCCESS;
        } else {
            return Constants.TEST_FAILED;
        }
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) PropertyNotFoundException(javax.el.PropertyNotFoundException) HashMap(java.util.HashMap) ELResolver(javax.el.ELResolver) ExternalContext(javax.faces.context.ExternalContext) PropertyNotWritableException(javax.el.PropertyNotWritableException) ELContext(javax.el.ELContext) PortletRequest(javax.portlet.PortletRequest) FeatureDescriptor(java.beans.FeatureDescriptor) PortletConfig(javax.portlet.PortletConfig) Map(java.util.Map) HashMap(java.util.HashMap) 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