Package org.springframework.mock.web
Class MockMultipartFile
java.lang.Object
org.springframework.mock.web.MockMultipartFile
- All Implemented Interfaces:
org.springframework.core.io.InputStreamSource
,org.springframework.web.multipart.MultipartFile
public class MockMultipartFile
extends Object
implements org.springframework.web.multipart.MultipartFile
Mock implementation of the
MultipartFile
interface.
Useful in conjunction with a MockMultipartHttpServletRequest
for testing application controllers that access multipart uploads.
- Since:
- 2.0
- Author:
- Juergen Hoeller, Eric Crampton
- See Also:
-
Constructor Summary
ConstructorDescriptionMockMultipartFile
(String name, byte[] content) Create a new MockMultipartFile with the given content.MockMultipartFile
(String name, InputStream contentStream) Create a new MockMultipartFile with the given content.MockMultipartFile
(String name, String originalFilename, String contentType, byte[] content) Create a new MockMultipartFile with the given content.MockMultipartFile
(String name, String originalFilename, String contentType, InputStream contentStream) Create a new MockMultipartFile with the given content. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.web.multipart.MultipartFile
getResource, transferTo
-
Constructor Details
-
MockMultipartFile
Create a new MockMultipartFile with the given content.- Parameters:
name
- the name of the filecontent
- the content of the file
-
MockMultipartFile
Create a new MockMultipartFile with the given content.- Parameters:
name
- the name of the filecontentStream
- the content of the file as stream- Throws:
IOException
- if reading from the stream failed
-
MockMultipartFile
public MockMultipartFile(String name, @Nullable String originalFilename, @Nullable String contentType, @Nullable byte[] content) Create a new MockMultipartFile with the given content.- Parameters:
name
- the name of the fileoriginalFilename
- the original filename (as on the client's machine)contentType
- the content type (if known)content
- the content of the file
-
MockMultipartFile
public MockMultipartFile(String name, @Nullable String originalFilename, @Nullable String contentType, InputStream contentStream) throws IOException Create a new MockMultipartFile with the given content.- Parameters:
name
- the name of the fileoriginalFilename
- the original filename (as on the client's machine)contentType
- the content type (if known)contentStream
- the content of the file as stream- Throws:
IOException
- if reading from the stream failed
-
-
Method Details
-
getName
- Specified by:
getName
in interfaceorg.springframework.web.multipart.MultipartFile
-
getOriginalFilename
- Specified by:
getOriginalFilename
in interfaceorg.springframework.web.multipart.MultipartFile
-
getContentType
- Specified by:
getContentType
in interfaceorg.springframework.web.multipart.MultipartFile
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceorg.springframework.web.multipart.MultipartFile
-
getSize
public long getSize()- Specified by:
getSize
in interfaceorg.springframework.web.multipart.MultipartFile
-
getBytes
- Specified by:
getBytes
in interfaceorg.springframework.web.multipart.MultipartFile
- Throws:
IOException
-
getInputStream
- Specified by:
getInputStream
in interfaceorg.springframework.core.io.InputStreamSource
- Specified by:
getInputStream
in interfaceorg.springframework.web.multipart.MultipartFile
- Throws:
IOException
-
transferTo
- Specified by:
transferTo
in interfaceorg.springframework.web.multipart.MultipartFile
- Throws:
IOException
IllegalStateException
-