1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.fileupload.portlet;
18
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertTrue;
21
22 import java.util.List;
23 import java.util.Map;
24
25 import javax.portlet.ActionRequest;
26
27 import org.apache.commons.fileupload.Constants;
28 import org.apache.commons.fileupload.FileItem;
29 import org.apache.commons.fileupload.FileUploadTest;
30 import org.apache.commons.fileupload.disk.DiskFileItemFactory;
31 import org.junit.Before;
32 import org.junit.Test;
33
34
35
36
37
38
39
40 public class PortletFileUploadTest {
41
42 private PortletFileUpload upload;
43
44 @Before
45 public void setUp() {
46 upload = new PortletFileUpload(new DiskFileItemFactory());
47 }
48
49 @Test
50 public void parseParameterMap()
51 throws Exception {
52 String text = "-----1234\r\n" +
53 "Content-Disposition: form-data; name=\"file\"; filename=\"foo.tab\"\r\n" +
54 "Content-Type: text/whatever\r\n" +
55 "\r\n" +
56 "This is the content of the file\n" +
57 "\r\n" +
58 "-----1234\r\n" +
59 "Content-Disposition: form-data; name=\"field\"\r\n" +
60 "\r\n" +
61 "fieldValue\r\n" +
62 "-----1234\r\n" +
63 "Content-Disposition: form-data; name=\"multi\"\r\n" +
64 "\r\n" +
65 "value1\r\n" +
66 "-----1234\r\n" +
67 "Content-Disposition: form-data; name=\"multi\"\r\n" +
68 "\r\n" +
69 "value2\r\n" +
70 "-----1234--\r\n";
71 byte[] bytes = text.getBytes("US-ASCII");
72 ActionRequest request = new MockPortletActionRequest(bytes, Constants.CONTENT_TYPE);
73
74 Map<String, List<FileItem>> mappedParameters = upload.parseParameterMap(request);
75 assertTrue(mappedParameters.containsKey("file"));
76 assertEquals(1, mappedParameters.get("file").size());
77
78 assertTrue(mappedParameters.containsKey("field"));
79 assertEquals(1, mappedParameters.get("field").size());
80
81 assertTrue(mappedParameters.containsKey("multi"));
82 assertEquals(2, mappedParameters.get("multi").size());
83 }
84
85 }