01: /*
02: * Copyright 2002-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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;
20: import java.util.Iterator;
21: import java.util.Map;
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
41: implements MultipartActionRequest {
42:
43: private final Map multipartFiles = CollectionFactory
44: .createLinkedMapIfPossible(4);
45:
46: /**
47: * Add a file to this request. The parameter name from the multipart
48: * form is taken from the {@link org.springframework.web.multipart.MultipartFile#getName()}.
49: * @param file multipart file to be added
50: */
51: public void addFile(MultipartFile file) {
52: Assert.notNull(file, "MultipartFile must not be null");
53: this .multipartFiles.put(file.getName(), file);
54: }
55:
56: public Iterator getFileNames() {
57: return getFileMap().keySet().iterator();
58: }
59:
60: public MultipartFile getFile(String name) {
61: return (MultipartFile) this .multipartFiles.get(name);
62: }
63:
64: public Map getFileMap() {
65: return Collections.unmodifiableMap(this.multipartFiles);
66: }
67:
68: }
|