Package org.nutz.mock.servlet.multipart

Examples of org.nutz.mock.servlet.multipart.MultipartInputStream


    public void test_upload_queryString() throws UploadException {
        MockHttpServletRequest req = Mock.servlet.request();
        req.setParameter("id", "1");
        req.setParameter("name", "nutz");
        Uploading up = UploadUnit.TYPE.born();
        MultipartInputStream ins = Mock.servlet.insmulti(charset);
        ins.append("age", "1");
        req.setInputStream(ins);
        req.init();
        Map<String, Object> map = up.parse(req, UploadingContext.create(tmps));
        assertEquals("1", map.get("id"));
        assertEquals("nutz", map.get("name"));
View Full Code Here


    public void test_upload_onlyQueryString() throws UploadException {
        MockHttpServletRequest req = Mock.servlet.request();
        req.setParameter("id", "1");
        req.setParameter("name", "nutz");
        Uploading up = UploadUnit.TYPE.born();
        MultipartInputStream ins = Mock.servlet.insmulti(charset);
        req.setInputStream(ins);
        req.init();
        Map<String, Object> map = up.parse(req, UploadingContext.create(tmps));
        assertEquals("1", map.get("id"));
        assertEquals("nutz", map.get("name"));
View Full Code Here

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

        /*
         * 默认不忽略空文件
 
View Full Code Here

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

        /*
         * 文件超大,会限制
 
View Full Code Here

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

        /*
         * 文件超大,会限制
 
View Full Code Here

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

        /*
         * 文件超大,会限制
 
View Full Code Here

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

        /*
         * 文件超大,会限制
 
View Full Code Here

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

        String val = "sfsafsa<> ' \" & -- / \\ | $@sdsdsdsaaaaaaaaaaaaaa";
        /*
         * 准备请求对象
         */
        MockHttpServletRequest req = Mock.servlet.request();
        MultipartInputStream ins = Mock.servlet.insmulti("GBK");
        ins.append("abc", val);
        req.setInputStream(ins);
        req.init();
        /*
         * 执行上传
         */
        Uploading up = UploadUnit.TYPE.born();
        Map<String, Object> map = up.parse(req,
                                           UploadingContext.create(tmps)
                                                           .setCharset("GBK"));
        /*
         * 检查以下是不是 GBK 编码被解析成功
         */
        assertEquals(val, map.get("abc"));

        /*
         * 另一段字符串
         */
        val = "<p>$%&amp;&amp;*(^?jyjmy?876&amp;%4</p>";
        /*
         * 准备请求对象
         */
        ins = Mock.servlet.insmulti("GBK");
        ins.append("abc", val);
        req.setInputStream(ins);
        req.init();
        /*
         * 执行上传
         */
 
View Full Code Here

    public void test_upload_multi_item_in_GBK() throws UploadException {
        /*
         * 准备请求对象
         */
        MockHttpServletRequest req = Mock.servlet.request();
        MultipartInputStream ins = Mock.servlet.insmulti("GBK");
        ins.append("abc", "程序员s");
        req.setInputStream(ins);
        req.init();
        /*
         * 执行上传
         */
 
View Full Code Here

TOP

Related Classes of org.nutz.mock.servlet.multipart.MultipartInputStream

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.