1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package wjhk.jupload2.testhelpers;
27
28 import java.io.ByteArrayInputStream;
29 import java.io.File;
30 import java.io.InputStream;
31 import java.util.Date;
32
33 import wjhk.jupload2.exception.JUploadException;
34 import wjhk.jupload2.exception.JUploadIOException;
35 import wjhk.jupload2.filedata.DefaultFileData;
36 import wjhk.jupload2.gui.filepanel.treeview.TreeFileDataNode;
37 import wjhk.jupload2.policies.UploadPolicy;
38 import wjhk.jupload2.upload.AbstractJUploadTestHelper;
39 import wjhk.jupload2.upload.helper.ByteArrayEncoder;
40
41
42
43
44 public class FileDataTestHelper extends DefaultFileData {
45
46 public final static String FILE_CONTENT_PREFIX = "This is the file content for the file number ";
47
48
49 public static String RELATIVE_DIR = File.separator + "files";
50
51
52 public String fileName;
53
54
55
56
57
58 public int fileNumber;
59
60
61 public String fileContent;
62
63
64 public static String FILE_EXTENSION = "txt";
65
66
67 public String md5sum = null;
68
69
70 public String mimeType = "text/plain";
71
72
73 public Date lastModified = new Date();
74
75
76 public boolean preparedForUpload = true;
77
78
79 public boolean uploadFlag = true;
80
81
82
83
84 public FileDataTestHelper(int fileNumber, UploadPolicy uploadPolicy) {
85 super(AbstractJUploadTestHelper.getTestFile(RELATIVE_DIR + File.separator + fileNumber + "." + FILE_EXTENSION),
86 uploadPolicy);
87 this.fileNumber = fileNumber;
88 this.fileName = fileNumber + "." + FILE_EXTENSION;
89 this.fileContent = FILE_CONTENT_PREFIX + fileNumber;
90 }
91
92
93 public void afterUpload() {
94
95 }
96
97
98
99
100
101
102 public void appendFileProperties(ByteArrayEncoder bae, int index) throws JUploadIOException {
103 throw new UnsupportedOperationException(this.getClass()
104 + ".appendFileProperties() is not implemented in tests cases");
105 }
106
107
108
109
110 public void beforeUpload(String root) throws JUploadException {
111
112 }
113
114
115
116
117 public boolean canRead() {
118 return true;
119 }
120
121
122
123
124 public String getDirectory() {
125 return this.file.getParent();
126 }
127
128
129
130
131 public File getFile() {
132 return this.file;
133 }
134
135
136
137
138 public String getFileExtension() {
139 return FILE_EXTENSION;
140 }
141
142
143
144
145 public long getFileLength() {
146 return this.fileContent.length();
147 }
148
149
150
151
152 public String getFileName() {
153 return this.fileName;
154 }
155
156
157
158
159
160 public InputStream getInputStream() throws JUploadException {
161 return new ByteArrayInputStream(this.fileContent.getBytes());
162 }
163
164
165
166
167 public Date getLastModified() {
168 return this.lastModified;
169 }
170
171
172
173
174 public String getMD5() throws JUploadException {
175 return this.md5sum;
176 }
177
178
179
180
181 public String getMimeType() {
182 return this.mimeType;
183 }
184
185
186
187
188 public String getRelativeDir() {
189 return RELATIVE_DIR;
190 }
191
192
193
194
195 public String getAbsolutePath() {
196 return this.file.getAbsolutePath();
197 }
198
199
200
201
202 public long getUploadLength() {
203 return this.fileContent.length();
204 }
205
206
207
208
209 public boolean isPreparedForUpload() {
210 return this.preparedForUpload;
211 }
212
213 public boolean getUploadFlag() {
214 return uploadFlag;
215 }
216
217 public void setUploadFlag(boolean uploadFlag) {
218 this.uploadFlag = uploadFlag;
219 }
220
221 public TreeFileDataNode getTreeFileDataNode() {
222
223 return null;
224 }
225
226 public void setTreeFileDataNode(TreeFileDataNode node) {
227
228
229 }
230
231 }