1 package wjhk.jupload2.testhelpers;
2
3 import java.awt.Cursor;
4 import java.awt.dnd.DropTargetDropEvent;
5 import java.io.File;
6 import java.text.SimpleDateFormat;
7 import java.util.Locale;
8
9 import javax.swing.Icon;
10 import javax.swing.JButton;
11 import javax.swing.JLabel;
12 import javax.swing.JOptionPane;
13 import javax.swing.JPanel;
14 import javax.swing.JProgressBar;
15
16 import org.apache.log4j.Logger;
17
18 import wjhk.jupload2.context.JUploadContext;
19 import wjhk.jupload2.exception.JUploadException;
20 import wjhk.jupload2.exception.JUploadExceptionStopAddingFiles;
21 import wjhk.jupload2.exception.JUploadIOException;
22 import wjhk.jupload2.filedata.DefaultFileData;
23 import wjhk.jupload2.filedata.FileData;
24 import wjhk.jupload2.gui.JUploadFileChooser;
25 import wjhk.jupload2.gui.JUploadPanel;
26 import wjhk.jupload2.gui.filepanel.FilePanel.FileListViewMode;
27 import wjhk.jupload2.policies.UploadPolicy;
28 import wjhk.jupload2.upload.helper.ByteArrayEncoder;
29 import wjhk.jupload2.upload.helper.InteractiveTrustManager;
30
31
32
33
34
35
36 public class UploadPolicyTestHelper implements UploadPolicy {
37
38 protected final Logger logger = Logger.getLogger(getClass());
39
40
41 public JUploadContext uploadContext = null;
42
43
44 public long maxFileSize;
45
46
47 public String lastMsgReceived = null;
48
49
50
51
52
53
54 public UploadPolicyTestHelper(JUploadPanel juploadPanel) {
55 this.uploadContext = new JUploadContextTestHelper(this, juploadPanel);
56
57 this.maxFileSize = this.uploadContext.getParameter(PROP_MAX_FILE_SIZE, DEFAULT_MAX_FILE_SIZE);
58 }
59
60
61 public void start() {
62 }
63
64
65
66
67 public void addComponentsToJUploadPanel(JUploadPanel jUploadPanel) {
68 displayWarn("UnsupportedOperationException: addComponentsToJUploadPanel() is not implemented in tests cases");
69
70 }
71
72
73
74
75 public void addHeader(String header) {
76 this.logger.warn(this.getClass() + ".addHeader() is not implemented in tests cases");
77
78 }
79
80
81
82
83 public void afterFileDropped(DropTargetDropEvent dropEvent) {
84 this.logger.warn(this.getClass() + ".afterFileDropped() is not implemented in tests cases");
85
86 }
87
88
89
90
91 public void afterUpload(Exception e, String serverOutput) throws JUploadException {
92 this.logger.warn(this.getClass() + ".afterUpload() is not implemented in tests cases");
93
94 }
95
96
97
98
99 public void alert(String key) {
100 this.logger.warn(this.getClass() + ".alert() is not implemented in tests cases");
101
102 }
103
104
105
106
107 public void alertStr(String str) {
108 this.logger.warn(this.getClass() + ".alertStr() is not implemented in tests cases");
109
110 }
111
112
113
114
115 public boolean beforeUpload() {
116 this.logger.warn(this.getClass() + ".beforeUpload() is not implemented in tests cases");
117 return true;
118 }
119
120
121
122
123 public boolean checkUploadSuccess(int status, String msg, String body) throws JUploadException {
124 this.logger.warn(this.getClass() + ".checkUploadSuccess() is not implemented in tests cases");
125 return true;
126 }
127
128
129
130
131 public int confirmDialogStr(String str, int optionTypes) {
132 this.logger.warn(this.getClass() + ".confirmDialogStr() is not implemented in tests cases");
133 return JOptionPane.OK_OPTION;
134 }
135
136
137
138
139 public JUploadFileChooser createFileChooser() {
140 this.logger.warn(this.getClass() + ".createFileChooser() is not implemented in tests cases");
141 return null;
142 }
143
144
145
146
147 public FileData createFileData(File file) throws JUploadExceptionStopAddingFiles {
148 return new DefaultFileData(file, this);
149 }
150
151
152
153
154
155 public JPanel createProgressPanel(JProgressBar preparationProgressBar, JProgressBar uploadProgressBar,
156 JButton uploadButton, JButton stopButton, JUploadPanel mainPanel) {
157 this.logger.warn(this.getClass() + ".createProgressPanel() is not implemented in tests cases");
158 return null;
159 }
160
161
162
163
164 public JPanel createStatusBar(JLabel statusContent, JUploadPanel mainPanel) {
165 this.logger.warn(this.getClass() + ".createStatusBar() is not implemented in tests cases");
166 return null;
167 }
168
169
170
171
172
173 public JPanel createTopPanel(JButton browse, JButton remove, JButton removeAll, JUploadPanel mainPanel) {
174 this.logger.warn(this.getClass() + ".createTopPanel() is not implemented in tests cases");
175 return null;
176 }
177
178
179
180
181 public void displayDebug(String debug, int minDebugLevel) {
182 this.lastMsgReceived = debug;
183 this.logger.debug(debug);
184 }
185
186 void displayMsg(String msg) {
187 this.lastMsgReceived = msg;
188 this.logger.info(msg);
189 }
190
191
192
193
194 public void displayErr(Exception e) {
195 this.lastMsgReceived = null;
196 this.logger.error(e.getClass().getName() + ": " + e.getMessage());
197 }
198
199
200
201
202 public int displayErr(String err, Exception e, int optionType) {
203 this.lastMsgReceived = err;
204 this.logger.error("[ERROR] " + e.getClass().getName() + ": " + e.getMessage() + " [" + err + "]");
205 return JOptionPane.OK_OPTION;
206 }
207
208
209
210
211 public void displayErr(String err) {
212 this.lastMsgReceived = err;
213 this.logger.error("[ERROR] " + err);
214 }
215
216
217
218
219 public void displayErr(String err, Exception e) {
220 this.lastMsgReceived = err;
221 this.logger.error("[ERROR] " + e.getClass().getName() + ": " + e.getMessage() + " [" + err + "]");
222 }
223
224
225
226
227 public void displayInfo(String info) {
228 this.lastMsgReceived = info;
229 this.logger.info("[INFO] " + info);
230 }
231
232
233
234
235 public void displayParameterStatus() {
236 this.logger.warn(this.getClass() + ".displayParameterStatus() is not implemented in tests cases");
237 }
238
239
240
241
242 public void displayWarn(String warn) {
243 this.lastMsgReceived = warn;
244 displayMsg("[WARNING] " + warn);
245 }
246
247
248
249
250 public boolean fileFilterAccept(File file) {
251 this.logger.warn(this.getClass() + ".fileFilterAccept() is not implemented in tests cases");
252 return true;
253 }
254
255
256
257
258 public String fileFilterGetDescription() {
259 this.logger.warn(this.getClass() + ".fileFilterGetDescription() is not implemented in tests cases");
260 return null;
261
262 }
263
264
265
266
267 public Icon fileViewGetIcon(File file) {
268 this.logger.warn(this.getClass() + ".fileViewGetIcon() is not implemented in tests cases");
269 return null;
270 }
271
272
273
274
275 public String getAfterUploadTarget() {
276 return this.uploadContext.getParameter(PROP_AFTER_UPLOAD_TARGET, DEFAULT_AFTER_UPLOAD_TARGET);
277 }
278
279
280
281
282 public String getAfterUploadURL() {
283 return this.uploadContext.getParameter(PROP_AFTER_UPLOAD_URL, DEFAULT_AFTER_UPLOAD_URL);
284 }
285
286
287
288
289 public boolean getAllowHttpPersistent() {
290 return this.uploadContext.getParameter(PROP_ALLOW_HTTP_PERSISTENT, DEFAULT_ALLOW_HTTP_PERSISTENT);
291 }
292
293
294
295
296 public String getAllowedFileExtensions() {
297 return this.uploadContext.getParameter(PROP_ALLOWED_FILE_EXTENSIONS, DEFAULT_ALLOWED_FILE_EXTENSIONS);
298 }
299
300
301
302
303 public JUploadContext getContext() {
304 return this.uploadContext;
305 }
306
307
308
309
310 public File getCurrentBrowsingDirectory() {
311 this.logger.warn(this.getClass() + ".getCurrentBrowsingDirectory() is not implemented in tests cases");
312 return null;
313 }
314
315
316
317
318 public String getDateFormat() {
319 return new SimpleDateFormat().toPattern();
320 }
321
322
323
324
325 public int getDebugLevel() {
326 return this.uploadContext.getParameter(PROP_DEBUG_LEVEL, DEFAULT_DEBUG_LEVEL);
327 }
328
329
330 public String getFileFilterName() {
331 return this.uploadContext.getParameter(PROP_FILE_FILTER_NAME, DEFAULT_FILE_FILTER_NAME);
332 }
333
334
335
336
337 public int getFileChooserIconFromFileContent() {
338 return this.uploadContext.getParameter(PROP_FILE_CHOOSER_ICON_FROM_FILE_CONTENT,
339 DEFAULT_FILE_CHOOSER_ICON_FROM_FILE_CONTENT);
340 }
341
342
343
344
345 public int getFileChooserIconSize() {
346 return this.uploadContext.getParameter(PROP_FILE_CHOOSER_ICON_SIZE, DEFAULT_FILE_CHOOSER_ICON_SIZE);
347 }
348
349
350 public FileListViewMode getFileListViewMode() {
351 return this.uploadContext.getParameter(PROP_FILE_LIST_VIEW_MODE, DEFAULT_FILE_LIST_VIEW_MODE);
352 }
353
354
355
356
357 public String getFilenameEncoding() {
358 return this.uploadContext.getParameter(PROP_FILENAME_ENCODING, DEFAULT_FILENAME_ENCODING);
359 }
360
361
362
363
364 public String getFormdata() {
365 return this.uploadContext.getParameter(PROP_FORMDATA, DEFAULT_FORMDATA);
366 }
367
368
369
370
371 public boolean getFtpCreateDirectoryStructure() {
372 return this.uploadContext.getParameter(PROP_FTP_CREATE_DIRECTORY_STRUCTURE,
373 DEFAULT_FTP_CREATE_DIRECTORY_STRUCTURE);
374 }
375
376
377
378
379 public boolean getFtpTransfertBinary() {
380 return this.uploadContext.getParameter(PROP_FTP_TRANSFERT_BINARY, DEFAULT_FTP_TRANSFERT_BINARY);
381 }
382
383
384
385
386 public boolean getFtpTransfertPassive() {
387 return this.uploadContext.getParameter(PROP_FTP_TRANSFERT_PASSIVE, DEFAULT_FTP_TRANSFERT_PASSIVE);
388 }
389
390
391
392
393 public String getHttpUploadParameterName() {
394 return this.uploadContext.getParameter(PROP_HTTP_UPLOAD_PARAMETER_NAME, DEFAULT_HTTP_UPLOAD_PARAMETER_NAME);
395 }
396
397
398
399
400 public String getHttpUploadParameterType() {
401 return this.uploadContext.getParameter(PROP_HTTP_UPLOAD_PARAMETER_TYPE, DEFAULT_HTTP_UPLOAD_PARAMETER_TYPE);
402 }
403
404
405
406
407 public JUploadException getLastException() {
408 this.logger.warn(this.getClass() + ".getLastException() is not implemented in tests cases");
409 return null;
410 }
411
412
413
414
415 public String getLastResponseBody() {
416 this.logger.warn(this.getClass() + ".getLastResponseBody() is not implemented in tests cases");
417 return null;
418 }
419
420
421
422
423 public String getLastResponseMessage() {
424 this.logger.warn(this.getClass() + ".getLastResponseMessage() is not implemented in tests cases");
425 return null;
426 }
427
428
429 public Locale getLocale() {
430 return Locale.getDefault();
431 }
432
433
434
435
436 public String getLocalizedString(String key, Object... args) {
437 if (key.equals("dateformat")) {
438 return "MM/dd/yyyy";
439 } else {
440 return key;
441 }
442 }
443
444
445
446
447 public long getMaxChunkSize() {
448 return this.uploadContext.getParameter(PROP_MAX_CHUNK_SIZE, DEFAULT_MAX_CHUNK_SIZE);
449 }
450
451
452
453
454 public long getMaxFileSize() {
455 return this.maxFileSize;
456 }
457
458
459
460
461 public int getNbFilesPerRequest() {
462 return this.uploadContext.getParameter(PROP_NB_FILES_PER_REQUEST, DEFAULT_NB_FILES_PER_REQUEST);
463 }
464
465
466
467
468 public String getPostURL() {
469 return this.uploadContext.getParameter(PROP_POST_URL, DEFAULT_POST_URL);
470 }
471
472
473
474
475 public boolean getReadCookieFromNavigator() {
476 return this.uploadContext.getParameter(PROP_READ_COOKIE_FROM_NAVIGATOR, DEFAULT_READ_COOKIE_FROM_NAVIGATOR);
477 }
478
479
480
481
482 public boolean getReadUserAgentFromNavigator() {
483 return this.uploadContext.getParameter(PROP_READ_USER_AGENT_FROM_NAVIGATOR,
484 DEFAULT_READ_USER_AGENT_FROM_NAVIGATOR);
485 }
486
487
488
489
490 public String getServerProtocol() {
491 return this.uploadContext.getParameter(PROP_SERVER_PROTOCOL, DEFAULT_SERVER_PROTOCOL);
492 }
493
494
495
496
497 public String getShowLogWindow() {
498 return this.uploadContext.getParameter(PROP_SHOW_LOGWINDOW, DEFAULT_SHOW_LOGWINDOW);
499 }
500
501
502
503
504 public String getSpecificHeaders() {
505 return this.uploadContext.getParameter(PROP_SPECIFIC_HEADERS, DEFAULT_SPECIFIC_HEADERS);
506 }
507
508
509
510
511 public int getSslVerifyCert() {
512 final String sslVerifyCert = this.uploadContext.getParameter(PROP_SSL_VERIFY_CERT, DEFAULT_SSL_VERIFY_CERT);
513 if (sslVerifyCert.toLowerCase().equals("none")) {
514 return InteractiveTrustManager.NONE;
515 } else if (sslVerifyCert.toLowerCase().equals("server")) {
516 return InteractiveTrustManager.SERVER;
517 } else if (sslVerifyCert.toLowerCase().equals("client")) {
518 return InteractiveTrustManager.CLIENT;
519 } else if (sslVerifyCert.toLowerCase().equals("strict")) {
520 return InteractiveTrustManager.STRICT;
521 } else {
522 this.logger.warn("Invalid parameter sslVerifyCert (" + sslVerifyCert + ")");
523 return InteractiveTrustManager.NONE;
524 }
525 }
526
527
528
529
530 public String getStringUploadError() {
531 return this.uploadContext.getParameter(PROP_STRING_UPLOAD_ERROR, DEFAULT_STRING_UPLOAD_ERROR);
532 }
533
534
535
536
537 public String getStringUploadSuccess() {
538 return this.uploadContext.getParameter(PROP_STRING_UPLOAD_SUCCESS, DEFAULT_STRING_UPLOAD_SUCCESS);
539 }
540
541
542
543
544 public String getStringUploadWarning() {
545 return this.uploadContext.getParameter(PROP_STRING_UPLOAD_WARNING, DEFAULT_STRING_UPLOAD_WARNING);
546 }
547
548
549
550
551 public String getUploadFilename(final FileData fileData, final int index) throws JUploadException {
552 this.logger.warn(this.getClass() + ".getUploadFilename() is not implemented in tests cases");
553 return null;
554 }
555
556
557
558
559 public String getUploadName(final FileData fileData, final int index) throws JUploadException {
560 this.logger.warn(this.getClass() + ".getUploadName() is not implemented in tests cases");
561 return null;
562 }
563
564
565
566
567 public String getUrlToSendErrorTo() {
568 return this.uploadContext.getParameter(PROP_URL_TO_SEND_ERROR_TO, DEFAULT_URL_TO_SEND_ERROR_TO);
569 }
570
571
572
573
574 public ByteArrayEncoder onAppendHeader(final ByteArrayEncoder sb) throws JUploadIOException {
575 this.logger.warn(this.getClass() + ".onAppendHeader() is not implemented in tests cases");
576 return null;
577 }
578
579
580
581
582 public void onFileDoubleClicked(FileData fileData) {
583 this.logger.warn(this.getClass() + ".onFileDoubleClicked() is not implemented in tests cases");
584 }
585
586
587
588
589 public void onFileSelected(FileData fileData) {
590 this.logger.warn(this.getClass() + ".onFileSelected() is not implemented in tests cases");
591 }
592
593
594
595
596 public void sendDebugInformation(String reason, Exception exception) {
597 this.logger.warn(this.getClass() + ".sendDebugInformation() is not implemented in tests cases");
598 }
599
600
601
602
603 public void setCurrentBrowsingDirectory(File currentBrowsingDirectoryParam) {
604 this.logger.warn(this.getClass() + ".setCurrentBrowsingDirectory() is not implemented in tests cases");
605 }
606
607
608
609
610 public void setCurrentBrowsingDirectory(String currentBrowsingDirectoryParam) {
611 this.logger.warn(this.getClass() + ".setCurrentBrowsingDirectory() is not implemented in tests cases");
612 }
613
614
615
616
617 public Cursor setCursor(Cursor cursor) {
618 this.logger.warn(this.getClass() + ".setCursor() is not implemented in tests cases");
619 return null;
620 }
621
622
623
624
625 public void setDebugLevel(int debugLevel) {
626 this.logger.warn(this.getClass() + ".setDebugLevel() is not implemented in tests cases");
627 }
628
629
630
631
632 public void setLang(String lang) {
633 this.logger.warn(this.getClass() + ".setLang() is not implemented in tests cases");
634 }
635
636
637
638
639 public void setPostURL(String postURL) throws JUploadException {
640 this.logger.warn(this.getClass() + ".setPostURL() is not implemented in tests cases");
641 }
642
643
644
645
646 public void setProperty(String prop, String value) throws JUploadException {
647 System.setProperty(prop, value);
648 }
649
650
651
652
653 public void setShowLogWindow(String showLogWindow) {
654 this.logger.warn(this.getClass() + ".setShowLogWindow() is not implemented in tests cases");
655 }
656
657
658
659
660 public void setUrlToSendErrorTo(String urlToSendErrorTo) throws JUploadException {
661 this.logger.warn(this.getClass() + ".setUrlToSendErrorTo() is not implemented in tests cases");
662 }
663
664
665
666
667 public Cursor setWaitCursor() {
668 this.logger.warn(this.getClass() + ".setWaitCursor() is not implemented in tests cases");
669 return null;
670 }
671
672
673 public boolean getSendMD5Sum() {
674 this.logger.warn(this.getClass() + ".getSendMD5Sum() is not implemented in tests cases");
675 return false;
676 }
677
678
679 public void setSendMD5Sum(boolean sendMD5Sum) {
680 this.logger.warn(this.getClass() + ".setSendMD5Sum() is not implemented in tests cases");
681 }
682
683
684
685
686 public void setServerProtocol(String serverProtocol) {
687 this.logger.warn(this.getClass() + ".setServerProtocol() is not implemented in tests cases");
688 }
689
690
691 public int getRetryMaxNumberOf() {
692 this.logger.warn(this.getClass() + ".getRetryMaxNumberOf() is not implemented in tests cases");
693 return 0;
694 }
695
696
697 public int getRetryNbSecondsBetween() {
698 this.logger.warn(this.getClass() + ".getRetryNbSecondsBetween() is not implemented in tests cases");
699 return 0;
700 }
701
702
703
704
705 public void updateButtonState(int executionStatus) {
706
707 }
708
709 public void setFileListViewMode(FileListViewMode fileListViewMode) {
710
711
712 }
713
714 }