use of org.nutz.mvc.upload.Uploading in project nutz by nutzam.
the class UploadingUnitTest method test_upload_multi_item_in_GBK.
/**
* 检查一下普通的非文件数据项是否能被正确解码
*/
@Test
public void test_upload_multi_item_in_GBK() throws UploadException {
/*
* 准备请求对象
*/
MockHttpServletRequest req = Mock.servlet.request();
MultipartInputStream ins = Mock.servlet.insmulti("GBK");
ins.append("abc", "程序员s");
req.setInputStream(ins);
req.init();
/*
* 执行上传
*/
Uploading up = UploadUnit.TYPE.born();
Map<String, Object> map = up.parse(req, UploadingContext.create(tmps).setCharset("GBK"));
/*
* 检查以下是不是 GBK 编码被解析成功
*/
assertEquals("程序员s", map.get("abc"));
}
use of org.nutz.mvc.upload.Uploading in project nutz by nutzam.
the class UploadingUnitTest method test_upload_queryString.
@Test
public void test_upload_queryString() throws UploadException {
MockHttpServletRequest req = Mock.servlet.request();
req.setParameter("id", "1");
req.setParameter("name", "nutz");
Uploading up = UploadUnit.TYPE.born();
MultipartInputStream ins = Mock.servlet.insmulti(charset);
ins.append("age", "1");
req.setInputStream(ins);
req.init();
Map<String, Object> map = up.parse(req, UploadingContext.create(tmps));
assertEquals("1", map.get("id"));
assertEquals("nutz", map.get("name"));
assertEquals("1", map.get("age"));
assertEquals(null, map.get("null"));
}
use of org.nutz.mvc.upload.Uploading in project nutz by nutzam.
the class UploadingUnitTest method test_limit_file_content_type_fail.
/**
* 测试限制文件类型:限制文件类型
*/
@Test(expected = UploadUnsupportedFileTypeException.class)
public void test_limit_file_content_type_fail() throws UploadException {
MockHttpServletRequest req = Mock.servlet.request();
req.setPathInfo("/nutz/junit/uploading");
File blue = Files.findFile("org/nutz/mvc/upload/files/quick/blue.png");
MultipartInputStream ins = Mock.servlet.insmulti(charset);
ins.append("blue", blue);
req.setInputStream(ins);
req.init();
/*
* 文件超大,会限制
*/
Uploading up = UploadUnit.TYPE.born();
up.parse(req, UploadingContext.create(tmps).setContentTypeFilter("^image/gif$"));
}
use of org.nutz.mvc.upload.Uploading in project nutz by nutzam.
the class UploadingUnitTest method test_cast_dt01.
@Test
public void test_cast_dt01() throws UploadException {
MockHttpServletRequest req = Mock.servlet.request();
req.setHeader("content-type", "multipart/form-data; boundary=----ESDT-321271401654cc6d669eef664aac");
Uploading up = UploadUnit.TYPE.born();
ServletInputStream ins = Mock.servlet.ins("org/nutz/mvc/upload/files/cast_dt01");
req.setInputStream(ins);
req.init();
Map<String, Object> map = up.parse(req, UploadingContext.create(tmps));
assertEquals(1, map.size());
assertEquals("Shapes100.jpg", ((TempFile) map.get("fileData")).getSubmittedFileName());
}
Aggregations