KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > mock > web > portlet > MockMultipartActionRequest


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.mock.web.portlet;
18
19 import java.util.Collections JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.Map JavaDoc;
22
23 import org.springframework.core.CollectionFactory;
24 import org.springframework.util.Assert;
25 import org.springframework.web.multipart.MultipartFile;
26 import org.springframework.web.portlet.multipart.MultipartActionRequest;
27
28 /**
29  * Mock implementation of the
30  * {@link org.springframework.web.portlet.multipart.MultipartActionRequest} interface.
31  *
32  * <p>Useful for testing application controllers that access multipart uploads.
33  * The {@link org.springframework.mock.web.MockMultipartFile} can be used to
34  * populate these mock requests with files.
35  *
36  * @author Juergen Hoeller
37  * @since 2.0
38  * @see org.springframework.mock.web.MockMultipartFile
39  */

40 public class MockMultipartActionRequest extends MockActionRequest implements MultipartActionRequest {
41
42     private final Map JavaDoc multipartFiles = CollectionFactory.createLinkedMapIfPossible(4);
43
44
45     /**
46      * Add a file to this request. The parameter name from the multipart
47      * form is taken from the {@link org.springframework.web.multipart.MultipartFile#getName()}.
48      * @param file multipart file to be added
49      */

50     public void addFile(MultipartFile file) {
51         Assert.notNull(file, "MultipartFile must not be null");
52         this.multipartFiles.put(file.getName(), file);
53     }
54
55     public Iterator JavaDoc getFileNames() {
56         return getFileMap().keySet().iterator();
57     }
58
59     public MultipartFile getFile(String JavaDoc name) {
60         return (MultipartFile) this.multipartFiles.get(name);
61     }
62
63     public Map JavaDoc getFileMap() {
64         return Collections.unmodifiableMap(this.multipartFiles);
65     }
66
67 }
68
Popular Tags