use of org.nutz.mock.servlet.multipart.MultipartInputStream in project nutz by nutzam.
the class UploadingUnitTest method test_limit_file_name_fail.
/**
* 测试限制文件名:限制文件名称
*/
@Test(expected = UploadUnsupportedFileNameException.class)
public void test_limit_file_name_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).setNameFilter("^(.+[.])(gif|jpg)$"));
}
use of org.nutz.mock.servlet.multipart.MultipartInputStream in project nutz by nutzam.
the class UploadingUnitTest method test_limit_file_size_ok.
/**
* 测试限制文件大小:文件不超过尺寸,不会会抛错
*/
@Test
public void test_limit_file_size_ok() 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).setBufferSize(1024).setMaxFileSize(19152));
}
use of org.nutz.mock.servlet.multipart.MultipartInputStream in project nutz by nutzam.
the class UploadingUnitTest method test_limit_file_size_fail.
/**
* 测试限制文件大小:文件超出尺寸,会抛错
*/
@Test(expected = UploadOutOfSizeException.class)
public void test_limit_file_size_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();
// 当设置为170,pass
// 设置为171,fail 原因未明
// zzh: FastUploading 的限制不是特别精确
// 因为是按块读取的, 每次循环,要读1-3个块,所以尺寸的限制同 缓冲大小,也会有关系
// 如果缓冲是 171, 可能正好读完
up.parse(req, UploadingContext.create(tmps).setBufferSize(171).setMaxFileSize(18620));
}
use of org.nutz.mock.servlet.multipart.MultipartInputStream 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.mock.servlet.multipart.MultipartInputStream 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"));
}
Aggregations