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