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
ConstructorsConstructorDescriptionMockMultipartFile(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, waitMethods 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:
getNamein interfaceorg.springframework.web.multipart.MultipartFile
-
getOriginalFilename
- Specified by:
getOriginalFilenamein interfaceorg.springframework.web.multipart.MultipartFile
-
getContentType
- Specified by:
getContentTypein interfaceorg.springframework.web.multipart.MultipartFile
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceorg.springframework.web.multipart.MultipartFile
-
getSize
public long getSize()- Specified by:
getSizein interfaceorg.springframework.web.multipart.MultipartFile
-
getBytes
- Specified by:
getBytesin interfaceorg.springframework.web.multipart.MultipartFile- Throws:
IOException
-
getInputStream
- Specified by:
getInputStreamin interfaceorg.springframework.core.io.InputStreamSource- Specified by:
getInputStreamin interfaceorg.springframework.web.multipart.MultipartFile- Throws:
IOException
-
transferTo
- Specified by:
transferToin interfaceorg.springframework.web.multipart.MultipartFile- Throws:
IOExceptionIllegalStateException
-