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]);
}
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]);
}
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]);
}
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);
}
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");
}
Aggregations