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());
}
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);
}
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));
}
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));
}
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);
}
Aggregations