I have a junit test method that takes a CommonsMultipartFile object as a parameter.
I'm trying to create a FileItem object so I can pass it to the constructor,
CommonsMultipartFile(org.apache.commons.fileupload.FileItem fileItem)
To do that, I'm trying to create the FileItem object using the DiskFileItem constructor,
DiskFileItem(java.lang.String fieldName, java.lang.String contentType, boolean isFormField, java.lang.String fileName, int sizeThreshold, java.io.File repository)
but I'm not sure how to pass any of those parameters.
I have all of this working in a Spring 3 MVC controller, but to do my junit tests, I need to pass a method two objects. One is the UploadItem object which looks like the following,
import org.springframework.web.multipart.commons.CommonsMultipartFile;
public class UploadItem {
private String fileName;
private String filePath;
private CommonsMultipartFile fileData;
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getFilePath() {
return filePath;
}
public void setFilePath(String filePath) {
this.filePath = filePath;
}
public CommonsMultipartFile getFileData() {
return fileData;
}
public void setFileData(CommonsMultipartFile fileData) {
this.fileData = fileData;
}
}
The setFileData() method requires the CommonsMultipartFile object which I'm trying to create just given a file in my src/test/resources directory.
Would anyone know how I can take a file, create a FileItem object and pass that to the CommonsMultipartFile object constructor?
Thanks. If anything is unclear, please let me know - I'm not that familiar with Spring MVC file uploads.