Search in sources :

Example 41 with MockHttpServletRequest

use of org.nutz.mock.servlet.MockHttpServletRequest in project nutz by nutzam.

the class ObjectNavlPairInjectorTest method test_string_to_string.

@Test
public void test_string_to_string() {
    // 准备数据
    MockHttpServletRequest req = Mock.servlet.request();
    req.setParameterValues("pojo.str", Lang.array("A"));
    // 执行
    MvcTestPojo pojo = (MvcTestPojo) inj().get(null, req, null, null);
    // 检测
    assertEquals("A", pojo.str);
}
Also used : MockHttpServletRequest(org.nutz.mock.servlet.MockHttpServletRequest) Test(org.junit.Test)

Example 42 with MockHttpServletRequest

use of org.nutz.mock.servlet.MockHttpServletRequest in project nutz by nutzam.

the class ObjectPairInjectorTest method test_duplicated_name_params.

/**
     * 这个测试将检验在 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);
    // 检测
    assertNull(pojo.longValue);
    assertEquals(23, pojo.num);
    assertEquals(3, pojo.names.length);
    assertEquals("A", pojo.names[0]);
    assertEquals("B", pojo.names[1]);
    assertEquals("C", pojo.names[2]);
}
Also used : MockHttpServletRequest(org.nutz.mock.servlet.MockHttpServletRequest) Test(org.junit.Test)

Example 43 with MockHttpServletRequest

use of org.nutz.mock.servlet.MockHttpServletRequest in project nutz by nutzam.

the class ObjectPairInjectorTest method test_balnk_param_to_number.

/**
     * 根据 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);
    // 检测
    assertNull(pojo.longValue);
    assertEquals(0, pojo.num);
}
Also used : MockHttpServletRequest(org.nutz.mock.servlet.MockHttpServletRequest) Test(org.junit.Test)

Aggregations

MockHttpServletRequest (org.nutz.mock.servlet.MockHttpServletRequest)43 Test (org.junit.Test)42 Uploading (org.nutz.mvc.upload.Uploading)14 MultipartInputStream (org.nutz.mock.servlet.multipart.MultipartInputStream)11 File (java.io.File)9 TempFile (org.nutz.mvc.upload.TempFile)8 ParamInjector (org.nutz.mvc.adaptor.ParamInjector)3 SimpleDateFormat (java.text.SimpleDateFormat)2 List (java.util.List)1 Map (java.util.Map)1 ServletInputStream (javax.servlet.ServletInputStream)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Stopwatch (org.nutz.lang.Stopwatch)1 NutMap (org.nutz.lang.util.NutMap)1 ParamExtractor (org.nutz.mvc.adaptor.ParamExtractor)1 ObjectNaviNode (org.nutz.mvc.adaptor.injector.ObjectNaviNode)1 Atom (org.nutz.trans.Atom)1