1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.kuali.rice.kew.test.web;
17  
18  import java.io.File;
19  import java.io.FileInputStream;
20  import java.io.FileNotFoundException;
21  import java.io.IOException;
22  import java.io.InputStream;
23  
24  import org.apache.struts.upload.FormFile;
25  import org.springframework.util.FileCopyUtils;
26  
27  
28  
29  
30  
31  public class MockFormFile implements FormFile {
32      private File file;
33      private String fileName;
34      private int fileSize;
35      private String contentType = "application/octet-stream";
36  
37      public MockFormFile(File file) {
38          this.file = file;
39          this.fileName = file.getName();
40          this.fileSize = (int) file.length();
41      }
42  
43      public String getContentType() {
44          return contentType;
45      }
46  
47      public void setContentType(String contentType) {
48          this.contentType = contentType;
49      }
50  
51      public byte[] getFileData() throws FileNotFoundException, IOException {
52          return FileCopyUtils.copyToByteArray(file);
53      }
54  
55      public String getFileName() {
56          return fileName;
57      }
58  
59      public void setFileName(String fileName) {
60          this.fileName = fileName;
61      }
62  
63      public int getFileSize() {
64          return fileSize;
65      }
66  
67      public void setFileSize(int fileSize) {
68          this.fileSize = fileSize;
69      }
70  
71      public InputStream getInputStream() throws FileNotFoundException, IOException {
72          return new FileInputStream(file);
73      }
74  
75      public void destroy() {
76      }
77  
78      public String toString() {
79          return "[MockFormFile: " + file + "]";
80      }
81  }