/* * 测试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(); }
// ----以下测试普通的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(); }