use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession in project wcomponents by BorderTech.
the class WComponentsPerformance_Test method testOtherImplementationCorrectness.
/**
* Basic sanity-test to ensure that the basic implementation is performing all the processing that it should.
*
* @throws java.lang.Exception an exception
*/
@Test
public void testOtherImplementationCorrectness() throws Exception {
MockHttpSession session = new MockHttpSession();
sendSimpleRequest(session, 0);
sendSimpleRequest(session, 1);
SimpleFormBean bean = (SimpleFormBean) session.getAttribute("formBean");
Assert.assertEquals("Incorrect property1 value", "p1_1", bean.getProperty1());
Assert.assertEquals("Incorrect property2 value", "p2_1", bean.getProperty2());
}
use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession in project wcomponents by BorderTech.
the class WComponentsPerformance_Test method timeOtherServlet.
/**
* Times the other servlet 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 timeOtherServlet(final int count) throws Exception {
final HttpSession session = new MockHttpSession();
// JIT warm-up
for (int i = 0; i < count; i++) {
sendSimpleRequest(session, i);
}
final HttpSession session2 = new MockHttpSession();
Runnable runnable = new Runnable() {
@Override
public void run() {
for (int i = 0; i < count; i++) {
sendSimpleRequest(session2, i);
}
}
};
return time(runnable);
}
use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession 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.MockHttpSession in project wcomponents by BorderTech.
the class LdeSessionUtil_Test method testSessionSerialization.
/**
* Test for serializeSessionAttributes / deserializeSessionAttributes.
*/
@Test
public void testSessionSerialization() {
MockHttpSession session1 = new MockHttpSession();
MockHttpSession session2 = new MockHttpSession();
session1.setAttribute(STRING_KEY, STRING_VALUE);
session1.setAttribute(INT_KEY, INT_VALUE);
session1.setAttribute(NON_SERIALIZABLE_KEY, NON_SERIALIZABLE_VALUE);
LdeSessionUtil.serializeSessionAttributes(session1);
LdeSessionUtil.deserializeSessionAttributes(session2);
Assert.assertEquals("Incorrect number of deserialized session attribute", 2, session2.getAttributes().size());
Assert.assertEquals("Incorrect value of String attribute", STRING_VALUE, session2.getAttribute(STRING_KEY));
Assert.assertEquals("Incorrect value of Integer attribute", INT_VALUE, session2.getAttribute(INT_KEY));
Assert.assertFalse("Session should not contain", session2.getAttributes().containsKey(NON_SERIALIZABLE_KEY));
}
use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession 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