Package org.nutz.mock.servlet

Examples of org.nutz.mock.servlet.MockHttpServletRequest


    /**
     * for issue #617
     */
    @Test
    public void test_upload_empty_just_r_n() throws Exception {
        MockHttpServletRequest req = Mock.servlet.request();
        req.setPathInfo("/nutz/junit/uploading");
        MultipartInputStream ins = Mock.servlet.insmulti(charset);
        File f = Files.findFile("org/nutz/mvc/upload/files/_r_n.txt");
        ins.append("theF", f);
        req.setInputStream(ins);
        req.init();

        /*
         * 默认不忽略空文件
         */
        Uploading up = UploadUnit.TYPE.born();
View Full Code Here


    /**
     * 测试限制文件类型:限制文件类型
     */
    @Test(expected = UploadUnsupportedFileTypeException.class)
    public void test_limit_file_content_type_fail() throws UploadException {
        MockHttpServletRequest req = Mock.servlet.request();
        req.setPathInfo("/nutz/junit/uploading");
        File blue = Files.findFile("org/nutz/mvc/upload/files/quick/blue.png");

        MultipartInputStream ins = Mock.servlet.insmulti(charset);
        ins.append("blue", blue);
        req.setInputStream(ins);
        req.init();

        /*
         * 文件超大,会限制
         */
        Uploading up = UploadUnit.TYPE.born();
View Full Code Here

    /**
     * 测试限制文件名:限制文件名称
     */
    @Test(expected = UploadUnsupportedFileNameException.class)
    public void test_limit_file_name_fail() throws UploadException {
        MockHttpServletRequest req = Mock.servlet.request();
        req.setPathInfo("/nutz/junit/uploading");
        File blue = Files.findFile("org/nutz/mvc/upload/files/quick/blue.png");

        MultipartInputStream ins = Mock.servlet.insmulti(charset);
        ins.append("blue", blue);
        req.setInputStream(ins);
        req.init();

        /*
         * 文件超大,会限制
         */
        Uploading up = UploadUnit.TYPE.born();
View Full Code Here

    /**
     * 测试限制文件大小:文件不超过尺寸,不会会抛错
     */
    @Test
    public void test_limit_file_size_ok() throws UploadException {
        MockHttpServletRequest req = Mock.servlet.request();
        req.setPathInfo("/nutz/junit/uploading");
        File blue = Files.findFile("org/nutz/mvc/upload/files/quick/blue.png");

        MultipartInputStream ins = Mock.servlet.insmulti(charset);
        ins.append("blue", blue);
        req.setInputStream(ins);
        req.init();

        /*
         * 文件超大,会限制
         */
        Uploading up = UploadUnit.TYPE.born();
View Full Code Here

        Mvcs.setServletContext(Mock.servlet.context());
    }

    @Test
    public void test_name() throws Exception {
        MockHttpServletRequest req = Mock.servlet.fullRequest();
        JspView fv = new JspView("abc.bcd");
        fv.render(req, null, null);
        assertEquals("/WEB-INF/abc/bcd.jsp", req.getDispatcherTarget());
    }
View Full Code Here

        assertEquals("/WEB-INF/abc/bcd.jsp", req.getDispatcherTarget());
    }

    @Test
    public void test_req_path() throws Exception {
        MockHttpServletRequest req = Mock.servlet.fullRequest();
        req.setPathInfo("/abc/bcd.do");
        JspView fv = new JspView(null);
        fv.render(req, null, null);
        assertEquals("/WEB-INF/abc/bcd.jsp", req.getDispatcherTarget());
    }
View Full Code Here

    /**
     * 测试限制文件大小:文件超出尺寸,会抛错
     */
    @Test(expected = UploadOutOfSizeException.class)
    public void test_limit_file_size_fail() throws UploadException {
        MockHttpServletRequest req = Mock.servlet.request();
        req.setPathInfo("/nutz/junit/uploading");
        File blue = Files.findFile("org/nutz/mvc/upload/files/quick/blue.png");

        MultipartInputStream ins = Mock.servlet.insmulti(charset);
        ins.append("blue", blue);
        req.setInputStream(ins);
        req.init();

        /*
         * 文件超大,会限制
         */
        Uploading up = UploadUnit.TYPE.born();
View Full Code Here

        assertEquals("/WEB-INF/abc/bcd.jsp", req.getDispatcherTarget());
    }

    @Test
    public void test_req_path2() throws Exception {
        MockHttpServletRequest req = Mock.servlet.fullRequest();
        req.setPathInfo("/abc/bcd.do");
        JspView fv = new JspView("");
        fv.render(req, null, null);
        assertEquals("/WEB-INF/abc/bcd.jsp", req.getDispatcherTarget());
    }
View Full Code Here

    /**
     * 测试忽略空文件
     */
    @Test
    public void test_upload_ignore_null() throws UploadException {
        MockHttpServletRequest req = Mock.servlet.request();
        req.setPathInfo("/nutz/junit/uploading");
        File txt = Files.findFile("org/nutz/mvc/upload/files/quick/abc.zdoc");
        File empty = Files.findFile("org/nutz/mvc/upload/files/empty.txt");

        MultipartInputStream ins = Mock.servlet.insmulti(charset);
        ins.append("abc", txt);
        ins.append("empty", empty);
        req.setInputStream(ins);
        req.init();

        /*
         * 默认不忽略空文件
         */
        Uploading up = UploadUnit.TYPE.born();
        Map<String, Object> map = up.parse(req, UploadingContext.create(tmps));
        assertEquals(2, map.size());
        TempFile txt2 = (TempFile) map.get("abc");
        TempFile empty2 = (TempFile) map.get("empty");

        assertEquals("abc.zdoc", txt2.getMeta().getFileLocalName());
        assertTrue(Files.equals(txt, txt2.getFile()));

        assertEquals("empty.txt", empty2.getMeta().getFileLocalName());
        assertTrue(Files.equals(empty, empty2.getFile()));

        /*
         * 设置忽略空文件
         */
        ins = Mock.servlet.insmulti(charset);
        ins.append("abc", txt);
        ins.append("empty", empty);
        req.setInputStream(ins);
        req.init();
        up = UploadUnit.TYPE.born();
        map = up.parse(req, UploadingContext.create(tmps).setIgnoreNull(true));
        assertEquals(1, map.size());
        txt2 = (TempFile) map.get("abc");
        empty2 = (TempFile) map.get("empty");
View Full Code Here

        assertEquals("/WEB-INF/abc/bcd.jsp", req.getDispatcherTarget());
    }

    @Test
    public void test_req_path3() throws Exception {
        MockHttpServletRequest req = Mock.servlet.fullRequest();
        req.setPathInfo("/abc/bcd.do");
        JspView fv = new JspView("  \r\n\t  ");
        fv.render(req, null, null);
        assertEquals("/WEB-INF/abc/bcd.jsp", req.getDispatcherTarget());
    }
View Full Code Here

TOP

Related Classes of org.nutz.mock.servlet.MockHttpServletRequest

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.