use of org.nutz.mock.servlet.MockHttpServletRequest in project nutz by nutzam.
the class ObjectPairInjectorTest method test_date.
@Test
public void test_date() {
// 准备数据
MockHttpServletRequest req = Mock.servlet.request();
req.setParameter("date", "2010-01-01");
// 执行
MvcTestPojo pojo = (MvcTestPojo) inj().get(null, req, null, null);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
System.out.println(sdf.format(pojo.date));
assertEquals("2010-01-01", sdf.format(pojo.date));
req.setParameter("date", "");
// 执行
MvcTestPojo pojoNull = (MvcTestPojo) inj().get(null, req, null, null);
assertEquals(null, pojoNull.date);
}
use of org.nutz.mock.servlet.MockHttpServletRequest in project nutz by nutzam.
the class ObjectPairInjectorTest method test_string_to_string.
@Test
public void test_string_to_string() {
// 准备数据
MockHttpServletRequest req = Mock.servlet.request();
req.setParameterValues("str", Lang.array("A"));
// 执行
MvcTestPojo pojo = (MvcTestPojo) inj().get(null, req, null, null);
// 检测
assertEquals("A", pojo.str);
}
use of org.nutz.mock.servlet.MockHttpServletRequest in project nutz by nutzam.
the class ObjectPairInjectorTest method test_array_to_string.
@Test
public void test_array_to_string() {
// 准备数据
MockHttpServletRequest req = Mock.servlet.request();
req.setParameterValues("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 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.MockHttpServletRequest in project nutz by nutzam.
the class UploadingUnitTest method test_upload_chinese_filename.
/**
* @author lAndRaxeE(landraxee@gmail.com)
*/
@Test
public void test_upload_chinese_filename() throws UploadException {
/*
* 准备模拟对象
*/
MockHttpServletRequest req = Mock.servlet.request();
File txt = Files.findFile("org/nutz/mvc/upload/files/quick/中文.txt");
/*
* 如果模拟上传时request使用 GBK 编码,用 GBK 来解码,应该会生成正确的文件名
*/
req.setInputStream(Mock.servlet.insmulti("GBK", txt)).init();
Uploading up = UploadUnit.TYPE.born();
TempFile txt2 = (TempFile) up.parse(req, UploadingContext.create(tmps).setCharset("GBK")).get("F0");
// 测试本地的默认编码是否是GBK,即模拟中文环境,本人环境为中文Windows XP
// 在JVM参数中增加-Dfile.encoding=GBK即可设置好
// assertEquals("GBK", Charset.defaultCharset().name());
//
// zzh: JUnit 测试必须在多数常用环境下可以比较方便的测试通过,经过这次修改,相信
// 即可以达到这个目的,又可以测试出中文文件名的编码问题。如果没有其他的问题,在
// 1.a.30 发布前,这段注释将被删除
assertEquals("中文.txt", txt2.getSubmittedFileName());
/*
* 为了验证上传是否是真的可以解码,再次准备模拟 GBK 的输入流,但是这次将用 UTF-8 来解码
*/
req.setInputStream(Mock.servlet.insmulti("GBK", txt)).init();
up = UploadUnit.TYPE.born();
txt2 = (TempFile) up.parse(req, UploadingContext.create(tmps)).get("F0");
assertFalse("中文.txt".equals(txt2.getSubmittedFileName()));
}
Aggregations