use of com.github.bordertech.wcomponents.util.mock.servlet.MockServletConfig 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.MockServletConfig in project wcomponents by BorderTech.
the class WServlet_Test method testHttpMethodTypes.
@Test
public void testHttpMethodTypes() throws ServletException, IOException {
MyWServlet servlet = new MyWServlet(new WText("test"));
servlet.init(new MockServletConfig());
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRequestURI("http://localhost/foo");
MockHttpServletResponse response = new MockHttpServletResponse();
request.setMethod("GET");
servlet.service(request, response);
Assert.assertEquals("Incorrect status code", 200, response.getStatus());
Assert.assertTrue("Should have written content", response.getOutput().length > 0);
response = new MockHttpServletResponse();
request.setMethod("POST");
servlet.service(request, response);
Assert.assertEquals("Incorrect status code", 200, response.getStatus());
Assert.assertTrue("Should have written content", response.getOutput().length > 0);
response = new MockHttpServletResponse();
request.setMethod("HEAD");
servlet.service(request, response);
Assert.assertEquals("Incorrect status code", 200, response.getStatus());
Assert.assertNull("Should not have written any content for HEAD request", response.getOutput());
response = new MockHttpServletResponse();
request.setMethod("DELETE");
servlet.service(request, response);
Assert.assertEquals("Incorrect status code", 501, response.getStatus());
Assert.assertNull("Should not have written any content for HEAD request", response.getOutput());
}
use of com.github.bordertech.wcomponents.util.mock.servlet.MockServletConfig 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.MockServletConfig in project wcomponents by BorderTech.
the class ThemeServlet_Test method setUp.
@Before
public void setUp() throws ServletException {
themeServlet = new ThemeServlet();
themeServlet.init(new MockServletConfig());
}
use of com.github.bordertech.wcomponents.util.mock.servlet.MockServletConfig 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());
}
Aggregations