Package org.nutz.mock.servlet

Examples of org.nutz.mock.servlet.MockHttpServletRequest


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

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


    public void test_upload_special_char() throws UploadException {
        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();
        /*
         * 执行上传
         */
        map = up.parse(req, UploadingContext.create(tmps).setCharset("GBK"));
        /*
 
View Full Code Here

     * 根据 Issue 272,如果为空串,原生类型的外覆类应该返回 null
     */
    @Test
    public void test_blank_param_to_number() {
        // 准备数据
        MockHttpServletRequest req = Mock.servlet.request();
        req.setParameter("a", "  ");
        req.setParameter("b", "  ");

        // 执行 & 检测
        assertNull(inj("a", Long.class, req));
        assertEquals(0, (int) inj("b", int.class, req));
    }
View Full Code Here

    }

    @Test
    public void test_duplicate_name() {
        // 准备数据
        MockHttpServletRequest req = Mock.servlet.request();
        req.setParameterValues("abc", Lang.array("1", "2", "3"));

        // 执行 & 检测
        String[] ss = inj("abc", String[].class, req);
        assertEquals(3, ss.length);
        assertEquals("1", ss[0]);
View Full Code Here

    }

    @Test
    public void test_normal_int() {
        // 准备数据
        MockHttpServletRequest req = Mock.servlet.request();
        req.setParameter("abc", "1");

        // 执行 & 检测
        assertEquals(Integer.valueOf(1), inj("abc", int.class, req));
    }
View Full Code Here

     * 根据 Issue 272,如果为空串,原生类型的外覆类应该返回 null
     */
    @Test
    public void test_balnk_param_to_number() {
        // 准备数据
        MockHttpServletRequest req = Mock.servlet.request();
        req.setParameter("longValue", "  ");
        req.setParameter("num", "  ");

        // 执行
        MvcTestPojo pojo = (MvcTestPojo) inj().get(null, req, null, null);

        // 检测
View Full Code Here

     * 这个测试将检验在 HTTP 请求中,如果存在多个参数同名的情况,本注入器能否正确处理
     */
    @Test
    public void test_duplicated_name_params() {
        // 准备数据
        MockHttpServletRequest req = Mock.servlet.request();
        req.setParameter("num", 23);
        req.setParameterValues("names", Lang.array("A", "B", "C"));

        // 执行
        MvcTestPojo pojo = (MvcTestPojo) inj().get(null, req, null, null);

        // 检测
View Full Code Here

    }

    @Test
    public void test_array_to_string() {
        // 准备数据
        MockHttpServletRequest req = Mock.servlet.request();
        req.setParameterValues("str", Lang.array("A", "B", "C"));

        // 执行
        MvcTestPojo pojo = (MvcTestPojo) inj().get(null, req, null, null);

        // 检测
View Full Code Here

    }

    @Test
    public void test_string_to_string() {
        // 准备数据
        MockHttpServletRequest req = Mock.servlet.request();
        req.setParameterValues("str", Lang.array("A"));

        // 执行
        MvcTestPojo pojo = (MvcTestPojo) inj().get(null, req, null, null);

        // 检测
View Full Code Here

    }
   
    @Test
    public void test_date(){
        // 准备数据
        MockHttpServletRequest req = Mock.servlet.request();
        req.setParameter("date", "2010-01-01");
        // 执行
        MvcTestPojo pojo = (MvcTestPojo) inj().get(null, req, null, null);
       
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        System.out.println(sdf.format(pojo.date));
        assertEquals("2010-01-01", sdf.format(pojo.date));
       
        req.setParameter("date", "");
        // 执行
        MvcTestPojo pojoNull = (MvcTestPojo) inj().get(null, req, null, null);
       
        assertEquals(null, pojoNull.date);
    }
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.