originalRequest.setMethod("POST");
originalRequest.setContentType("multipart/form-data");
originalRequest.addHeader("Content-type", "multipart/form-data");
originalRequest.addParameter("getField", "getValue");
assertTrue(resolver.isMultipart(originalRequest));
MultipartHttpServletRequest request = resolver.resolveMultipart(originalRequest);
Set parameterNames = new HashSet();
Enumeration parameterEnum = request.getParameterNames();
while (parameterEnum.hasMoreElements()) {
parameterNames.add(parameterEnum.nextElement());
}
assertEquals(3, parameterNames.size());
assertTrue(parameterNames.contains("field3"));
assertTrue(parameterNames.contains("field4"));
assertTrue(parameterNames.contains("getField"));
assertEquals("value3", request.getParameter("field3"));
List parameterValues = Arrays.asList(request.getParameterValues("field3"));
assertEquals(1, parameterValues.size());
assertTrue(parameterValues.contains("value3"));
assertEquals("value4", request.getParameter("field4"));
parameterValues = Arrays.asList(request.getParameterValues("field4"));
assertEquals(2, parameterValues.size());
assertTrue(parameterValues.contains("value4"));
assertTrue(parameterValues.contains("value5"));
assertEquals("value4", request.getParameter("field4"));
assertEquals("getValue", request.getParameter("getField"));
List parameterMapKeys = new ArrayList();
List parameterMapValues = new ArrayList();
for (Iterator parameterMapIter = request.getParameterMap().keySet().iterator(); parameterMapIter.hasNext();) {
String key = (String) parameterMapIter.next();
parameterMapKeys.add(key);
parameterMapValues.add(request.getParameterMap().get(key));
}
assertEquals(3, parameterMapKeys.size());
assertEquals(3, parameterMapValues.size());
int field3Index = parameterMapKeys.indexOf("field3");
int field4Index = parameterMapKeys.indexOf("field4");
int getFieldIndex = parameterMapKeys.indexOf("getField");
assertTrue(field3Index != -1);
assertTrue(field4Index != -1);
assertTrue(getFieldIndex != -1);
parameterValues = Arrays.asList((String[]) parameterMapValues.get(field3Index));
assertEquals(1, parameterValues.size());
assertTrue(parameterValues.contains("value3"));
parameterValues = Arrays.asList((String[]) parameterMapValues.get(field4Index));
assertEquals(2, parameterValues.size());
assertTrue(parameterValues.contains("value4"));
assertTrue(parameterValues.contains("value5"));
parameterValues = Arrays.asList((String[]) parameterMapValues.get(getFieldIndex));
assertEquals(1, parameterValues.size());
assertTrue(parameterValues.contains("getValue"));
Set fileNames = new HashSet();
Iterator fileIter = request.getFileNames();
while (fileIter.hasNext()) {
fileNames.add(fileIter.next());
}
assertEquals(3, fileNames.size());
assertTrue(fileNames.contains("field1"));
assertTrue(fileNames.contains("field2"));
assertTrue(fileNames.contains("field2x"));
CommonsMultipartFile file1 = (CommonsMultipartFile) request.getFile("field1");
CommonsMultipartFile file2 = (CommonsMultipartFile) request.getFile("field2");
CommonsMultipartFile file2x = (CommonsMultipartFile) request.getFile("field2x");
Map fileMap = request.getFileMap();
assertEquals(3, fileMap.size());
assertTrue(fileMap.containsKey("field1"));
assertTrue(fileMap.containsKey("field2"));
assertTrue(fileMap.containsKey("field2x"));
assertEquals(file1, fileMap.get("field1"));