MockHttpServletRequest req = Mock.servlet.request();
req.setPathInfo("/nutz/junit/uploading");
File txt = Files.findFile("org/nutz/mvc/upload/files/quick/abc.zdoc");
File empty = Files.findFile("org/nutz/mvc/upload/files/empty.txt");
MultipartInputStream ins = Mock.servlet.insmulti(charset);
ins.append("abc", txt);
ins.append("empty", empty);
req.setInputStream(ins);
req.init();
/*
* 默认不忽略空文件
*/
Uploading up = UploadUnit.TYPE.born();
Map<String, Object> map = up.parse(req, UploadingContext.create(tmps));
assertEquals(2, map.size());
TempFile txt2 = (TempFile) map.get("abc");
TempFile empty2 = (TempFile) map.get("empty");
assertEquals("abc.zdoc", txt2.getMeta().getFileLocalName());
assertTrue(Files.equals(txt, txt2.getFile()));
assertEquals("empty.txt", empty2.getMeta().getFileLocalName());
assertTrue(Files.equals(empty, empty2.getFile()));
/*
* 设置忽略空文件
*/
ins = Mock.servlet.insmulti(charset);
ins.append("abc", txt);
ins.append("empty", empty);
req.setInputStream(ins);
req.init();
up = UploadUnit.TYPE.born();
map = up.parse(req, UploadingContext.create(tmps).setIgnoreNull(true));
assertEquals(1, map.size());