use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse in project wcomponents by BorderTech.
the class ServletResponse_Test method testGetOutputStream.
@Test
public void testGetOutputStream() throws IOException {
MockHttpServletResponse backing = new MockHttpServletResponse();
ServletResponse response = new ServletResponse(backing);
Assert.assertSame("Incorrect outputStream", backing.getOutputStream(), response.getOutputStream());
}
use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse in project wcomponents by BorderTech.
the class ThemeServlet_Test method testValidFile.
@Test
public void testValidFile() throws ServletException, IOException {
MockHttpServletResponse response = requestFile("ThemeServlet_Testfile.xsl", false);
Assert.assertEquals("Should have returned 200", HttpServletResponse.SC_OK, response.getStatus());
Assert.assertEquals("Incorrect MIME type", ConfigurationProperties.getFileMimeTypeForExtension("xsl"), response.getContentType());
response = requestFile("ThemeServlet_Testfile.xsl", true);
Assert.assertEquals("Should have returned 200", HttpServletResponse.SC_OK, response.getStatus());
Assert.assertEquals("Incorrect MIME type", ConfigurationProperties.getFileMimeTypeForExtension("xsl"), response.getContentType());
}
use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse in project wcomponents by BorderTech.
the class ThemeServlet_Test method testInvalidFiles.
@Test
public void testInvalidFiles() throws ServletException, IOException {
// Test Invalid due to relative path
MockHttpServletResponse response = requestFile("../wcomponents.properties", false);
Assert.assertEquals("Should have returned 404", HttpServletResponse.SC_NOT_FOUND, response.getStatus());
response = requestFile("../wcomponents.properties", true);
Assert.assertEquals("Should have returned 404", HttpServletResponse.SC_NOT_FOUND, response.getStatus());
response = requestFile("/wcomponents.properties", false);
Assert.assertEquals("Should have returned 404", HttpServletResponse.SC_NOT_FOUND, response.getStatus());
response = requestFile("/wcomponents.properties", true);
Assert.assertEquals("Should have returned 404", HttpServletResponse.SC_NOT_FOUND, response.getStatus());
// Invalid due to non-existant resource
response = requestFile("xslt/ThemeServlet_Test.testInvalidFiles", false);
Assert.assertEquals("Should have returned 404", HttpServletResponse.SC_NOT_FOUND, response.getStatus());
}
use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse in project wcomponents by BorderTech.
the class ThemeServlet_Test method requestFile.
/**
* Requests a file from the servlet.
*
* @param path the path to the file
* @param asParam true to use the ThemeServlet's 'f' parameter or false to place the path in the URL.
* @return the servlet response
* @throws ServletException a servlet exception
* @throws IOException an exception
*/
private MockHttpServletResponse requestFile(final String path, final boolean asParam) throws ServletException, IOException {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
if (asParam) {
request.setRequestURI("/theme");
request.setParameter("f", path);
} else {
request.setRequestURI("/theme/" + path);
request.setPathInfo('/' + path);
}
themeServlet.doGet(request, response);
return response;
}
use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse 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);
}
Aggregations