Search in sources :

Example 31 with MockHttpServletRequest

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

the class ArrayInjectorTest method test_array_auto_split.

/**
     * for issue #816
     */
@Test
public void test_array_auto_split() {
    // 准备数据
    MockHttpServletRequest req = Mock.servlet.request();
    req.setParameterValues("abc", Lang.array("A,B"));
    // 执行
    ParamInjector pi = inj("abc", String[].class, true);
    Object obj = pi.get(null, req, null, null);
    // 检测
    assertEquals(String[].class, obj.getClass());
    String[] ss = (String[]) obj;
    assertEquals(2, ss.length);
    assertEquals("A", ss[0]);
    assertEquals("B", ss[1]);
}
Also used : ParamInjector(org.nutz.mvc.adaptor.ParamInjector) MockHttpServletRequest(org.nutz.mock.servlet.MockHttpServletRequest) Test(org.junit.Test)

Example 32 with MockHttpServletRequest

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

the class ArrayInjectorTest method test_array_no_split2.

/**
     * for issue #816
     */
@Test
public void test_array_no_split2() {
    // 准备数据
    MockHttpServletRequest req = Mock.servlet.request();
    req.setParameterValues("abc", Lang.array("A,B", "X,Y"));
    // 执行
    ParamInjector pi = inj("abc", String[].class, false);
    Object obj = pi.get(null, req, null, null);
    // 检测
    assertEquals(String[].class, obj.getClass());
    String[] ss = (String[]) obj;
    assertEquals(2, ss.length);
    assertEquals("A,B", ss[0]);
    assertEquals("X,Y", ss[1]);
}
Also used : ParamInjector(org.nutz.mvc.adaptor.ParamInjector) MockHttpServletRequest(org.nutz.mock.servlet.MockHttpServletRequest) Test(org.junit.Test)

Example 33 with MockHttpServletRequest

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

the class NameInjectorTest method test_duplicate_name.

@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]);
    assertEquals("2", ss[1]);
    assertEquals("3", ss[2]);
}
Also used : MockHttpServletRequest(org.nutz.mock.servlet.MockHttpServletRequest) Test(org.junit.Test)

Example 34 with MockHttpServletRequest

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

the class ObjectNavlPairInjectorTest method test_balnk_param_to_number.

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

Example 35 with MockHttpServletRequest

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

the class ObjectNavlPairInjectorTest method testMap.

@Test
public void testMap() {
    //准备数据
    MockHttpServletRequest req = Mock.servlet.request();
    req.setParameter("pojo.maps(abc).str", "a");
    req.setParameter("pojo.maps(1).str", "b");
    req.setParameter("pojo.maps(jk).str", "c");
    req.setParameter("pojo.maps(jk).maps.nutz.str", "k");
    //执行
    MvcTestPojo pojo = (MvcTestPojo) inj().get(null, req, null, null);
    assertEquals(pojo.maps.get("abc").str, "a");
    assertEquals(pojo.maps.get("1").str, "b");
    assertEquals(pojo.maps.get("jk").str, "c");
    assertEquals(pojo.maps.get("jk").maps.get("nutz").str, "k");
}
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