Updated Branches:
  refs/heads/master af890025e -> 3bf98ca71

WICKET-5074 Improvement for MockHttpServletRequest and FormTester to support 
'multiple' input type of fileUpload


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/3bf98ca7
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/3bf98ca7
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/3bf98ca7

Branch: refs/heads/master
Commit: 3bf98ca71ee72088920a37292ac301815991521f
Parents: af89002
Author: Martin Tzvetanov Grigorov <[email protected]>
Authored: Tue Mar 12 14:42:52 2013 +0100
Committer: Martin Tzvetanov Grigorov <[email protected]>
Committed: Tue Mar 12 14:42:52 2013 +0100

----------------------------------------------------------------------
 .../protocol/http/mock/MockHttpServletRequest.java |   62 +++++++++------
 1 files changed, 36 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/3bf98ca7/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/MockHttpServletRequest.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/MockHttpServletRequest.java
 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/MockHttpServletRequest.java
index b760093..8c1a123 100755
--- 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/MockHttpServletRequest.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/MockHttpServletRequest.java
@@ -175,7 +175,7 @@ public class MockHttpServletRequest implements 
HttpServletRequest
 
        private String url;
 
-       private Map<String, UploadedFile> uploadedFiles;
+       private Map<String, List<UploadedFile>> uploadedFiles;
 
        private boolean useMultiPartContentType;
 
@@ -264,12 +264,19 @@ public class MockHttpServletRequest implements 
HttpServletRequest
 
                if (uploadedFiles == null)
                {
-                       uploadedFiles = new HashMap<String, UploadedFile>();
+                       uploadedFiles = new HashMap<String, 
List<UploadedFile>>();
                }
 
                UploadedFile uf = new UploadedFile(fieldName, file, 
contentType);
 
-               uploadedFiles.put(fieldName, uf);
+               List<UploadedFile> filesPerField = uploadedFiles.get(fieldName);
+               if (filesPerField == null)
+               {
+                       filesPerField = new ArrayList<UploadedFile>();
+                       uploadedFiles.put(fieldName, filesPerField);
+               }
+
+               filesPerField.add(uf);
                setUseMultiPartContentType(true);
        }
 
@@ -1642,32 +1649,35 @@ public class MockHttpServletRequest implements 
HttpServletRequest
                        {
                                for (String fieldName : uploadedFiles.keySet())
                                {
-                                       UploadedFile uf = 
uploadedFiles.get(fieldName);
-
-                                       newAttachment(out);
-                                       out.write("; name=\"".getBytes());
-                                       out.write(fieldName.getBytes());
-                                       out.write("\"; filename=\"".getBytes());
-                                       
out.write(uf.getFile().getName().getBytes());
-                                       out.write("\"".getBytes());
-                                       out.write(crlf.getBytes());
-                                       out.write("Content-Type: ".getBytes());
-                                       
out.write(uf.getContentType().getBytes());
-                                       out.write(crlf.getBytes());
-                                       out.write(crlf.getBytes());
-
-                                       // Load the file and put it into the 
the inputstream
-                                       FileInputStream fis = new 
FileInputStream(uf.getFile());
+                                       List<UploadedFile> files = 
uploadedFiles.get(fieldName);
 
-                                       try
+                                       for (UploadedFile uf : files)
                                        {
-                                               IOUtils.copy(fis, out);
+                                               newAttachment(out);
+                                               out.write("; 
name=\"".getBytes());
+                                               out.write(fieldName.getBytes());
+                                               out.write("\"; 
filename=\"".getBytes());
+                                               
out.write(uf.getFile().getName().getBytes());
+                                               out.write("\"".getBytes());
+                                               out.write(crlf.getBytes());
+                                               out.write("Content-Type: 
".getBytes());
+                                               
out.write(uf.getContentType().getBytes());
+                                               out.write(crlf.getBytes());
+                                               out.write(crlf.getBytes());
+
+                                               // Load the file and put it 
into the the inputstream
+                                               FileInputStream fis = new 
FileInputStream(uf.getFile());
+
+                                               try
+                                               {
+                                                       IOUtils.copy(fis, out);
+                                               }
+                                               finally
+                                               {
+                                                       fis.close();
+                                               }
+                                               out.write(crlf.getBytes());
                                        }
-                                       finally
-                                       {
-                                               fis.close();
-                                       }
-                                       out.write(crlf.getBytes());
                                }
                        }
 

Reply via email to