use of org.nutz.mvc.upload.Uploading in project nutz by nutzam.
the class UploadingUnitTest method test_upload_empty_just_r_n.
/**
* for issue #617
*/
@Test
public void test_upload_empty_just_r_n() throws Exception {
MockHttpServletRequest req = Mock.servlet.request();
req.setPathInfo("/nutz/junit/uploading");
MultipartInputStream ins = Mock.servlet.insmulti(charset);
File f = Files.findFile("org/nutz/mvc/upload/files/_r_n.txt");
ins.append("theF", f);
req.setInputStream(ins);
req.init();
/*
* 默认不忽略空文件
*/
Uploading up = UploadUnit.TYPE.born();
Map<String, Object> map = up.parse(req, UploadingContext.create(tmps));
assertEquals(1, map.size());
TempFile tf = (TempFile) map.get("theF");
assertEquals("_r_n.txt", tf.getSubmittedFileName());
assertTrue(Streams.equals(Streams.fileIn(f), tf.getInputStream()));
}
use of org.nutz.mvc.upload.Uploading in project nutz by nutzam.
the class UploadingUnitTest method test_upload_ignore_null.
/**
* 测试忽略空文件
*/
@Test
public void test_upload_ignore_null() throws Exception {
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.getSubmittedFileName());
assertTrue(Streams.equals(Streams.fileIn(txt), txt2.getInputStream()));
assertEquals("empty.txt", empty2.getSubmittedFileName());
assertTrue(Streams.equals(Streams.fileIn(empty), empty2.getInputStream()));
/*
* 设置忽略空文件
*/
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());
txt2 = (TempFile) map.get("abc");
empty2 = (TempFile) map.get("empty");
assertEquals("abc.zdoc", txt2.getSubmittedFileName());
assertTrue(Streams.equals(Streams.fileIn(txt), txt2.getInputStream()));
assertNull(empty2);
}
use of org.nutz.mvc.upload.Uploading in project nutz by nutzam.
the class UploadingUnitTest method test_upload_1txt_3img.
@Test
public void test_upload_1txt_3img() throws Exception {
MockHttpServletRequest req = Mock.servlet.request();
req.setPathInfo("/nutz/junit/uploading");
File txt = Files.findFile("org/nutz/mvc/upload/files/quick/abc.zdoc");
File red = Files.findFile("org/nutz/mvc/upload/files/quick/red.png");
File blue = Files.findFile("org/nutz/mvc/upload/files/quick/blue.png");
File green = Files.findFile("org/nutz/mvc/upload/files/quick/green.png");
MultipartInputStream ins = Mock.servlet.insmulti(charset);
ins.append("abc", txt);
ins.append("red", red);
ins.append("blue", blue);
ins.append("green", green);
req.setInputStream(ins);
req.init();
Uploading up = UploadUnit.TYPE.born();
Map<String, Object> map = up.parse(req, UploadingContext.create(tmps));
assertEquals(4, map.size());
TempFile txt2 = (TempFile) map.get("abc");
TempFile red2 = (TempFile) map.get("red");
TempFile blue2 = (TempFile) map.get("blue");
TempFile green2 = (TempFile) map.get("green");
assertEquals("abc.zdoc", txt2.getSubmittedFileName());
assertTrue(Streams.equals(Streams.fileIn(txt), txt2.getInputStream()));
assertEquals("red.png", red2.getSubmittedFileName());
assertTrue(Streams.equals(Streams.fileIn(red), red2.getInputStream()));
assertEquals("blue.png", blue2.getSubmittedFileName());
assertTrue(Streams.equals(Streams.fileIn(blue), blue2.getInputStream()));
assertEquals("green.png", green2.getSubmittedFileName());
assertTrue(Streams.equals(Streams.fileIn(green), green2.getInputStream()));
}
use of org.nutz.mvc.upload.Uploading in project nutz by nutzam.
the class UploadingUnitTest method test_upload_onlyQueryString.
@Test
public void test_upload_onlyQueryString() 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);
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(null, map.get("null"));
}
use of org.nutz.mvc.upload.Uploading in project nutz by nutzam.
the class UploadingUnitTest method test_upload_special_char.
/**
* 检查以下特殊字符作为参数
*/
@Test
public void test_upload_special_char() throws UploadException {
String val = "sfsafsa<> ' \" & -- / \\ | $@sdsdsdsaaaaaaaaaaaaaa";
/*
* 准备请求对象
*/
MockHttpServletRequest req = Mock.servlet.request();
MultipartInputStream ins = Mock.servlet.insmulti("GBK");
ins.append("abc", val);
req.setInputStream(ins);
req.init();
/*
* 执行上传
*/
Uploading up = UploadUnit.TYPE.born();
Map<String, Object> map = up.parse(req, UploadingContext.create(tmps).setCharset("GBK"));
/*
* 检查以下是不是 GBK 编码被解析成功
*/
assertEquals(val, map.get("abc"));
/*
* 另一段字符串
*/
val = "<p>$%&&*(^?jyjmy?876&%4</p>";
/*
* 准备请求对象
*/
ins = Mock.servlet.insmulti("GBK");
ins.append("abc", val);
req.setInputStream(ins);
req.init();
/*
* 执行上传
*/
map = up.parse(req, UploadingContext.create(tmps).setCharset("GBK"));
/*
* 检查以下是不是 GBK 编码被解析成功
*/
assertEquals(val, map.get("abc"));
}
Aggregations