Search in sources :

Example 6 with MockHttpSession

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());
}
Also used : MockHttpSession(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession) WServletPerformance_Test(com.github.bordertech.wcomponents.servlet.WServletPerformance_Test) Test(org.junit.Test)

Example 7 with MockHttpSession

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);
}
Also used : HttpSession(javax.servlet.http.HttpSession) MockHttpSession(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession) MockHttpSession(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession)

Example 8 with MockHttpSession

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());
}
Also used : MockHttpServletRequest(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest) MockHttpSession(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession) Test(org.junit.Test)

Example 9 with MockHttpSession

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));
}
Also used : MockHttpSession(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession) Test(org.junit.Test)

Example 10 with MockHttpSession

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);
}
Also used : WText(com.github.bordertech.wcomponents.WText) MockHttpServletRequest(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest) MockServletConfig(com.github.bordertech.wcomponents.util.mock.servlet.MockServletConfig) MockHttpSession(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession) MockHttpServletResponse(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

MockHttpSession (com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession)18 Test (org.junit.Test)15 MockHttpServletRequest (com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest)13 MockServletConfig (com.github.bordertech.wcomponents.util.mock.servlet.MockServletConfig)9 MockHttpServletResponse (com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse)6 WText (com.github.bordertech.wcomponents.WText)5 UIContext (com.github.bordertech.wcomponents.UIContext)3 WServletHelper (com.github.bordertech.wcomponents.servlet.WServlet.WServletHelper)2 ServletException (javax.servlet.ServletException)2 HttpSession (javax.servlet.http.HttpSession)2 MockContainer (com.github.bordertech.wcomponents.MockContainer)1 UIContextImpl (com.github.bordertech.wcomponents.UIContextImpl)1 ServletRequest (com.github.bordertech.wcomponents.servlet.ServletRequest)1 WServletPerformance_Test (com.github.bordertech.wcomponents.servlet.WServletPerformance_Test)1 NullWriter (com.github.bordertech.wcomponents.util.NullWriter)1 PrintWriter (java.io.PrintWriter)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1