Пример #1
0
  // ----以下测试普通的post数据
  @Test
  public void test普通的post数据() throws Exception {
    String temp =
        "product=mail163&"
            + "savelogin=&"
            + "url=http%3A%2F%2Fmail.163.com%2Ferrorpage%2Ferr_163.htm&"
            + "username=2005081097&"
            + "password=013579";
    String normal_con_type = "application/x-www-form-urlencoded";
    byte[] bytes = temp.getBytes("US-ASCII");
    HttpServletRequest request = new MockHttpServletRequest(bytes, normal_con_type);
    Object o = null;
    o = LazyParser.getParameter(request, "product");
    assertEquals("mail163", (String) o);
    o = LazyParser.getParameter(request, "savelogin");
    assertNull(o);
    o = LazyParser.getParameter(request, "url");
    assertEquals("http://mail.163.com/errorpage/err_163.htm", (String) o);

    List<FileItem> fileItemList = LazyParser.getFileItemsFromRequest(request);
    assertTrue(fileItemList.size() == 0);

    Map map = LazyParser.getParameterMap(request);
    assertEquals(5, map.size());
    assertEquals("mail163", map.get("product"));
    assertEquals("http://mail.163.com/errorpage/err_163.htm", map.get("url"));

    Set<String> paramNames = LazyParser.getParameterNames(request);
    assertEquals(5, paramNames.size());
    assertTrue(paramNames.contains("product"));
    LazyParser.release();
  }
Пример #2
0
 /*
  * 测试getParameterNames
  */
 @Test
 public void testGetParameterNames_正常情况() throws Exception {
   byte[] bytes = content.getBytes("US-ASCII");
   HttpServletRequest request = new MockHttpServletRequest(bytes, CONTENT_TYPE);
   Set<String> paramNames = LazyParser.getParameterNames(request);
   assertEquals(3, paramNames.size());
   assertTrue(
       paramNames.contains("file")
           && paramNames.contains("field")
           && paramNames.contains("multi"));
   LazyParser.release();
 }