Search in sources :

Example 81 with BridgeTest

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

the class Tests method getMimeTypeTest.

// Test 6.139
@BridgeTest(test = "getMimeTypeTest")
public String getMimeTypeTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    PortletContext portletContext = (PortletContext) externalContext.getContext();
    String mimeType = portletContext.getMimeType("index.html");
    if (mimeType.equals("text/html") && mimeType.equals(externalContext.getMimeType("index.html"))) {
        testBean.setTestResult(true, "ExternalContext.getMimeType() returned the correct value");
        return Constants.TEST_SUCCESS;
    }
    testBean.setTestResult(false, "ExternalContext.getMimeType() returned an incorrect value");
    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)

Example 82 with BridgeTest

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

the class Tests method addResponseCookieTest.

// Test 6.138
@BridgeTest(test = "addResponseCookieTest")
public String addResponseCookieTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    Bridge.PortletPhase portletRequestPhase = BridgeUtil.getPortletRequestPhase(facesContext);
    ExternalContext externalContext = facesContext.getExternalContext();
    if (portletRequestPhase == Bridge.PortletPhase.ACTION_PHASE) {
        Map<String, Object> properties = new HashMap<>();
        properties.put("comment", "tckComment");
        properties.put("httpOnly", true);
        properties.put("maxAge", new Integer(1234));
        properties.put("secure", Boolean.FALSE);
        properties.put("path", "tckPath");
        externalContext.addResponseCookie("tckCookie", "tck1234", properties);
        return "requestRenderRedisplayTest";
    } else if (portletRequestPhase == Bridge.PortletPhase.HEADER_PHASE) {
        // If redisplay hasn't been invoked yet -- merely return
        if (externalContext.getRequestParameterMap().get("org.apache.portlet.faces.tck.redisplay") == null) {
            return "requestRenderRedisplayTest";
        }
        Map<String, Object> requestCookieMap = externalContext.getRequestCookieMap();
        Object tckCookie = requestCookieMap.get("tckCookie");
        if ((tckCookie != null) && (tckCookie instanceof Cookie)) {
            Cookie cookie = (Cookie) tckCookie;
            if ("tckCookie".equals(cookie.getName()) && "tck1234".equals(cookie.getValue())) {
                testBean.setTestResult(true, "externalContext.addResponseCookie() set the expected cookie");
            } else {
                testBean.setTestResult(false, "externalContext.addResponseCookie() did not set the expected cookie value");
            }
        } else {
            testBean.setTestResult(false, "externalContext.addResponseCookie() did not set the expected cookie");
        }
        testBean.setTestComplete(true);
        if (testBean.getTestStatus()) {
            return Constants.TEST_SUCCESS;
        } else {
            return Constants.TEST_FAILED;
        }
    }
    return "";
}
Also used : Cookie(javax.servlet.http.Cookie) FacesContext(javax.faces.context.FacesContext) HashMap(java.util.HashMap) ExternalContext(javax.faces.context.ExternalContext) HashMap(java.util.HashMap) Map(java.util.Map) Bridge(javax.portlet.faces.Bridge) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 83 with BridgeTest

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

the class Tests method getRequestSchemeTest.

// Test 6.140
@BridgeTest(test = "getRequestSchemeTest")
public String getRequestSchemeTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
    String scheme = portletRequest.getScheme();
    if (scheme.equals("http") && scheme.equals(externalContext.getRequestScheme())) {
        testBean.setTestResult(true, "ExternalContext.getRequestScheme() returned the correct value");
        return Constants.TEST_SUCCESS;
    }
    testBean.setTestResult(false, "ExternalContext.getRequestScheme() returned an incorrect value");
    return Constants.TEST_FAILED;
}
Also used : FacesContext(javax.faces.context.FacesContext) PortletRequest(javax.portlet.PortletRequest) ExternalContext(javax.faces.context.ExternalContext) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 84 with BridgeTest

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

