Package org.nutz.mock.servlet

Examples of org.nutz.mock.servlet.MockHttpServletRequest


   * 根据 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

    /**
     * 测试限制文件类型:限制文件类型
     */
    @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

    /**
     * 测试限制文件大小:文件超出尺寸,会抛错
     */
    @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

    /**
     * 测试忽略空文件
     */
    @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

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.