Search in sources :

Example 11 with MultipartInputStream

use of org.nutz.mock.servlet.multipart.MultipartInputStream 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$"));
}
Also used : MockHttpServletRequest(org.nutz.mock.servlet.MockHttpServletRequest) Uploading(org.nutz.mvc.upload.Uploading) TempFile(org.nutz.mvc.upload.TempFile) File(java.io.File) MultipartInputStream(org.nutz.mock.servlet.multipart.MultipartInputStream) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)11 MockHttpServletRequest (org.nutz.mock.servlet.MockHttpServletRequest)11 MultipartInputStream (org.nutz.mock.servlet.multipart.MultipartInputStream)11 Uploading (org.nutz.mvc.upload.Uploading)11 File (java.io.File)7 TempFile (org.nutz.mvc.upload.TempFile)7