spring-test

org.springframework.mock.web
Class MockMultipartFile

java.lang.Object
  extended by org.springframework.mock.web.MockMultipartFile
All Implemented Interfaces:
org.springframework.web.multipart.MultipartFile

public class MockMultipartFile
extends java.lang.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:
MockMultipartHttpServletRequest

Constructor Summary
MockMultipartFile(java.lang.String name, byte[] content)
          Create a new MockMultipartFile with the given content.
MockMultipartFile(java.lang.String name, java.io.InputStream contentStream)
          Create a new MockMultipartFile with the given content.
MockMultipartFile(java.lang.String name, java.lang.String originalFilename, java.lang.String contentType, byte[] content)
          Create a new MockMultipartFile with the given content.
MockMultipartFile(java.lang.String name, java.lang.String originalFilename, java.lang.String contentType, java.io.InputStream contentStream)
          Create a new MockMultipartFile with the given content.
 
Method Summary
 byte[] getBytes()
           
 java.lang.String getContentType()
           
 java.io.InputStream getInputStream()
           
 java.lang.String getName()
           
 java.lang.String getOriginalFilename()
           
 long getSize()
           
 boolean isEmpty()
           
 void transferTo(java.io.File dest)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MockMultipartFile

public MockMultipartFile(java.lang.String name,
                         byte[] content)
Create a new MockMultipartFile with the given content.

Parameters:
name - the name of the file
content - the content of the file

MockMultipartFile

public MockMultipartFile(java.lang.String name,
                         java.io.InputStream contentStream)
                  throws java.io.IOException
Create a new MockMultipartFile with the given content.

Parameters:
name - the name of the file
contentStream - the content of the file as stream
Throws:
java.io.IOException - if reading from the stream failed

MockMultipartFile

public MockMultipartFile(java.lang.String name,
                         java.lang.String originalFilename,
                         java.lang.String contentType,
                         byte[] content)
Create a new MockMultipartFile with the given content.

Parameters:
name - the name of the file
originalFilename - the original filename (as on the client's machine)
contentType - the content type (if known)
content - the content of the file

MockMultipartFile

public MockMultipartFile(java.lang.String name,
                         java.lang.String originalFilename,
                         java.lang.String contentType,
                         java.io.InputStream contentStream)
                  throws java.io.IOException
Create a new MockMultipartFile with the given content.

Parameters:
name - the name of the file
originalFilename - the original filename (as on the client's machine)
contentType - the content type (if known)
contentStream - the content of the file as stream
Throws:
java.io.IOException - if reading from the stream failed
Method Detail

getName

public java.lang.String getName()
Specified by:
getName in interface org.springframework.web.multipart.MultipartFile

getOriginalFilename

public java.lang.String getOriginalFilename()
Specified by:
getOriginalFilename in interface org.springframework.web.multipart.MultipartFile

getContentType

public java.lang.String getContentType()
Specified by:
getContentType in interface org.springframework.web.multipart.MultipartFile

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface org.springframework.web.multipart.MultipartFile

getSize

public long getSize()
Specified by:
getSize in interface org.springframework.web.multipart.MultipartFile

getBytes

public byte[] getBytes()
                throws java.io.IOException
Specified by:
getBytes in interface org.springframework.web.multipart.MultipartFile
Throws:
java.io.IOException

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Specified by:
getInputStream in interface org.springframework.web.multipart.MultipartFile
Throws:
java.io.IOException

transferTo

public void transferTo(java.io.File dest)
                throws java.io.IOException,
                       java.lang.IllegalStateException
Specified by:
transferTo in interface org.springframework.web.multipart.MultipartFile
Throws:
java.io.IOException
java.lang.IllegalStateException

spring-test