use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession 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.mock.servlet.MockHttpSession in project wcomponents by BorderTech.
the class WServlet_Test method testServiceNormalRequest.
@Test
public void testServiceNormalRequest() throws ServletException, IOException {
MockServletConfig config = new MockServletConfig();
config.setInitParameter(WServlet.WServletHelper.ONGOING_URL_SUFFIX, "foo");
MockContainer content = new MockContainer();
content.add(new WText(LABEL_TEXT));
content.setLocked(true);
MyWServlet servlet = new MyWServlet(content);
servlet.init(config);
MockHttpSession session1 = new MockHttpSession();
MockHttpSession session2 = new MockHttpSession();
sendRequest(session1, servlet);
sendRequest(session2, servlet);
sendRequest(session1, servlet);
// check handle request / paint counts for each session
UIContext uic = getContextForSession(servlet, session1);
setActiveContext(uic);
Assert.assertEquals("Incorrect handle request count for session1", 2, content.getHandleRequestCount());
Assert.assertEquals("Incorrect paint count for session1", 2, content.getPaintCount());
uic = getContextForSession(servlet, session2);
setActiveContext(uic);
Assert.assertEquals("Incorrect handle request count for session2", 1, content.getHandleRequestCount());
Assert.assertEquals("Incorrect paint count for session2", 1, content.getPaintCount());
}
use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession in project wcomponents by BorderTech.
the class WServlet_Test method testSubSessionsEnabledNoSSID.
@Test
public void testSubSessionsEnabledNoSSID() throws ServletException, IOException {
Config.getInstance().setProperty(ConfigurationProperties.SERVLET_ENABLE_SUBSESSIONS, "true");
MyWServlet servlet = new MyWServlet(new WText("test"));
servlet.init(new MockServletConfig());
MockHttpSession session = new MockHttpSession();
servlet.service(new MockHttpServletRequest(session), new MockHttpServletResponse());
Assert.assertEquals("Incorrect invocation count", 1, servlet.lastInvocationCount);
// No SSID should trigger a new subsession
servlet.service(new MockHttpServletRequest(session), new MockHttpServletResponse());
Assert.assertEquals("Incorrect invocation count", 1, servlet.lastInvocationCount);
}
use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession 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));
}
use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession in project wcomponents by BorderTech.
the class ServletRequest_Test method testAppSessionAttributeAccessors.
@Test
public void testAppSessionAttributeAccessors() {
String attributeName = "ServletRequest_Test.testAppSessionAttributeAccessors.attributeName";
String attributeValue1 = "ServletRequest_Test.testAppSessionAttributeAccessors.attributeValue1";
String attributeValue2 = "ServletRequest_Test.testAppSessionAttributeAccessors.attributeValue2";
// Test with no session
MockHttpServletRequest backing = new MockHttpServletRequest();
ServletRequest request = new ServletRequest(backing);
Assert.assertNull("Attribute should be null if no session", request.getAppSessionAttribute(attributeName));
request.setAppSessionAttribute(attributeName, attributeValue1);
Assert.assertEquals("Incorrect attribute value after setAppSessionAttribute", attributeValue1, request.getAppSessionAttribute(attributeName));
// Test with a session
MockHttpSession session = new MockHttpSession();
session.setAttribute(attributeName, attributeValue1);
backing = new MockHttpServletRequest(session);
request = new ServletRequest(backing);
Assert.assertEquals("Incorrect attribute value", attributeValue1, request.getAppSessionAttribute(attributeName));
request.setAppSessionAttribute(attributeName, attributeValue2);
Assert.assertEquals("Incorrect attribute value after setAppSessionAttribute", attributeValue2, request.getAppSessionAttribute(attributeName));
}
Aggregations