Search in sources :

Example 16 with MockHttpSession

use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession in project wcomponents by BorderTech.

the class WServletPerformance_Test method testOtherServletAppCorrectness.

/**
 * Basic sanity-test to ensure that the other app is performing all the processing that it should.
 *
 * @throws Exception an exception
 */
@Test
public void testOtherServletAppCorrectness() throws Exception {
    SimpleServlet servlet = new SimpleServlet();
    servlet.init(new MockServletConfig());
    MockHttpSession session = new MockHttpSession();
    sendOtherServletRequest(servlet, session, 0);
    sendOtherServletRequest(servlet, session, 1);
    SimpleFormBean bean = servlet.getFormBean(new MockHttpServletRequest(session));
    Assert.assertEquals("Incorrect property1 value", "p1_1", bean.getProperty1());
    Assert.assertEquals("Incorrect property2 value", "p2_1", bean.getProperty2());
}
Also used : 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) Test(org.junit.Test)

Example 17 with MockHttpSession

use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession in project wcomponents by BorderTech.

the class WServletPerformance_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 SimpleServlet servlet = new SimpleServlet();
    servlet.init(new MockServletConfig());
    final MockHttpSession simpleServletSession = new MockHttpSession();
    // JIT warm-up
    for (int i = 0; i < count; i++) {
        sendOtherServletRequest(servlet, simpleServletSession, i);
    }
    simpleServletSession.getAttributes().clear();
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            try {
                for (int i = 0; i < count; i++) {
                    sendOtherServletRequest(servlet, simpleServletSession, i);
                }
            } catch (Exception e) {
                LOG.error("Failed to execute test", e);
            }
        }
    };
    return time(runnable);
}
Also used : MockServletConfig(com.github.bordertech.wcomponents.util.mock.servlet.MockServletConfig) MockHttpSession(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession) ServletException(javax.servlet.ServletException)

Example 18 with MockHttpSession

use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession in project wcomponents by BorderTech.

the class WServletPerformance_Test method testWServletAppCorrectness.

/**
 * Basic sanity-test to ensure that the WComponent app is performing all the processing that it should.
 *
 * @throws Exception an exception
 */
@Test
public void testWServletAppCorrectness() throws Exception {
    SimpleWServlet servlet = new SimpleWServlet();
    servlet.init(new MockServletConfig());
    MockHttpSession session = new MockHttpSession();
    // First request
    sendWServletRequest(servlet, session, 0, null);
    // Second request
    WServletHelper helper = new WServletHelper(servlet, new MockHttpServletRequest(session), new MockHttpServletResponse());
    UIContext uic = helper.getUIContext();
    SimpleApp app = (SimpleApp) uic.getUI();
    sendWServletRequest(servlet, session, 1, uic.getEnvironment().getSessionToken());
    setActiveContext(uic);
    Assert.assertEquals("Incorrect step", 2, uic.getEnvironment().getStep());
    Assert.assertEquals("Incorrect property1 value", "p1_1", ((SimpleFormBean) app.beanContainer.getBean()).getProperty1());
    Assert.assertEquals("Incorrect property2 value", "p2_1", ((SimpleFormBean) app.beanContainer.getBean()).getProperty2());
}
Also used : WServletHelper(com.github.bordertech.wcomponents.servlet.WServlet.WServletHelper) UIContext(com.github.bordertech.wcomponents.UIContext) 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