Package net.sourceforge.cruisecontrol.mock

Examples of net.sourceforge.cruisecontrol.mock.MockServletContext


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


                }
                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 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

    }

    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);
        assertNotNull(indexes);
        assertEquals(0, indexes.size());

        // 2-
        context.setInitParameter("fileServlet.welcomeFiles", null);
        indexes = servlet.getIndexFiles(config);
        assertNotNull(indexes);
        assertEquals(0, indexes.size());

        // 3-
        context.setInitParameter("fileServlet.welcomeFiles", "");
        indexes = servlet.getIndexFiles(config);
        assertNotNull(indexes);
        assertEquals(0, indexes.size());

        // 4- some indexes defined
        context.setInitParameter("fileServlet.welcomeFiles", "index.htm index.html");
        indexes = servlet.getIndexFiles(config);
        assertNotNull(indexes);
        assertEquals(2, indexes.size());
        assertEquals("index.htm", indexes.get(0));
        assertEquals("index.html", indexes.get(1));

        // 5- resistant to strange spacing
        context.setInitParameter("fileServlet.welcomeFiles", " index.html  index.htm ");
        indexes = servlet.getIndexFiles(config);
        assertNotNull(indexes);
        assertEquals(2, indexes.size());
        assertEquals("index.html", indexes.get(0));
        assertEquals("index.htm", indexes.get(1));
View Full Code Here

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

        assertEquals("text/html", actualMimeType);
        assertEquals(0, myServlet.printDirCalls);
    }

    public void testGetMimeType() {
        MockServletContext context = new MockServletContext() {
            public String getMimeType(String s) {
                return "text/html";
            }
        };
        servlet = new TestFileServlet(context);
        assertEquals("text/html", servlet.getMimeType(""));

        context = new MockServletContext() {
            public String getMimeType(String s) {
                return null;
            }
        };
        servlet = new TestFileServlet(context);
View Full Code Here

    }

    private XSLTag createXSLTag() {
        XSLTag tag = new XSLTag();
        final MockPageContext pageContext = new MockPageContext();
        final MockServletContext servletContext = (MockServletContext) pageContext.getServletContext();
        servletContext.setBaseResourceDir(logDir);
        tag.setPageContext(pageContext);
        tag.setXslRootContext("/");
        return tag;
    }
View Full Code Here

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

        String actualMimeType = response.getContentType();
        assertEquals("text/html", actualMimeType);
    }

    public void testGetMimeType() {
        MockServletContext context = new MockServletContext() {
            public String getMimeType(String s) {
                return "text/html";
            }
        };
        servlet = new TestFileServlet(context);
        assertEquals("text/html", servlet.getMimeType(""));

        context = new MockServletContext() {
            public String getMimeType(String s) {
                return null;
            }
        };
        servlet = new TestFileServlet(context);
View Full Code Here

        InputStream in = new FileInputStream(log2);
        StringWriter out = new StringWriter();

        XSLTag tag = new XSLTag();
        final MockPageContext pageContext = new MockPageContext();
        final MockServletContext servletContext = (MockServletContext) pageContext.getServletContext();
        servletContext.setBaseResourceDir(logDir);
        tag.setPageContext(pageContext);
        tag.setXslRootContext("/");
        tag.transform(log3, in, out);
        assertEquals("test=3.1", out.toString());
    }
View Full Code Here

TOP

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

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.