use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse in project wcomponents by BorderTech.
the class ServletResponse_Test method testGetWriter.
@Test
public void testGetWriter() throws IOException {
MockHttpServletResponse backing = new MockHttpServletResponse();
ServletResponse response = new ServletResponse(backing);
Assert.assertSame("Incorrect writer", backing.getWriter(), response.getWriter());
}
use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse in project wcomponents by BorderTech.
the class ServletResponse_Test method testSendError.
@Test
public void testSendError() throws IOException {
// something relatively obscure
int errorCode = 505;
MockHttpServletResponse backing = new MockHttpServletResponse();
ServletResponse response = new ServletResponse(backing);
response.sendError(errorCode, "dummy");
Assert.assertEquals("Incorrect error", errorCode, backing.getStatus());
}
use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse in project wcomponents by BorderTech.
the class WServletPerformance_Test method sendWServletRequest.
/**
* Invokes WComponent servlet processing.
*
* @param servlet the servlet to invoke request processing on.
* @param session the current session.
* @param step the step count
* @param token the session token
* @throws Exception an exception
*/
private void sendWServletRequest(final WServlet servlet, final HttpSession session, final int step, final String token) throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest(session);
MockHttpServletResponse response = new MockHttpServletResponse();
if (step > 0) {
request.setMethod("POST");
request.setRequestURI("http://localhost/app");
// These are hard-coded to avoid overhead during performance testing
request.setParameter(Environment.STEP_VARIABLE, String.valueOf(step));
request.setParameter(Environment.SESSION_TOKEN_VARIABLE, token);
request.setParameter("_0b", "p1_" + step);
request.setParameter("_0d", "p2_" + step);
request.setParameter("_0e", "x");
} else {
request.setMethod("GET");
request.setRequestURI("http://localhost/app");
}
servlet.service(request, response);
}
use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse in project wcomponents by BorderTech.
the class WServletPerformance_Test method timeWServlet.
/**
* Times the WServlet execution looping the given number of times and returns the elapsed time.
*
* @param count the number of times to loop.
* @return the elapsed time, in nanoseconds.
* @throws Exception an exception
*/
private long timeWServlet(final int count) throws Exception {
final SimpleWServlet servlet = new SimpleWServlet();
servlet.init(new MockServletConfig());
final MockHttpSession simpleWServletSession = new MockHttpSession();
// Do first request to get session token
sendWServletRequest(servlet, simpleWServletSession, 0, null);
// Get token
WServletHelper helper = new WServletHelper(servlet, new MockHttpServletRequest(simpleWServletSession), new MockHttpServletResponse());
String token = helper.getUIContext().getEnvironment().getSessionToken();
// JIT warm-up
for (int i = 1; i < count; i++) {
sendWServletRequest(servlet, simpleWServletSession, i, token);
}
simpleWServletSession.getAttributes().clear();
// Do first request to get session token
sendWServletRequest(servlet, simpleWServletSession, 0, null);
final String token2 = helper.getUIContext().getEnvironment().getSessionToken();
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
for (int i = 1; i < count; i++) {
sendWServletRequest(servlet, simpleWServletSession, i, token2);
}
} catch (Exception e) {
LOG.error("Failed to execute test", e);
}
}
};
return time(runnable);
}
use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse in project wcomponents by BorderTech.
the class WComponentsPerformance_Test method sendSimpleRequest.
/**
* Invokes simple request processing.
*
* @param session the http session
* @param step the step count
*/
private void sendSimpleRequest(final HttpSession session, final int step) {
MockHttpServletRequest request = new MockHttpServletRequest(session);
request.setParameter("formBean.property1", "p1_" + step);
request.setParameter("formBean.property2", "p2_" + step);
request.setParameter("submit", "Submit");
doSimpleRequest(request, new MockHttpServletResponse());
}
Aggregations