use of org.nutz.mock.servlet.MockHttpServletRequest in project nutz by nutzam.
the class ObjectNavlPairInjectorTest method testArray.
@Test
public void testArray() throws NoSuchFieldException {
//准备数据
MockHttpServletRequest req = Mock.servlet.request();
req.setParameter("arrays[1].str", "a");
ObjectNavlPairInjector onpi = inj("arrays", NutType.array(MvcTestPojo.class));
//执行
MvcTestPojo[] pojo = (MvcTestPojo[]) onpi.get(null, req, null, null);
assertTrue(pojo[0].str.contains("a"));
}
use of org.nutz.mock.servlet.MockHttpServletRequest in project nutz by nutzam.
the class ObjectNavlPairInjectorTest method test_date.
@Test
public void test_date() {
// 准备数据
MockHttpServletRequest req = Mock.servlet.request();
req.setParameter("pojo.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("pojo.date", "");
// 执行
MvcTestPojo pojoNull = (MvcTestPojo) inj().get(null, req, null, null);
assertEquals(null, pojoNull.date);
}
use of org.nutz.mock.servlet.MockHttpServletRequest in project nutz by nutzam.
the class ObjectNavlPairInjectorTest method testList.
@Test
public void testList() {
//准备数据
MockHttpServletRequest req = Mock.servlet.request();
req.setParameter("pojo.books[1]", "a");
req.setParameter("pojo.books[ads]", "b");
req.setParameter("pojo.books[3]", "c");
//执行
MvcTestPojo pojo = (MvcTestPojo) inj().get(null, req, null, null);
assertTrue(pojo.books.contains("a"));
assertTrue(pojo.books.contains("b"));
assertTrue(pojo.books.contains("c"));
}
use of org.nutz.mock.servlet.MockHttpServletRequest in project nutz by nutzam.
the class ObjectNavlPairInjectorTest method testListParam.
@SuppressWarnings("unchecked")
@Test
public void testListParam() throws NoSuchFieldException {
//准备数据
MockHttpServletRequest req = Mock.servlet.request();
req.setParameter("lists[1].str", "a");
ObjectNavlPairInjector onpi = inj("lists", NutType.list(MvcTestPojo.class));
//执行
List<MvcTestPojo> pojo = (List<MvcTestPojo>) onpi.get(null, req, null, null);
assertTrue(pojo.get(0).str.contains("a"));
}
use of org.nutz.mock.servlet.MockHttpServletRequest in project nutz by nutzam.
the class ObjectNavlPairInjectorTest method testSet.
@Test
public void testSet() {
//准备数据
MockHttpServletRequest req = Mock.servlet.request();
req.setParameter("pojo.sets[jk].str", "c");
req.setParameter("pojo.sets[jk].maps(nutz).str", "k");
//执行
MvcTestPojo pojo = (MvcTestPojo) inj().get(null, req, null, null);
for (MvcTestPojo m : pojo.sets) {
assertEquals(m.str, "c");
assertEquals(m.maps.get("nutz").str, "k");
}
}
Aggregations