Search in sources :

Example 31 with MockHttpServletRequest

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

the class ServletRequest_Test method testRenderParameterAccessors.

@Test
public void testRenderParameterAccessors() {
    String renderParamName = "ServletRequest_Test.testRenderParameterAccessors.renderParamName";
    String renderParamValue = "ServletRequest_Test.testRenderParameterAccessors.renderParamValue";
    // Set the render parameters on a request
    HttpSession session = new MockHttpSession();
    MockHttpServletRequest backing = new MockHttpServletRequest(session);
    ServletRequest request = new ServletRequest(backing);
    request.setRenderParameter(renderParamName, renderParamValue);
    Assert.assertEquals("Incorrect render parameter value after setRenderParameter", renderParamValue, request.getRenderParameter(renderParamName));
    // Test that the render parameters were stored in the session
    request = new ServletRequest(new MockHttpServletRequest(session));
    Assert.assertEquals("Incorrect render parameter value from another request", renderParamValue, request.getRenderParameter(renderParamName));
}
Also used : MockHttpServletRequest(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest) HttpSession(javax.servlet.http.HttpSession) MockHttpSession(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession) MockHttpServletRequest(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest) MockHttpSession(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession) Test(org.junit.Test)

Example 32 with MockHttpServletRequest

use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest 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.container.getBean()).getProperty1());
    Assert.assertEquals("Incorrect property2 value", "p2_1", ((SimpleFormBean) app.container.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)

Example 33 with MockHttpServletRequest

use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest 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 34 with MockHttpServletRequest

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

the class WServletPerformance_Test method sendOtherServletRequest.

/**
 * Invokes the other servlet request processing.
 *
 * @param servlet the servlet to invoke request processing on.
 * @param session the current session.
 * @param step the step count
 * @throws Exception an exception
 */
private void sendOtherServletRequest(final SimpleServlet servlet, final HttpSession session, final int step) throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest(session);
    MockHttpServletResponse response = new MockHttpServletResponse();
    if (step > 0) {
        request.setMethod("POST");
        request.setRequestURI("http://localhost/app");
        request.setParameter("formBean.property1", "p1_" + step);
        request.setParameter("formBean.property2", "p2_" + step);
        request.setParameter("submit", "Submit");
    } else {
        request.setMethod("GET");
        request.setRequestURI("http://localhost/app");
    }
    servlet.service(request, response);
}
Also used : MockHttpServletRequest(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest) MockHttpServletResponse(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse)

Example 35 with MockHttpServletRequest

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

the class SerializationPerformance_Test method sendRequest.

/**
 * Invokes WComponent request processing, so that this test case can more closely match a production scenario.
 *
 * @param comp the component to invoke request processing on.
 * @param uic the user context to use.
 */
private void sendRequest(final WComponent comp, final UIContext uic) {
    PrintWriter writer = new PrintWriter(new NullWriter());
    uic.setEnvironment(new WServlet.WServletEnvironment("", "http://localhost", ""));
    uic.setUI(comp);
    InterceptorComponent root = ServletUtil.createInterceptorChain(new MockHttpServletRequest());
    root.attachUI(comp);
    Response response = new MockResponse();
    root.attachResponse(response);
    setActiveContext(uic);
    MockRequest request = new MockRequest();
    try {
        root.serviceRequest(request);
        root.preparePaint(request);
        root.paint(new WebXmlRenderContext(writer));
    } finally {
        resetContext();
    }
}
Also used : MockResponse(com.github.bordertech.wcomponents.util.mock.MockResponse) WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) MockResponse(com.github.bordertech.wcomponents.util.mock.MockResponse) InterceptorComponent(com.github.bordertech.wcomponents.container.InterceptorComponent) MockHttpServletRequest(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) WServlet(com.github.bordertech.wcomponents.servlet.WServlet) NullWriter(com.github.bordertech.wcomponents.util.NullWriter) PrintWriter(java.io.PrintWriter)

Aggregations

MockHttpServletRequest (com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest)36 Test (org.junit.Test)25 MockHttpServletResponse (com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse)13 MockHttpSession (com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession)13 MockServletConfig (com.github.bordertech.wcomponents.util.mock.servlet.MockServletConfig)9 WText (com.github.bordertech.wcomponents.WText)5 PrintWriter (java.io.PrintWriter)5 UIContext (com.github.bordertech.wcomponents.UIContext)4 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)4 MockResponse (com.github.bordertech.wcomponents.util.mock.MockResponse)4 ServletRequest (com.github.bordertech.wcomponents.servlet.ServletRequest)3 NullWriter (com.github.bordertech.wcomponents.util.NullWriter)3 AbstractWComponent (com.github.bordertech.wcomponents.AbstractWComponent)2 WComponent (com.github.bordertech.wcomponents.WComponent)2 InterceptorComponent (com.github.bordertech.wcomponents.container.InterceptorComponent)2 WServlet (com.github.bordertech.wcomponents.servlet.WServlet)2 WServletHelper (com.github.bordertech.wcomponents.servlet.WServlet.WServletHelper)2 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)2 StringWriter (java.io.StringWriter)2 Locale (java.util.Locale)2