Package org.nutz.mock.servlet

Examples of org.nutz.mock.servlet.MockHttpServletRequest


    public static MockServletConfig config(String s) {
      return new MockServletConfig(context(), s);
    }

    public static MockHttpServletRequest request() {
      return new MockHttpServletRequest();
    }
View Full Code Here


    public static MockHttpServletRequest request() {
      return new MockHttpServletRequest();
    }

    public static MockHttpServletRequest fullRequest() {
      MockHttpServletRequest req = request();
      req.setSession(session(context()));
      return req;
    }
View Full Code Here

   * 根据 Issue 272,如果为空串,原生类型的外覆类应该返回 null
   */
  @Test
  public void test_balnk_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.