the class Tests method getRequestServerPortTest.

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

Example 85 with BridgeTest

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

the class Tests method setResponseStatusTest.

// Test 6.151
@BridgeTest(test = "setResponseStatusTest")
public String setResponseStatusTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    if (BridgeUtil.getPortletRequestPhase(facesContext) == Bridge.PortletPhase.RESOURCE_PHASE) {
        int[] statusCodes = new int[] { HttpServletResponse.SC_ACCEPTED, HttpServletResponse.SC_BAD_GATEWAY, HttpServletResponse.SC_BAD_REQUEST, HttpServletResponse.SC_CONFLICT, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, HttpServletResponse.SC_CONTINUE, HttpServletResponse.SC_CREATED, HttpServletResponse.SC_EXPECTATION_FAILED, HttpServletResponse.SC_FORBIDDEN, HttpServletResponse.SC_FOUND, HttpServletResponse.SC_GATEWAY_TIMEOUT, HttpServletResponse.SC_GONE, HttpServletResponse.SC_HTTP_VERSION_NOT_SUPPORTED, HttpServletResponse.SC_LENGTH_REQUIRED, HttpServletResponse.SC_METHOD_NOT_ALLOWED, HttpServletResponse.SC_MOVED_PERMANENTLY, HttpServletResponse.SC_MOVED_TEMPORARILY, HttpServletResponse.SC_MULTIPLE_CHOICES, HttpServletResponse.SC_NO_CONTENT, HttpServletResponse.SC_NO_CONTENT, HttpServletResponse.SC_NON_AUTHORITATIVE_INFORMATION, HttpServletResponse.SC_NOT_ACCEPTABLE, HttpServletResponse.SC_NOT_FOUND, HttpServletResponse.SC_NOT_IMPLEMENTED, HttpServletResponse.SC_NOT_MODIFIED, HttpServletResponse.SC_OK, HttpServletResponse.SC_PARTIAL_CONTENT, HttpServletResponse.SC_PAYMENT_REQUIRED, HttpServletResponse.SC_PRECONDITION_FAILED, HttpServletResponse.SC_PROXY_AUTHENTICATION_REQUIRED, HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE, HttpServletResponse.SC_REQUEST_TIMEOUT, HttpServletResponse.SC_REQUEST_URI_TOO_LONG, HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE, HttpServletResponse.SC_RESET_CONTENT, HttpServletResponse.SC_SEE_OTHER, HttpServletResponse.SC_SERVICE_UNAVAILABLE, HttpServletResponse.SC_SWITCHING_PROTOCOLS, HttpServletResponse.SC_TEMPORARY_REDIRECT, HttpServletResponse.SC_UNAUTHORIZED, HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, HttpServletResponse.SC_USE_PROXY };
        ExternalContext externalContext = facesContext.getExternalContext();
        ResourceResponse resourceResponse = (ResourceResponse) externalContext.getResponse();
        int originalStatus = resourceResponse.getStatus();
        boolean pass = true;
        for (int statusCode : statusCodes) {
            externalContext.setResponseStatus(statusCode);
            if (resourceResponse.getStatus() != statusCode) {
                pass = false;
                testBean.setTestResult(false, "externalContext.setResponseStatus(int) did not set the underlying status on the ResourceResponse");
            }
        }
        if (pass) {
            testBean.setTestResult(true, "externalContext.setResponseStatus(int) correctly set the underlying status on the ResourceResponse");
        }
        externalContext.setResponseStatus(originalStatus);
        testBean.setTestComplete(true);
        if (testBean.getTestStatus()) {
            return Constants.TEST_SUCCESS;
        } else {
            return Constants.TEST_FAILED;
        }
    }
    return "";
}
Also used : FacesContext(javax.faces.context.FacesContext) ResourceResponse(javax.portlet.ResourceResponse) ExternalContext(javax.faces.context.ExternalContext) 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