Package net.sourceforge.cruisecontrol.mock

Examples of net.sourceforge.cruisecontrol.mock.MockServletResponse


    /*
     * Test for void service(HttpServletRequest, HttpServletResponse)
     */
    public void testServiceInvalidFile() throws ServletException, IOException {
        MockServletRequest request = new MockServletRequest();
        MockServletResponse response = new MockServletResponse();

        final String fileName = "tmp12345.html";
        request.setPathInfo(fileName);

        servlet.service(request, response);
        String actual = response.getWritten();
        String expected = "<html><body><h1>" + fileName + "</h1><h1>Invalid File or Directory</h1></body></html>";
        assertEquals(expected, actual);
        String actualMimeType = response.getContentType();
        assertEquals("text/html", actualMimeType);
    }
View Full Code Here


    /*
     * Test for void service(HttpServletRequest, HttpServletResponse)
     */
    public void testServiceFile() 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());
        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/html", actualMimeType);
    }
View Full Code Here

    /*
     * 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());

    }
View Full Code Here

    /*
     * Test for void service(HttpServletRequest, HttpServletResponse)
     */
    public void testService() 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());
        servlet = new FileServlet() {
            File getRootDir(ServletConfig servletconfig) {
                return dir;
            }
        };
        servlet.service(request, response);
        String actual = response.getWritten();
        String expected = "<html><body><h1>" + file.getName() + "</h1><h1>Invalid File or Directory</h1></body></html>";
        assertEquals(expected, actual);
        String actualMimeType = response.getContentType();
        assertEquals("text/html", actualMimeType);
    }
View Full Code Here

TOP

Related Classes of net.sourceforge.cruisecontrol.mock.MockServletResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.