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());
}
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();
}
}
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();
}
}
Aggregations