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