/*
* Test for void service(HttpServletRequest, HttpServletResponse)
*/
public void testServiceParametrizedMimeType() throws ServletException, IOException {
MockServletRequest request = new MockServletRequest();
MockServletResponse response = new MockServletResponse();
File file = File.createTempFile("tmp", ".html");
file.deleteOnExit();
final File dir = file.getParentFile();
request.setPathInfo(file.getName());
request.addParameter("mimetype", "text/plain");
servlet = new FileServlet() {
File getRootDir(ServletConfig servletconfig) {
return dir;
}
String getMimeType(String filename) {
if (filename.endsWith(".html")) {
return "text/html";
}
return null;
}
};
final MockServletConfig servletconfig = new MockServletConfig();
servletconfig.setServletContext(new MockServletContext());
servlet.init(servletconfig);
servlet.service(request, response);
String actual = response.getWritten();
String expected = "";
assertEquals(expected, actual);
String actualMimeType = response.getContentType();
assertEquals("text/plain", actualMimeType);
request.setPathInfo(file.getName());
}