Search in sources :

Example 36 with MockHttpServletRequest

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"));
}
Also used : MockHttpServletRequest(org.nutz.mock.servlet.MockHttpServletRequest) Test(org.junit.Test)

Example 37 with MockHttpServletRequest

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);
}
Also used : MockHttpServletRequest(org.nutz.mock.servlet.MockHttpServletRequest) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 38 with MockHttpServletRequest

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"));
}
Also used : MockHttpServletRequest(org.nutz.mock.servlet.MockHttpServletRequest) Test(org.junit.Test)

Example 39 with MockHttpServletRequest

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"));
}
Also used : MockHttpServletRequest(org.nutz.mock.servlet.MockHttpServletRequest) List(java.util.List) Test(org.junit.Test)

Example 40 with MockHttpServletRequest

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