Search in sources :

Example 31 with BridgeTest

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

the class EncodeResourceURLTests method encodeResourceURLWithWindowStateTest.

// Test is MultiRequest -- Render/Action
// Test #6.136 (b)
@BridgeTest(test = "encodeResourceURLWithWindowStateTest")
public String encodeResourceURLWithWindowStateTest(TestBean testBean) {
    // This tests that we can encode a new mode in an actionURL
    // done by navigation rule.
    FacesContext facesContext = FacesContext.getCurrentInstance();
    if (BridgeUtil.getPortletRequestPhase(facesContext) == Bridge.PortletPhase.RESOURCE_PHASE) {
        PortletRequest portletRequest = (PortletRequest) facesContext.getExternalContext().getRequest();
        // Parameter/Mode encoded in the faces-config.xml target
        WindowState windowState = portletRequest.getWindowState();
        // Check that the parameter came along too
        String paramValue = facesContext.getExternalContext().getRequestParameterMap().get("param1");
        if ((windowState == null) || !windowState.toString().equalsIgnoreCase("normal")) {
            testBean.setTestResult(false, "encodeResourceURL incorrectly encoded the portlet window state.  The resulting request should have ignored the invalid window state and remained in 'normal' mode.");
        } else if (paramValue == null) {
            testBean.setTestResult(false, "encodeResourceURL incorrectly encoded the window state and parameter.  The resulting request didn't contain the expected 'param1' parameter.");
        } else if (!paramValue.equals("testValue")) {
            testBean.setTestResult(false, "encodeResourceURL incorrectly encoded the window state and parameter.  The resulting request contained the wrong parameter value. Expected: testValue  Received: " + paramValue);
        } else {
            testBean.setTestResult(true, "encodeResourceURL correctly encoded a URL by ignoring the window state and properly encoding the parameter.");
        }
        testBean.setTestComplete(true);
        if (testBean.getTestStatus()) {
            return Constants.TEST_SUCCESS;
        } else {
            return Constants.TEST_FAILED;
        }
    } else {
        return "";
    }
}
Also used : WindowState(javax.portlet.WindowState) FacesContext(javax.faces.context.FacesContext) PortletRequest(javax.portlet.PortletRequest) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 32 with BridgeTest

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

the class EncodeResourceURLTests method encodeResourceURLWithModeTest.

