Search in sources :

Example 26 with MockHttpServletRequest

use of org.nutz.mock.servlet.MockHttpServletRequest 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)

Example 27 with MockHttpServletRequest

use of org.nutz.mock.servlet.MockHttpServletRequest 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());
}
Also used : ServletInputStream(javax.servlet.ServletInputStream) MockHttpServletRequest(org.nutz.mock.servlet.MockHttpServletRequest) Uploading(org.nutz.mvc.upload.Uploading) Test(org.junit.Test)

Example 28 with MockHttpServletRequest

use of org.nutz.mock.servlet.MockHttpServletRequest in project nutz by nutzam.

the class JspViewTest method test_req_path.

@Test
public void test_req_path() throws Exception {
    MockHttpServletRequest req = Mock.servlet.fullRequest();
    req.setPathInfo("/abc/bcd.do");
    JspView fv = new JspView(null);
    fv.render(req, null, null);
    assertEquals("/WEB-INF/abc/bcd.jsp", req.getDispatcherTarget());
}
Also used : MockHttpServletRequest(org.nutz.mock.servlet.MockHttpServletRequest) Test(org.junit.Test)

Example 29 with MockHttpServletRequest

use of org.nutz.mock.servlet.MockHttpServletRequest in project nutz by nutzam.

the class JspViewTest method test_req_path3.

@Test
public void test_req_path3() throws Exception {
    MockHttpServletRequest req = Mock.servlet.fullRequest();
    req.setPathInfo("/abc/bcd.do");
    JspView fv = new JspView("  \r\n\t  ");
    fv.render(req, null, null);
    assertEquals("/WEB-INF/abc/bcd.jsp", req.getDispatcherTarget());
}
Also used : MockHttpServletRequest(org.nutz.mock.servlet.MockHttpServletRequest) Test(org.junit.Test)

Example 30 with MockHttpServletRequest

use of org.nutz.mock.servlet.MockHttpServletRequest in project nutz by nutzam.

the class ArrayInjectorTest method test_array_no_split.

/**
     * for issue #816
     */
@Test
public void test_array_no_split() {
    // 准备数据
    MockHttpServletRequest req = Mock.servlet.request();
    req.setParameterValues("abc", Lang.array("A,B"));
    // 执行
    ParamInjector pi = inj("abc", String[].class, false);
    Object obj = pi.get(null, req, null, null);
    // 检测
    assertEquals(String[].class, obj.getClass());
    String[] ss = (String[]) obj;
    assertEquals(1, ss.length);
    assertEquals("A,B", ss[0]);
}
Also used : ParamInjector(org.nutz.mvc.adaptor.ParamInjector) MockHttpServletRequest(org.nutz.mock.servlet.MockHttpServletRequest) Test(org.junit.Test)

Aggregations

MockHttpServletRequest (org.nutz.mock.servlet.MockHttpServletRequest)43 Test (org.junit.Test)42 Uploading (org.nutz.mvc.upload.Uploading)14 MultipartInputStream (org.nutz.mock.servlet.multipart.MultipartInputStream)11 File (java.io.File)9 TempFile (org.nutz.mvc.upload.TempFile)8 ParamInjector (org.nutz.mvc.adaptor.ParamInjector)3 SimpleDateFormat (java.text.SimpleDateFormat)2 List (java.util.List)1 Map (java.util.Map)1 ServletInputStream (javax.servlet.ServletInputStream)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Stopwatch (org.nutz.lang.Stopwatch)1 NutMap (org.nutz.lang.util.NutMap)1 ParamExtractor (org.nutz.mvc.adaptor.ParamExtractor)1 ObjectNaviNode (org.nutz.mvc.adaptor.injector.ObjectNaviNode)1 Atom (org.nutz.trans.Atom)1