Exemplo n.º 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();
  }
Exemplo n.º 2
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();
  }