use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest in project wcomponents by BorderTech.
the class DevToolkit_Test method testResetSession.
@Test
public void testResetSession() {
MockHttpSession session = new MockHttpSession();
Assert.assertFalse("Session should not be invalidated", session.isInvalidated());
DevToolkit toolkit = new DevToolkit();
MockHttpServletRequest request = new MockHttpServletRequest(session);
request.setParameter("wc_devToolkit", "x");
toolkit.serviceRequest(request);
Assert.assertFalse("Session should not be invalidated", session.isInvalidated());
request = new MockHttpServletRequest(session);
request.setParameter("wc_devToolkit", "x");
request.setParameter("devToolkit_resetSession", "x");
toolkit.serviceRequest(request);
Assert.assertTrue("Session should be invalidated", session.isInvalidated());
}
use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest in project wcomponents by BorderTech.
the class DevToolkit_Test method testPaintHeaderShowRequest.
@Test
public void testPaintHeaderShowRequest() {
DevToolkit toolkit = new DevToolkit();
String header = renderHeader(toolkit);
Assert.assertTrue("Should not contain request info", header.indexOf("request headers") == -1);
sendToolkitRequest(toolkit, "devToolkit_showRequest", "true");
final String paramKey1 = "DevToolkit_Test.testPaintHeaderShowRequest.pkey1";
final String paramKey2 = "DevToolkit_Test.testPaintHeaderShowRequest.pkey2";
final String paramValue1 = "DevToolkit_Test.testPaintHeaderShowRequest.pvalue1";
final String paramValue2 = "DevToolkit_Test.testPaintHeaderShowRequest.pvalue2";
final String headerKey1 = "DevToolkit_Test.testPaintHeaderShowRequest.hkey1";
final String headerKey2 = "DevToolkit_Test.testPaintHeaderShowRequest.hkey2";
final String headerValue1 = "DevToolkit_Test.testPaintHeaderShowRequest.hvalue1";
final String headerValue2 = "DevToolkit_Test.testPaintHeaderShowRequest.hvalue2";
MockHttpServletRequest request = new MockHttpServletRequest();
request.setParameter(paramKey1, paramValue1);
request.setParameter(paramKey2, paramValue2);
request.setHeader(headerKey1, headerValue1);
request.setHeader(headerKey2, headerValue2);
toolkit.serviceRequest(request);
header = renderHeader(toolkit);
Assert.assertTrue("Should contain request info", header.indexOf("request headers") != -1);
Assert.assertTrue("Output should contain parameter key1", header.contains(paramKey1));
Assert.assertTrue("Output should contain parameter key2", header.contains(paramKey2));
Assert.assertTrue("Output should contain parameter value1", header.contains(paramValue1));
Assert.assertTrue("Output should contain parameter value2", header.contains(paramValue2));
Assert.assertTrue("Output should contain header key1", header.contains(headerKey1));
Assert.assertTrue("Output should contain header key2", header.contains(headerKey2));
Assert.assertTrue("Output should contain header value1", header.contains(headerValue1));
Assert.assertTrue("Output should contain header value2", header.contains(headerValue2));
}
use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest in project wcomponents by BorderTech.
the class WebXmlRenderingPerformance_Test method sendRequest.
/**
* Invokes WComponent request processing, so that this test case can more closely match a production scenario.
*
* @param comp the component to invoke request processing on.
* @param uic the user context to use.
*/
private void sendRequest(final WComponent comp, final UIContext uic) {
PrintWriter writer = new PrintWriter(new NullWriter());
uic.setEnvironment(new WServlet.WServletEnvironment("", "http://localhost", ""));
uic.setUI(comp);
InterceptorComponent root = ServletUtil.createInterceptorChain(new MockHttpServletRequest());
root.attachUI(comp);
Response response = new MockResponse();
root.attachResponse(response);
setActiveContext(uic);
MockRequest request = new MockRequest();
try {
root.serviceRequest(request);
root.preparePaint(request);
root.paint(new WebXmlRenderContext(writer));
} finally {
resetContext();
}
}
use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest in project wcomponents by BorderTech.
the class ServletUtilTest method testExtractCookieAmongstMany.
@Test
public void testExtractCookieAmongstMany() {
String cookieName = "mycookiename";
String cookieValue = "mycookievalue";
MockHttpServletRequest httpServletRequest = new MockHttpServletRequest();
for (byte i = 0; i < 10; i++) {
httpServletRequest.setCookie(cookieName + i, cookieValue + 1);
}
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 ThemeServlet_Test method requestFile.
/**
* Requests a file from the servlet.
*
* @param path the path to the file
* @param asParam true to use the ThemeServlet's 'f' parameter or false to place the path in the URL.
* @return the servlet response
* @throws ServletException a servlet exception
* @throws IOException an exception
*/
private MockHttpServletResponse requestFile(final String path, final boolean asParam) throws ServletException, IOException {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
if (asParam) {
request.setRequestURI("/theme");
request.setParameter("f", path);
} else {
request.setRequestURI("/theme/" + path);
request.setPathInfo('/' + path);
}
themeServlet.doGet(request, response);
return response;
}
Aggregations