Package net.sourceforge.cruisecontrol.mock

Examples of net.sourceforge.cruisecontrol.mock.MockServletConfig


    protected void tearDown() {
        servlet = null;
    }

    public void testGetRootDir() {
        MockServletConfig config = new MockServletConfig();
        MockServletContext context = new MockServletContext();
        config.setServletContext(context);
       
        try {
            servlet.getRootDir(config);
            fail("should have exception when required attributes not set");
        } catch (ServletException e) {
        }

        config.setInitParameter("rootDir", ".");
        try {
            servlet.getRootDir(config);
        } catch (ServletException e) {
            fail("shouldn't throw exception when valid rootDir parameter set");
        }
       
        context.setInitParameter("logDir", "this directory does not exist");
        try {
            servlet.getRootDir(config);
        } catch (ServletException e) {
            fail("good rootDir but bad logDir should work");
        }
       
        config = new MockServletConfig();
        context = new MockServletContext();
        config.setServletContext(context);

        context.setInitParameter("logDir", ".");
        try {
            servlet.getRootDir(config);
        } catch (ServletException e) {
            fail("shouldn't throw exception when valid logDir parameter set");
        }
       
        config.setInitParameter("rootDir", "this directory does not exist");
        try {
            servlet.getRootDir(config);
        } catch (ServletException e) {
            fail("bad rootDir but good logDir should work");
        }
View Full Code Here


                    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);
View Full Code Here

                    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);
View Full Code Here

        request.setPathInfo(file.getName());

    }

    public void testGetIndexes() throws ServletException, IOException {
        MockServletConfig config = new MockServletConfig();
        MockServletContext context = new MockServletContext();
        config.setServletContext(context);

        List indexes;

        // 1- no index defined
        indexes = servlet.getIndexFiles(config);
View Full Code Here

        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();
View Full Code Here

        logDir = new File("testresults/ProjectNavigationTagTest");
        if (!logDir.exists()) {
            assertTrue("Failed to create test result dir", logDir.mkdir());
        }
        final MockServletConfig servletConfig = (MockServletConfig) pageContext.getServletConfig();
        servletConfig.setInitParameter("logDir", logDir.getAbsolutePath());
       

        logProjects = new File[] { new File(logDir, "ProjectB"), new File(logDir, "Project A"),
                                   new File(logDir, "First_project") };
        for (int i = 0; i < logProjects.length; i++) {
View Full Code Here

        logDir = new File("testresults/NavigationTagTest");
        if (!logDir.exists()) {
            assertTrue("Failed to create test result dir", logDir.mkdirs());
        }
        final MockServletConfig servletConfig = (MockServletConfig) pageContext.getServletConfig();
        servletConfig.setInitParameter("logDir", logDir.getAbsolutePath());

        logFiles = new File[] { new File(logDir, "log20020222120000.xml"), new File(logDir, "log20020223120000.xml"),
                                new File(logDir, "log20020224120000.xml"), new File(logDir, "log20020225120000.xml") };
        for (int i = 0; i < logFiles.length; i++) {
            File logFile = logFiles[i];
View Full Code Here

    protected void setUp() {
        pageContext = new MockPageContext();
        tag = new BuildInfoTag();
        tag.setPageContext(pageContext);

        final MockServletConfig servletConfig = (MockServletConfig) pageContext.getServletConfig();
        servletConfig.setInitParameter("logDir", LogFileSetupDecorator.LOG_DIR.getAbsolutePath());
    }
View Full Code Here

        pageContext.setHttpServletRequest(request);

        tag = new ArtifactsLinkTag();
        tag.setPageContext(pageContext);

        final MockServletConfig servletConfig = (MockServletConfig) pageContext.getServletConfig();
        servletConfig.setInitParameter("logDir", LogFileSetupDecorator.LOG_DIR.getAbsolutePath());
    }
View Full Code Here

    protected void tearDown() {
        servlet = null;
    }

    public void testGetRootDir() {
        MockServletConfig config = new MockServletConfig();
        MockServletContext context = new MockServletContext();
        config.setServletContext(context);
       
        try {
            servlet.getRootDir(config);
            fail("should have exception when required attributes not set");
        } catch (ServletException e) {
        }

        config.setInitParameter("rootDir", ".");
        try {
            servlet.getRootDir(config);
        } catch (ServletException e) {
            fail("shouldn't throw exception when valid rootDir parameter set");
        }
       
        context.setInitParameter("logDir", "this directory does not exist");
        try {
            servlet.getRootDir(config);
        } catch (ServletException e) {
            fail("good rootDir but bad logDir should work");
        }
       
        config = new MockServletConfig();
        context = new MockServletContext();
        config.setServletContext(context);

        context.setInitParameter("logDir", ".");
        try {
            servlet.getRootDir(config);
        } catch (ServletException e) {
            fail("shouldn't throw exception when valid logDir parameter set");
        }
       
        config.setInitParameter("rootDir", "this directory does not exist");
        try {
            servlet.getRootDir(config);
        } catch (ServletException e) {
            fail("bad rootDir but good logDir should work");
        }
View Full Code Here

TOP

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

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.