use of org.nutz.mock.servlet.MockHttpServletRequest in project nutz by nutzam.
the class UploadingSpeedTest method main.
public static void main(String[] args) {
if (0 == args.length) {
System.err.println("Lack files directory!");
System.exit(0);
}
File dir = Files.findFile(args[0]);
if (null == dir) {
System.err.println("Fail to found directory: " + args[0]);
System.exit(0);
}
final Uploading up = UploadUnit.TYPE.born();
final UploadingContext uc = UploadingContext.create("~/nutz/unit/uploadtmp");
File[] files = dir.listFiles();
final MockHttpServletRequest req = request().setInputStream(insmulti("UTF-8", files));
req.setSession(session(context()));
req.init();
Object monLock = new Object();
int monInterval = 2000;
UploadMonitor mon = new UploadMonitor(monLock, req.getSession(), out, monInterval);
Thread monThread = new Thread(mon, "UploadingMonitor");
monThread.start();
out.println("Begin...");
Stopwatch sw = null;
try {
sw = Stopwatch.run(new Atom() {
public void run() {
try {
up.parse(req, uc);
} catch (UploadException e) {
throw Lang.wrapThrow(e);
}
}
});
} catch (Exception e) {
e.printStackTrace();
} finally {
mon.stop();
out.println("\n...Done!");
if (null != sw)
out.println(sw);
}
}
use of org.nutz.mock.servlet.MockHttpServletRequest in project nutz by nutzam.
the class NameInjectorTest method test_blank_param_to_number.
/**
* 根据 Issue 272,如果为空串,原生类型的外覆类应该返回 null
*/
@Test
public void test_blank_param_to_number() {
// 准备数据
MockHttpServletRequest req = Mock.servlet.request();
req.setParameter("a", " ");
req.setParameter("b", " ");
// 执行 & 检测
assertNull(inj("a", Long.class, req));
assertEquals(0, (int) inj("b", int.class, req));
}
use of org.nutz.mock.servlet.MockHttpServletRequest in project nutz by nutzam.
the class NameInjectorTest method test_normal_int.
@Test
public void test_normal_int() {
// 准备数据
MockHttpServletRequest req = Mock.servlet.request();
req.setParameter("abc", "1");
// 执行 & 检测
assertEquals(Integer.valueOf(1), inj("abc", int.class, req));
}
use of org.nutz.mock.servlet.MockHttpServletRequest in project nutz by nutzam.
the class ObjectNavlPairInjectorTest method test_array_to_string.
@Test
public void test_array_to_string() {
// 准备数据
MockHttpServletRequest req = Mock.servlet.request();
req.setParameterValues("pojo.str", Lang.array("A", "B", "C"));
// 执行
MvcTestPojo pojo = (MvcTestPojo) inj().get(null, req, null, null);
// 检测
assertEquals("A,B,C", pojo.str);
}
use of org.nutz.mock.servlet.MockHttpServletRequest in project nutz by nutzam.
the class ObjectNavlPairInjectorTest method test_duplicated_name_params.
/**
* 这个测试将检验在 HTTP 请求中,如果存在多个参数同名的情况,本注入器能否正确处理
*/
@Test
public void test_duplicated_name_params() {
// 准备数据
MockHttpServletRequest req = Mock.servlet.request();
req.setParameter("pojo.num", 23);
req.setParameterValues("pojo.names", Lang.array("A", "B", "C"));
// 执行
MvcTestPojo pojo = (MvcTestPojo) inj().get(null, req, null, null);
// 检测
assertNull(pojo.longValue);
assertEquals(23, pojo.num);
assertEquals(3, pojo.names.length);
assertEquals("A", pojo.names[0]);
assertEquals("B", pojo.names[1]);
assertEquals("C", pojo.names[2]);
}
Aggregations