use of com.github.bordertech.wcomponents.util.mock.servlet.MockServletConfig in project wcomponents by BorderTech.
the class WServlet_Test method testSubSessionsDisabledNoSSID.
@Test
public void testSubSessionsDisabledNoSSID() throws ServletException, IOException {
Config.getInstance().setProperty(ConfigurationProperties.SERVLET_ENABLE_SUBSESSIONS, "false");
MyWServlet servlet = new MyWServlet(new WText("test"));
servlet.init(new MockServletConfig());
MockHttpSession session = new MockHttpSession();
servlet.service(new MockHttpServletRequest(session), new MockHttpServletResponse());
Assert.assertEquals("Incorrect invocation count", 1, servlet.lastInvocationCount);
servlet.service(new MockHttpServletRequest(session), new MockHttpServletResponse());
Assert.assertEquals("Incorrect invocation count", 2, servlet.lastInvocationCount);
}
use of com.github.bordertech.wcomponents.util.mock.servlet.MockServletConfig in project wcomponents by BorderTech.
the class WServlet_Test method testSubSessionsEnabled.
@Test
public void testSubSessionsEnabled() throws ServletException, IOException {
Config.getInstance().setProperty(ConfigurationProperties.SERVLET_ENABLE_SUBSESSIONS, "true");
MyWServlet servlet = new MyWServlet(new WText("test"));
servlet.init(new MockServletConfig());
MockHttpSession session = new MockHttpSession();
// Initial request will be missing a SSID, will create a new subsession (id = 0)
MockHttpServletRequest request = new MockHttpServletRequest(session);
servlet.service(request, new MockHttpServletResponse());
Assert.assertEquals("Incorrect invocation count", 1, servlet.lastInvocationCount);
// Passing in an invalid SSID should return same subsession (id = 0)
request = new MockHttpServletRequest(session);
request.setParameter("ssid", "asdf");
servlet.service(request, new MockHttpServletResponse());
Assert.assertEquals("Incorrect invocation count", 2, servlet.lastInvocationCount);
// Missing SSID should create a new subession (id = 1)
request = new MockHttpServletRequest(session);
servlet.service(request, new MockHttpServletResponse());
Assert.assertEquals("Incorrect invocation count", 1, servlet.lastInvocationCount);
// Should update the primary session (id = 0)
request = new MockHttpServletRequest(session);
request.setParameter("ssid", "0");
servlet.service(request, new MockHttpServletResponse());
Assert.assertEquals("Incorrect invocation count", 3, servlet.lastInvocationCount);
// Should update the secondary session (id = 1)
request = new MockHttpServletRequest(session);
request.setParameter("ssid", "1");
servlet.service(request, new MockHttpServletResponse());
Assert.assertEquals("Incorrect invocation count", 2, servlet.lastInvocationCount);
}
use of com.github.bordertech.wcomponents.util.mock.servlet.MockServletConfig 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);
}
use of com.github.bordertech.wcomponents.util.mock.servlet.MockServletConfig 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.MockServletConfig in project wcomponents by BorderTech.
the class WServlet_Test method testSubSessionsDisabled.
@Test
public void testSubSessionsDisabled() throws ServletException, IOException {
Config.getInstance().setProperty(ConfigurationProperties.SERVLET_ENABLE_SUBSESSIONS, "false");
MyWServlet servlet = new MyWServlet(new WText("test"));
servlet.init(new MockServletConfig());
MockHttpSession session = new MockHttpSession();
MockHttpServletRequest request = new MockHttpServletRequest(session);
request.setParameter("ssid", "1");
servlet.service(request, new MockHttpServletResponse());
Assert.assertEquals("Incorrect invocation count", 1, servlet.lastInvocationCount);
request = new MockHttpServletRequest(session);
request.setParameter("ssid", "2");
servlet.service(request, new MockHttpServletResponse());
Assert.assertEquals("Incorrect invocation count", 2, servlet.lastInvocationCount);
request = new MockHttpServletRequest(session);
request.setParameter("ssid", "1");
servlet.service(request, new MockHttpServletResponse());
Assert.assertEquals("Incorrect invocation count", 3, servlet.lastInvocationCount);
}
Aggregations