Search in sources :

Example 6 with NullWriter

use of com.github.bordertech.wcomponents.util.NullWriter in project wcomponents by BorderTech.

the class WServlet_Test method testServiceAjaxRequest.

@Test
public void testServiceAjaxRequest() throws ServletException, IOException {
    AjaxTestUI ui = new AjaxTestUI();
    ui.setLocked(true);
    MockHttpSession session1 = new MockHttpSession();
    UIContextImpl uic1 = new UIContextImpl();
    uic1.setEnvironment(new WServlet.WServletEnvironment("app", "http://localhost", ""));
    uic1.setUI(ui);
    uic1.getEnvironment().setSessionToken("1");
    uic1.getEnvironment().setStep(1);
    MockHttpSession session2 = new MockHttpSession();
    UIContextImpl uic2 = new UIContextImpl();
    uic2.setEnvironment(new WServlet.WServletEnvironment("app", "http://localhost", ""));
    uic2.setUI(ui);
    uic2.getEnvironment().setSessionToken("2");
    // Request cycle for session 1
    setActiveContext(uic1);
    ui.serviceRequest(new ServletRequest(new MockHttpServletRequest(session1)));
    ui.preparePaint(new ServletRequest(new MockHttpServletRequest(session1)));
    ui.paint(new WebXmlRenderContext(new PrintWriter(new NullWriter())));
    // Request cycle for session 2
    setActiveContext(uic2);
    ui.serviceRequest(new ServletRequest(new MockHttpServletRequest(session2)));
    ui.preparePaint(new ServletRequest(new MockHttpServletRequest(session2)));
    ui.paint(new WebXmlRenderContext(new PrintWriter(new NullWriter())));
    // check handle request / paint counts for each session - label should not have been painted for either.
    setActiveContext(uic1);
    Assert.assertEquals("HandleRequest should have been called for main panel in session1", 1, ui.mainPanel.getHandleRequestCount());
    Assert.assertEquals("HandleRequest should have been called for ajax panel in session1", 1, ui.ajaxPanel.getHandleRequestCount());
    Assert.assertEquals("HandleRequest should have been called for label panel in session1", 1, ui.label.getHandleRequestCount());
    Assert.assertEquals("Main panel should have painted in session1", 1, ui.mainPanel.getPaintCount());
    Assert.assertEquals("Ajax panel should have painted in session1", 1, ui.ajaxPanel.getPaintCount());
    Assert.assertEquals("Label should not have painted in session1", 0, ui.label.getPaintCount());
    setActiveContext(uic2);
    Assert.assertEquals("HandleRequest should have been called for main panel in session2", 1, ui.mainPanel.getHandleRequestCount());
    Assert.assertEquals("HandleRequest should have been called for ajax panel in session2", 1, ui.ajaxPanel.getHandleRequestCount());
    Assert.assertEquals("HandleRequest should have been called for label panel in session2", 1, ui.label.getHandleRequestCount());
    Assert.assertEquals("Main panel should have painted in session2", 1, ui.mainPanel.getPaintCount());
    Assert.assertEquals("Ajax panel should have painted in session2", 1, ui.ajaxPanel.getPaintCount());
    Assert.assertEquals("Label should not have painted in session2", 0, ui.label.getPaintCount());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest) MockHttpServletRequest(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest) UIContextImpl(com.github.bordertech.wcomponents.UIContextImpl) MockHttpSession(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession) NullWriter(com.github.bordertech.wcomponents.util.NullWriter) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 7 with NullWriter

use of com.github.bordertech.wcomponents.util.NullWriter 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)

Example 8 with NullWriter

use of com.github.bordertech.wcomponents.util.NullWriter in project wcomponents by BorderTech.

the class WebXmlRenderingPerformance_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 : Response(com.github.bordertech.wcomponents.Response) 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

NullWriter (com.github.bordertech.wcomponents.util.NullWriter)8 PrintWriter (java.io.PrintWriter)8 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)7 Test (org.junit.Test)5 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)4 RenderContext (com.github.bordertech.wcomponents.RenderContext)3 UIContext (com.github.bordertech.wcomponents.UIContext)3 WServlet (com.github.bordertech.wcomponents.servlet.WServlet)3 MockHttpServletRequest (com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest)3 AllComponents (com.github.bordertech.wcomponents.AllComponents)2 UIContextImpl (com.github.bordertech.wcomponents.UIContextImpl)2 InterceptorComponent (com.github.bordertech.wcomponents.container.InterceptorComponent)2 MockResponse (com.github.bordertech.wcomponents.util.mock.MockResponse)2 InternalResource (com.github.bordertech.wcomponents.InternalResource)1 MockLabel (com.github.bordertech.wcomponents.MockLabel)1 Response (com.github.bordertech.wcomponents.Response)1 WApplication (com.github.bordertech.wcomponents.WApplication)1 WComponent (com.github.bordertech.wcomponents.WComponent)1 WContent (com.github.bordertech.wcomponents.WContent)1 WWindow (com.github.bordertech.wcomponents.WWindow)1