// Test is MultiRequest -- Render/Action
// Test #6.136
@BridgeTest(test = "encodeResourceURLWithModeTest")
public String encodeResourceURLWithModeTest(TestBean testBean) {
    // This tests that we can encode a new mode in an actionURL
    // done by navigation rule.
    FacesContext facesContext = FacesContext.getCurrentInstance();
    if (BridgeUtil.getPortletRequestPhase(facesContext) == Bridge.PortletPhase.RESOURCE_PHASE) {
        PortletRequest portletRequest = (PortletRequest) facesContext.getExternalContext().getRequest();
        // Parameter/Mode encoded in the faces-config.xml target
        PortletMode portletMode = portletRequest.getPortletMode();
        // Check that the parameter came along too
        String paramValue = facesContext.getExternalContext().getRequestParameterMap().get("param1");
        if ((portletMode == null) || !portletMode.toString().equalsIgnoreCase("view")) {
            testBean.setTestResult(false, "encodeResourceURL incorrectly encoded the portlet mode.  The resulting request should have ignored the mode and remained in 'view' mode.");
        } else if (paramValue == null) {
            testBean.setTestResult(false, "encodeResourceURL incorrectly encoded the mode and parameter.  The resulting request didn't contain the expected 'param1' parameter.");
        } else if (!paramValue.equals("testValue")) {
            testBean.setTestResult(false, "encodeResourceURL incorrectly encoded the mode and parameter.  The resulting request contained the wrong parameter value. Expected: testValue  Received: " + paramValue);
        } else {
            testBean.setTestResult(true, "encodeResourceURL correctly encoded a URL by ignoring the mode and properly encoding the parameter.");
        }
        testBean.setTestComplete(true);
        if (testBean.getTestStatus()) {
            return Constants.TEST_SUCCESS;
        } else {
            return Constants.TEST_FAILED;
        }
    } else {
        return "";
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) PortletRequest(javax.portlet.PortletRequest) PortletMode(javax.portlet.PortletMode) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 33 with BridgeTest

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

the class EncodeResourceURLTests method encodeResourceURLRelativeURLBackLinkTest.

// Test is SingleRequest -- Render only
// Test #6.30
@BridgeTest(test = "encodeResourceURLRelativeURLBackLinkTest")
public String encodeResourceURLRelativeURLBackLinkTest(TestBean testBean) {
    testBean.setTestComplete(true);
    final String RELATIVEURL_BACKLINK_TEST_STRING = "../resources/myImage.jpg?javax.portlet.faces.BackLink=myBackLinkParam";
    final String RELATIVEURL_BACKLINK_VERIFY_STRING = "/resources/myImage.jpg?myBackLinkParam=";
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    // compute what the backLink should be
    String actionURL = externalContext.encodeActionURL(facesContext.getApplication().getViewHandler().getActionURL(facesContext, facesContext.getViewRoot().getViewId()));
    String verifyString = null;
    try {
        verifyString = externalContext.getRequestContextPath() + RELATIVEURL_BACKLINK_VERIFY_STRING + HTTPUtils.encode(actionURL, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        testBean.setTestResult(false, "Failed because couldn't UTF-8 encode backLink parameter.");
        return Constants.TEST_FAILED;
    }
    // So ensure compares match by stripping from the one generated by the portlet container (if it exists)
    if (externalContext.encodeResourceURL(RELATIVEURL_BACKLINK_TEST_STRING).equals(((PortletResponse) externalContext.getResponse()).encodeURL(verifyString).replace("&", "&"))) {
        testBean.setTestResult(true, "encodeResourceURL correctly encoded a relative URL with a backLink.");
        return Constants.TEST_SUCCESS;
    } else {
        testBean.setTestResult(false, "encodeResourceURL didn't correctly encoded a relative URL with a backLink.  Expected: " + verifyString + " but encodeResourceURL returned: " + externalContext.encodeResourceURL(RELATIVEURL_BACKLINK_TEST_STRING));
        return Constants.TEST_FAILED;
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) ExternalContext(javax.faces.context.ExternalContext) PortletResponse(javax.portlet.PortletResponse) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 34 with BridgeTest

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

the class EncodeResourceURLTests method encodeResourceURLViewLinkTest.

// Test is SingleRequest -- Render only
// Test #6.33
@BridgeTest(test = "encodeResourceURLViewLinkTest")
public String encodeResourceURLViewLinkTest(TestBean testBean) {
    testBean.setTestComplete(true);
    // assume web.xml does Faces suffix mapping of .jsf to .jsp
    final String URL_VIEWLINK_TEST_STRING = "/tests/viewLink.jsf?javax.portlet.faces.ViewLink=true&param1=testValue";
    final String URL_VIEWLINK_VERIFY_STRING = "/tests/viewLink.jsf?param1=testValue";
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
    String testString = viewHandler.getResourceURL(facesContext, URL_VIEWLINK_TEST_STRING);
    String verifyString = viewHandler.getResourceURL(facesContext, URL_VIEWLINK_VERIFY_STRING);
    if (externalContext.encodeResourceURL(testString).equals(externalContext.encodeActionURL(verifyString))) {
        testBean.setTestResult(true, "encodeResourceURL correctly encoded a viewLink.");
        return Constants.TEST_SUCCESS;
    } else {
        testBean.setTestResult(false, "encodeResourceURL incorrectly encoded a viewLink.  Expected: " + externalContext.encodeActionURL(verifyString) + " but encodeResourceURL with the viewLink returned: " + externalContext.encodeResourceURL(testString));
        return Constants.TEST_FAILED;
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) ExternalContext(javax.faces.context.ExternalContext) ViewHandler(javax.faces.application.ViewHandler) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 35 with BridgeTest

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

the class Tests method portletInitializationParametersTest.

@BridgeTest(test = "portletInitializationParametersTest")
public String portletInitializationParametersTest(TestBean testBean) {
    // Section 4.1
    // Tests whether the GenericFacesPortlet portlet initialization
    // parameters have been correctly set as Bridge attributes.
    String PARAM_NAMESPACE = "javax.portlet.faces.chapter4_1Tests-portletInitializationParametersTest-portlet.";
    Map<String, Object> expectedInitParams = new HashMap<String, Object>();
    Map<String, String> viewIds = new HashMap<String, String>();
    viewIds.put("view", "/tests/singleRequestTest.xhtml");
    viewIds.put("edit", "/tests/singleRequestTest.xhtml");
    viewIds.put("help", "/tests/singleRequestTest.xhtml");
    expectedInitParams.put("defaultViewIdMap", viewIds);
    expectedInitParams.put("excludedRequestAttributes", "exclude1,exclude2");
    expectedInitParams.put("preserveActionParams", Boolean.TRUE);
    expectedInitParams.put("bridgeEventHandler", "com.liferay.faces.bridge.tck.tests.chapter_5.section_5_2.Ch5TestEventHandler");
    expectedInitParams.put("bridgePublicRenderParameterHandler", "com.liferay.faces.bridge.tck.tests.chapter_5.section_5_3.Tests");
    expectedInitParams.put("defaultRenderKitId", "HTML_BASIC");
    ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
    StringBuilder notFoundMsg = new StringBuilder();
    boolean pass = checkAttrs(externalContext.getApplicationMap(), PARAM_NAMESPACE, expectedInitParams, notFoundMsg);
    if (notFoundMsg.length() != 0) {
        notFoundMsg.append(".  ");
    }
    StringBuilder msg = new StringBuilder();
    if (pass) {
        msg.append("GenericFacesPortlet properly sets appropriate portlet init parameters as the spec defined corresponding portlet context attributes.");
    } else {
        msg.append("GenericFacesPortlet didn't properly set the appropriate portlet init parameters as the spec defined corresponding portlet context attributes. Missing or incorrect portlet context attributes: " + notFoundMsg);
    }
    testBean.setTestResult(pass, msg.toString());
    if (pass) {
        return Constants.TEST_SUCCESS;
    } else {
        return Constants.TEST_FAILED;
    }
}
Also used : HashMap(java.util.HashMap) 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