Package net.sourceforge.cruisecontrol.mock

Examples of net.sourceforge.cruisecontrol.mock.MockServletRequest


    public void setUp() {
        tag = new CruiseControlTagSupport();
        MockPageContext pageContext = new MockPageContext();
        tag.setPageContext(pageContext);
        request = new MockServletRequest("context", "servlet");
        pageContext.setHttpServletRequest(request);

        logDir = new File("testresults/");
        if (!logDir.exists()) {
            assertTrue("Failed to create test result dir", logDir.mkdir());
View Full Code Here


    protected void setUp() {
        tabSheet = new TabSheetTag();
        content = new MockBodyContent();
        tabSheet.setBodyContent(content);
        pageContext = new MockPageContext();
        request = new MockServletRequest("context", "servlet");
        pageContext.setHttpServletRequest(request);
        tabSheet.setPageContext(pageContext);
    }
View Full Code Here

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

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

                new String("log2")
            };

        final StringWriter writer1 = new StringWriter();

        final MockServletRequest request1 = new MockServletRequest() {
            public String getRequestURI() {
                return "/artifacts/abc";
            }
        };
        fileServlet.printDirs(request1, new MockWebFile(new File("notimportant"), "notimportant", files), writer1);

        final String expectedOutput1 =
            "<ul>"
            + "<li><a href=\"/artifacts/abc/log1.txt\">log1.txt</a></li>"
            + "<li><a href=\"/artifacts/abc/log2\">log2/</a></li>"
            + "</ul>";

        assertEquals(expectedOutput1, writer1.getBuffer().toString());


        final StringWriter writer2 = new StringWriter();
        final MockServletRequest request2 = new MockServletRequest() {
            public String getRequestURI() {
                return "/artifacts/abc;jsessionid=012456789ABCDEF";
            }
        };
        fileServlet.printDirs(request2, new MockWebFile(new File("/tmp"), "test", files), writer2);
View Full Code Here

        assertEquals(expectedOutput2, writer2.getBuffer().toString());
    }

    public void testServiceIndexFile() throws ServletException, IOException {
        MockServletRequest request = new MockServletRequest() {
          public String getRequestURI() {
            return "";
          }
        };
        MyMockServletResponse response1 = new MyMockServletResponse();
        final File dir = new File(System.getProperty("java.io.tmpdir"));

        MyMockFileServlet myServlet = new MyMockFileServlet();
        myServlet.setRootDir(dir);

        MockServletConfig config = new MockServletConfig();
        MockServletContext context = new MockServletContext() {
            public String getMimeType(String s) {
                return "text/html";
            }
        };
        config.setServletContext(context);
        myServlet.init(config);

        File indexFile = new File(dir, "index.html");
        indexFile.deleteOnExit();
        assertFalse("cannot test service index if index.html already exists", indexFile.exists());
        boolean created = indexFile.createNewFile();
        assertTrue(created);

        // redirect when no trailing path, even if no index defined.
        request.setPathInfo("");
        myServlet.service(request, response1);
        response1.ensureRedirect("/");
        assertEquals(0, myServlet.printDirCalls);

        // do not display index if none configured
        myServlet.init();
        MyMockServletResponse response2 = new MyMockServletResponse();
        request.setPathInfo("/");
        myServlet.service(request, response2);
        String actual = response2.getWritten();
        assertTrue(actual.startsWith("<html><body><h1>"));
        assertTrue(myServlet.printDirCalls > 0);
        String actualMimeType = response2.getContentType();
        assertEquals("text/html", actualMimeType);

        // use index if one exists when asking for trailing path and fileServlet.indexFiles configured
        myServlet.init();
        MyMockServletResponse response3 = new MyMockServletResponse();
        context.setInitParameter("fileServlet.welcomeFiles", "index.html");
        config.setServletContext(context);
        myServlet.init(config);

        request.setPathInfo("/");
        myServlet.service(request, response3);
        actual = response3.getWritten();
        String expected = "";
        assertEquals(expected, actual);
        actualMimeType = response3.getContentType();
View Full Code Here

    private File[] logProjects;

    public void setUp() throws IOException {
        tag = new ProjectNavigationTag();
        pageContext = new MockPageContext();
        MockServletRequest request = new MockServletRequest("context", "servlet");
        request.setLocale(Locale.US);
        request.setPathInfo("/Project A");
        pageContext.setHttpServletRequest(request);

        tag.setPageContext(pageContext);
        tag.setBodyContent(new MockBodyContent());
View Full Code Here

    private File logDir;

    public void setUp() throws IOException {
        tag = new NavigationTag();
        pageContext = new MockPageContext();
        MockServletRequest request = new MockServletRequest("context", "servlet");
        request.setLocale(Locale.US);
        pageContext.setHttpServletRequest(request);

        tag.setPageContext(pageContext);
        tag.setBodyContent(new MockBodyContent());
View Full Code Here

    public static Test suite() {
        return new LogFileSetupDecorator(new TestSuite(ArtifactsLinkTagTest.class));
    }

    protected void setUp() throws Exception {
        request = new MockServletRequest("context", "servlet");

        pageContext = new MockPageContext();
        pageContext.setHttpServletRequest(request);

        tag = new ArtifactsLinkTag();
View Full Code Here

TOP

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

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.