Search in sources :

Example 6 with MockHttpServletRequest

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

the class ObjectNavlPairInjectorTest method testMapParam.

@SuppressWarnings("unchecked")
@Test
public void testMapParam() throws NoSuchFieldException {
    //准备数据
    MockHttpServletRequest req = Mock.servlet.request();
    req.setParameter("maps(abc).str", "a");
    req.setParameter("maps(1).str", "b");
    req.setParameter("maps(jk).str", "c");
    req.setParameter("maps.jk.maps.nutz.str", "k");
    //执行
    ObjectNavlPairInjector onpi = inj("maps", NutType.map(String.class, MvcTestPojo.class));
    Map<String, MvcTestPojo> pojo = (Map<String, MvcTestPojo>) onpi.get(null, req, null, null);
    assertEquals(pojo.get("abc").str, "a");
    assertEquals(pojo.get("1").str, "b");
    assertEquals(pojo.get("jk").str, "c");
    assertEquals(pojo.get("jk").maps.get("nutz").str, "k");
}
Also used : MockHttpServletRequest(org.nutz.mock.servlet.MockHttpServletRequest) Map(java.util.Map) Test(org.junit.Test)

Example 7 with MockHttpServletRequest

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

the class MaplTest method test_complex_prefix.

@Test
public void test_complex_prefix() throws Exception {
    String params = "draw=1&columns%5B0%5D%5Bdata%5D=userId&columns%5B0%5D%5Bname%5D=&columns%5B0%5D%5Bsearchable%5D=true&columns%5B0%5D%5Borderable%5D=true&columns%5B0%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B0%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B1%5D%5Bdata%5D=loginname&columns%5B1%5D%5Bname%5D=&columns%5B1%5D%5Bsearchable%5D=true&columns%5B1%5D%5Borderable%5D=true&columns%5B1%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B1%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B2%5D%5Bdata%5D=nickname&columns%5B2%5D%5Bname%5D=&columns%5B2%5D%5Bsearchable%5D=true&columns%5B2%5D%5Borderable%5D=true&columns%5B2%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B2%5D%5Bsearch%5D%5Bregex%5D=false&order%5B0%5D%5Bcolumn%5D=0&order%5B0%5D%5Bdir%5D=asc&start=0&length=10&search%5Bvalue%5D=&search%5Bregex%5D=false";
    //String params = "columns%5B0%5D%5Bdata%5D=userId&columns%5B0%5D%5Bname%5D=&columns%5B0%5D%5Bsearchable%5D=true";
    NutMap map = new NutMap();
    for (String kv : params.split("&")) {
        //System.out.println(kv);
        String[] tmp = kv.split("=");
        String key = URLDecoder.decode(tmp[0], "UTF-8");
        String value = URLDecoder.decode(tmp.length > 1 ? tmp[1] : "", "UTF-8");
        map.put(key, value);
    }
    System.out.println(map);
    String prefix = "columns";
    Object refer = map;
    HttpServletRequest req = new MockHttpServletRequest();
    ObjectNaviNode no = new ObjectNaviNode();
    String pre = "";
    if ("".equals(prefix))
        pre = "node.";
    ParamExtractor pe = Params.makeParamExtractor(req, refer);
    for (Object name : pe.keys()) {
        String na = (String) name;
        if (na.startsWith(prefix)) {
            String[] val = pe.extractor(na);
            no.put(pre + na, val);
        }
    }
    Object model = no.get();
    System.out.println(Json.toJson(model));
    Object re = Mapl.maplistToObj(model, NutType.list(DataTableColumn.class));
    System.out.println(Json.toJson(re));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(org.nutz.mock.servlet.MockHttpServletRequest) MockHttpServletRequest(org.nutz.mock.servlet.MockHttpServletRequest) ObjectNaviNode(org.nutz.mvc.adaptor.injector.ObjectNaviNode) ParamExtractor(org.nutz.mvc.adaptor.ParamExtractor) NutMap(org.nutz.lang.util.NutMap) Test(org.junit.Test)

Example 8 with MockHttpServletRequest

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

the class JspViewTest method test_req_path2.

@Test
public void test_req_path2() throws Exception {
    MockHttpServletRequest req = Mock.servlet.fullRequest();
    req.setPathInfo("/abc/bcd.do");
    JspView fv = new JspView("");
    fv.render(req, null, null);
    assertEquals("/WEB-INF/abc/bcd.jsp", req.getDispatcherTarget());
}
Also used : MockHttpServletRequest(org.nutz.mock.servlet.MockHttpServletRequest) Test(org.junit.Test)

Example 9 with MockHttpServletRequest

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

the class JspViewTest method test_dest_path.

@Test
public void test_dest_path() throws Exception {
    MockHttpServletRequest req = Mock.servlet.fullRequest();
    JspView fv = new JspView("/abc/bcd.jsp");
    fv.render(req, null, null);
    assertEquals("/abc/bcd.jsp", req.getDispatcherTarget());
}
Also used : MockHttpServletRequest(org.nutz.mock.servlet.MockHttpServletRequest) Test(org.junit.Test)

Example 10 with MockHttpServletRequest

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

the class JspViewTest method test_name.

@Test
public void test_name() throws Exception {
    MockHttpServletRequest req = Mock.servlet.fullRequest();
    JspView fv = new JspView("abc.bcd");
    fv.render(req, null, null);
    assertEquals("/WEB-INF/abc/bcd.jsp", req.getDispatcherTarget());
}
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