Search in sources :

Example 1 with MockHttpServletRequest

use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest in project wcomponents by BorderTech.

the class DevToolkit_Test method testServiceRequest.

@Test
public void testServiceRequest() {
    DevToolkit toolkit = new DevToolkit();
    // Test when disabled
    Config.getInstance().clearProperty(ConfigurationProperties.DEVELOPER_TOOKIT);
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("wc_devToolkit", "x");
    request.setParameter("devToolkit_showTree", "true");
    toolkit.serviceRequest(request);
    Assert.assertFalse("Should have ignored the request when disabled", toolkit.isShowTree());
    // Test when enabled
    Config.getInstance().setProperty(ConfigurationProperties.DEVELOPER_TOOKIT, "true");
    request = new MockHttpServletRequest();
    request.setParameter("wc_devToolkit", "x");
    request.setParameter("devToolkit_showTree", "true");
    toolkit.serviceRequest(request);
    Assert.assertTrue("Should have set show tree", toolkit.isShowTree());
}
Also used : MockHttpServletRequest(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest) Test(org.junit.Test)

Example 2 with MockHttpServletRequest

use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest in project wcomponents by BorderTech.

the class DevToolkit_Test method sendToolkitRequest.

/**
 * Sends a request to the given toolkit.
 *
 * @param toolkit the toolkit
 * @param key the request parameter key
 * @param value the request parameter value
 */
private void sendToolkitRequest(final DevToolkit toolkit, final String key, final String value) {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("wc_devToolkit", "x");
    request.setParameter(key, value);
    toolkit.serviceRequest(request);
}
Also used : MockHttpServletRequest(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest)

Example 3 with MockHttpServletRequest

use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest in project wcomponents by BorderTech.

the class ServletUtilTest method testExtractCookie.

@Test
public void testExtractCookie() {
    String cookieName = "mycookiename";
    String cookieValue = "mycookievalue";
    MockHttpServletRequest httpServletRequest = new MockHttpServletRequest();
    httpServletRequest.setCookie(cookieName, cookieValue);
    Assert.assertEquals("Got cookie value by name", cookieValue, ServletUtil.extractCookie(httpServletRequest, cookieName));
}
Also used : MockHttpServletRequest(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest) Test(org.junit.Test)

Example 4 with MockHttpServletRequest

use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest in project wcomponents by BorderTech.

the class ServletUtilTest method testExtractCookieNoneFound.

@Test
public void testExtractCookieNoneFound() {
    String cookieName = "mycookiename";
    MockHttpServletRequest httpServletRequest = new MockHttpServletRequest();
    Assert.assertNull("Got cookie value by name", ServletUtil.extractCookie(httpServletRequest, cookieName));
}
Also used : MockHttpServletRequest(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest) Test(org.junit.Test)

Example 5 with MockHttpServletRequest

use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest in project wcomponents by BorderTech.

the class WServlet_Test method testServiceWithException.

@Test
public void testServiceWithException() throws ServletException, IOException {
    // A null UI should result in an exception which should be handled internally
    MyWServlet servlet = new MyWServlet(null);
    servlet.init(new MockServletConfig());
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setMethod("GET");
    MockHttpServletResponse response = new MockHttpServletResponse();
    servlet.service(request, response);
    String output = new String(response.getOutput());
    Assert.assertNotNull("An error message should be written when an exception occurs", output);
}
Also used : MockHttpServletRequest(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest) MockServletConfig(com.github.bordertech.wcomponents.util.mock.servlet.MockServletConfig) MockHttpServletResponse(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

MockHttpServletRequest (com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest)36 Test (org.junit.Test)25 MockHttpServletResponse (com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse)13 MockHttpSession (com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession)13 MockServletConfig (com.github.bordertech.wcomponents.util.mock.servlet.MockServletConfig)9 WText (com.github.bordertech.wcomponents.WText)5 PrintWriter (java.io.PrintWriter)5 UIContext (com.github.bordertech.wcomponents.UIContext)4 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)4 MockResponse (com.github.bordertech.wcomponents.util.mock.MockResponse)4 ServletRequest (com.github.bordertech.wcomponents.servlet.ServletRequest)3 NullWriter (com.github.bordertech.wcomponents.util.NullWriter)3 AbstractWComponent (com.github.bordertech.wcomponents.AbstractWComponent)2 WComponent (com.github.bordertech.wcomponents.WComponent)2 InterceptorComponent (com.github.bordertech.wcomponents.container.InterceptorComponent)2 WServlet (com.github.bordertech.wcomponents.servlet.WServlet)2 WServletHelper (com.github.bordertech.wcomponents.servlet.WServlet.WServletHelper)2 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)2 StringWriter (java.io.StringWriter)2 Locale (java.util.Locale)2