示例#1
1
  /*
   * 测试getParameterMap
   */
  @Test
  public void testGetParameterMap_正常情况() throws Exception {
    byte[] bytes = content.getBytes("US-ASCII");
    HttpServletRequest request = new MockHttpServletRequest(bytes, CONTENT_TYPE);
    Map map = LazyParser.getParameterMap(request);
    // assertEquals("4",map.size()); //FIXME
    // 在form表单中的field重复的情况下,也应该能返回重复的表单数据
    FileItem f = (FileItem) map.get("file");
    assertEquals("This is the content of the file\n", new String(f.getBout().toByteArray()));
    assertEquals("text/whatever", f.getContentType());
    assertEquals("foo.tab", f.getFileName());

    f = (FileItem) map.get("field");
    assertEquals("fieldValue", f.getValue());

    f = (FileItem) map.get("multi");
    assertEquals("value1", f.getValue());
    LazyParser.release();
  }
示例#2
0
 /*
  * 测试getFileItemsFromRequest
  */
 @Test
 public void testGetFileItemFromRequest_正常情况() throws Exception {
   byte[] bytes = content.getBytes("US-ASCII");
   HttpServletRequest request = new MockHttpServletRequest(bytes, CONTENT_TYPE);
   List<FileItem> fileItem = LazyParser.getFileItemsFromRequest(request);
   assertEquals(1, fileItem.size());
   FileItem f = fileItem.get(0);
   assertEquals("This is the content of the file\n", new String(f.getBout().toByteArray()));
   assertEquals("text/whatever", f.getContentType());
   assertEquals("foo.tab", f.getFileName());
   LazyParser.release();
 }
示例#3
0
  /** 测试getParameter的正常情况 */
  @Test
  public void testGetParameter_正常情况_上传文件() throws Exception {
    byte[] bytes = content.getBytes("US-ASCII");
    HttpServletRequest request = new MockHttpServletRequest(bytes, CONTENT_TYPE);
    // 文件域
    Object o = LazyParser.getParameter(request, "file");
    assertTrue(o instanceof FileItem);
    FileItem f = (FileItem) o;
    assertEquals("This is the content of the file\n", new String(f.getBout().toByteArray()));
    assertEquals("text/whatever", f.getContentType());
    assertEquals("foo.tab", f.getFileName());
    // 普通域
    o = LazyParser.getParameter(request, "field");
    assertTrue(o instanceof FileItem);
    f = (FileItem) o;
    assertEquals("fieldValue", f.getValue());

    LazyParser.release();
  }