View Javadoc
1   //
2   // $Id$
3   //
4   // jupload - A file upload applet.
5   //
6   // Copyright 2010 The JUpload Team
7   //
8   // Created: 25 fevr. 2010
9   // Creator: etienne_sf
10  // Last modified: $Date$
11  //
12  // This program is free software; you can redistribute it and/or modify
13  // it under the terms of the GNU General Public License as published by
14  // the Free Software Foundation; either version 2 of the License, or
15  // (at your option) any later version.
16  //
17  // This program is distributed in the hope that it will be useful,
18  // but WITHOUT ANY WARRANTY; without even the implied warranty of
19  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  // GNU General Public License for more details.
21  //
22  // You should have received a copy of the GNU General Public License
23  // along with this program; if not, write to the Free Software
24  // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25  package wjhk.jupload2.filedata;
26  
27  import java.awt.Canvas;
28  import java.awt.Image;
29  import java.awt.image.BufferedImage;
30  import java.io.File;
31  import java.io.FileInputStream;
32  import java.io.IOException;
33  import java.io.InputStream;
34  import java.lang.reflect.InvocationTargetException;
35  
36  import javax.imageio.ImageIO;
37  import javax.swing.ImageIcon;
38  
39  import org.junit.After;
40  import org.junit.Assert;
41  import org.junit.Before;
42  import org.junit.Test;
43  
44  import wjhk.jupload2.exception.JUploadException;
45  import wjhk.jupload2.exception.JUploadIOException;
46  import wjhk.jupload2.policies.PictureUploadPolicy;
47  import wjhk.jupload2.testhelpers.JUploadContextTestHelper;
48  import wjhk.jupload2.upload.AbstractJUploadTestHelper;
49  
50  /**
51   * @author etienne_sf
52   */
53  public class PictureFileDataTest extends AbstractJUploadTestHelper {
54  
55      // The test file root is ./src/test/resources/files
56      private String myFileRoot = AbstractJUploadTestHelper.getTestFilesRootPath();
57  
58      private static String DEFAULT_FILENAME = "test.bmp";
59  
60      private PictureFileData pictureFileData;
61  
62      private File file;
63  
64      private String root;
65  
66      /**
67       * @throws JUploadException
68       */
69      @Before
70      public void setUp() throws JUploadException {
71          setUp(DEFAULT_FILENAME);
72      }
73  
74      /**
75       * Let's construct a test case, for the given filename.
76       * 
77       * @param filename
78       * @throws JUploadException
79       */
80      private void setUp(String filename) throws JUploadException {
81          this.file = new File(this.myFileRoot + filename);
82          this.root = new File(this.myFileRoot).getAbsolutePath();
83  
84          System.setProperty("pictureTransmitMetadata", "true");
85          this.uploadPolicy = new PictureUploadPolicy(this.juploadContext);
86          ((JUploadContextTestHelper) this.juploadContext).uploadPolicy = this.uploadPolicy;
87          this.pictureFileData = new PictureFileData(this.file, (PictureUploadPolicy) this.uploadPolicy);
88      }
89  
90      /**
91       * Erase any system property, which could have been set by the test
92       */
93      @After
94      public void cleanUp() {
95          // Let's clean the execution context, for next tests.
96          System.clearProperty("maxPicWidth");
97          System.clearProperty("maxPicHeight");
98      }
99  
100     /**
101      * @throws JUploadException
102      */
103     @Test
104     public void testConstructor() throws JUploadException {
105         // Default filename: test.bmp
106         Assert.assertTrue("We have a picture, here (attribute)", this.pictureFileData.isPicture);
107         Assert.assertTrue("We have a picture, here (getter)", this.pictureFileData.isPicture());
108 
109         Assert.assertEquals("Check of the filename", DEFAULT_FILENAME, this.pictureFileData.file.getName());
110         Assert.assertEquals("It's a gif, here (mime-type)", "image/bmp", this.pictureFileData.getMimeType());
111 
112         // Test with a non-picture file
113         setUp("level1/ATestFile.txt");
114         Assert.assertFalse("We have a non-picturefile , here (attribute)", this.pictureFileData.isPicture);
115         Assert.assertFalse("We have a non-picturefile , here (attribute)", this.pictureFileData.isPicture());
116 
117         Assert.assertEquals("It's a text, here (mime-type)", JUploadContextTestHelper.TEST_CASE_MIME_TYPE,
118                 this.pictureFileData.getMimeType());
119     }
120 
121     /**
122      * @throws JUploadException
123      */
124     @Test
125     public void testBeforeUpload_noTransformation() throws JUploadException {
126         Assert.assertFalse("The file should not be prepared before the test", this.pictureFileData.preparedForUpload);
127         Assert.assertEquals("Check of the maxWidth", Integer.MAX_VALUE,
128                 ((PictureUploadPolicy) this.uploadPolicy).getMaxWidth());
129         Assert.assertEquals("Check of the maxHeight", Integer.MAX_VALUE,
130                 ((PictureUploadPolicy) this.uploadPolicy).getMaxHeight());
131         this.pictureFileData.beforeUpload(this.root);
132         Assert.assertTrue("The file is now prepared", this.pictureFileData.preparedForUpload);
133 
134         Assert.assertNull("Non transformed file (no transformed file)", this.pictureFileData.transformedPictureFile);
135         Assert.assertNull("Non transformed file (working copy file)", this.pictureFileData.workingCopyTempFile);
136         Assert.assertEquals("Non transformed file (length - attribute)", this.file.length(),
137                 this.pictureFileData.uploadLength);
138         Assert.assertEquals("Non transformed file (length - getter)", this.file.length(),
139                 this.pictureFileData.getUploadLength());
140     }
141 
142     /**
143      * @throws JUploadException
144      */
145     @Test
146     public void testBeforeUpload_oneRotation() throws JUploadException {
147         this.pictureFileData.quarterRotation = 1;
148         this.pictureFileData.beforeUpload(this.root);
149         Assert.assertTrue("The file is now prepared", this.pictureFileData.preparedForUpload);
150 
151         Assert.assertNotNull("File is transformed (there must exist one transformed file)",
152                 this.pictureFileData.transformedPictureFile);
153         Assert.assertNotNull("File is transformed (there must exist one working copy file)",
154                 this.pictureFileData.workingCopyTempFile);
155         // Let's remove the temporary files.
156         this.pictureFileData.afterUpload();
157     }
158 
159     /** */
160     @Test
161     public void testGetUploadLength() {
162         // Already tested in beforeUpload. We just check here the response, when
163         // the file is not prepared.
164         Assert.assertFalse("By default, the file is not prepared", this.pictureFileData.preparedForUpload);
165         try {
166             this.pictureFileData.getUploadLength();
167             Assert.fail("getUploadLength() on non prepared file should raise an exception");
168         } catch (java.lang.IllegalStateException e) {
169             // Success!
170         }
171     }
172 
173     /**
174      * @throws JUploadException
175      * @throws IOException
176      */
177     @Test
178     public void testGetInputStream_nonPreparedFile() throws JUploadException, IOException {
179         try {
180             this.pictureFileData.getInputStream();
181             Assert.fail("getInputStream() should raise an exception when called on a non prepared file");
182         } catch (java.lang.IllegalStateException e) {
183             // Success!
184         }
185     }
186 
187     /**
188      * @throws JUploadException
189      * @throws IOException
190      */
191     @Test
192     public void testGetInputStream_nonTransformedFile() throws JUploadException, IOException {
193         Assert.assertFalse("By default, the file is not prepared", this.pictureFileData.preparedForUpload);
194         this.pictureFileData.beforeUpload(this.root);
195         Assert.assertTrue("Then, the file is not prepared", this.pictureFileData.preparedForUpload);
196 
197         InputStream isTest = this.pictureFileData.getInputStream();
198         InputStream isAssert = new FileInputStream(this.file);
199         int charAssert;
200         int charTest;
201         while ((charAssert = isAssert.read()) >= 0) {
202             charTest = isTest.read();
203             if (charTest < 0) {
204                 isTest.close();
205                 isAssert.close();
206                 Assert.fail("Can't read one byte for the pictureFileData input stream");
207             }
208             Assert.assertEquals("File content should be identical", charAssert, charTest);
209         }
210         charTest = isTest.read();
211         if (charTest >= 0) {
212             isTest.close();
213             isAssert.close();
214             Assert.fail("The pictureFileData input stream should be finished");
215         }
216         isTest.close();
217         isAssert.close();
218     }
219 
220     /**
221      * @throws JUploadException
222      * @throws IOException
223      */
224     @Test
225     public void testGetInputStream_RotatedFile() throws JUploadException, IOException {
226         this.pictureFileData.quarterRotation = 1;
227         this.pictureFileData.beforeUpload(this.root);
228         InputStream isTest = this.pictureFileData.getInputStream();
229         InputStream isAssert = new FileInputStream(this.file);
230         int charAssert;
231         int charTest;
232         while ((charAssert = isAssert.read()) >= 0) {
233             charTest = isTest.read();
234             if (charTest < 0) {
235                 // There is a difference between the two files: the file has
236                 // been transformed. We can't really test more here, so let's
237                 // stop here.
238                 isTest.close();
239                 isAssert.close();
240                 return;
241             }
242             if (charTest != charAssert) {
243                 // There is a difference between the two files: the file has
244                 // been transformed. We can't really test more here, so let's
245                 // stop here.
246                 isTest.close();
247                 isAssert.close();
248                 return;
249             }
250         }// while
251         charTest = isTest.read();
252         if (charTest >= 0) {
253             // There is a difference between the two files: the file has
254             // been transformed. We can't really test more here, so let's
255             // stop here.
256             isTest.close();
257             isAssert.close();
258             return;
259         }
260         isTest.close();
261         isAssert.close();
262 
263         Assert.fail("The files are identifical (although the pictureFileData should have transformed it !");
264     }
265 
266     /**
267      * @throws JUploadException
268      */
269     @Test
270     public void testAfterUpload() throws JUploadException {
271         // We need a transformed picture file.
272         this.pictureFileData.quarterRotation = 1;
273         this.pictureFileData.beforeUpload(this.root);
274         Assert.assertNotNull("The transformed file should exist", this.pictureFileData.transformedPictureFile);
275         Assert.assertNotNull("The transformed file should exist", this.pictureFileData.workingCopyTempFile);
276         this.pictureFileData.afterUpload();
277         Assert.assertNull("The transformed file should now be deleted", this.pictureFileData.transformedPictureFile);
278         Assert.assertNull("The transformed file should now be deleted", this.pictureFileData.workingCopyTempFile);
279     }
280 
281     /**
282      * @throws JUploadException
283      */
284     @Test
285     public void testGetImage() throws JUploadException {
286         try {
287             this.pictureFileData.getImage(null, false);
288             Assert.fail("Canvas null should not be accepted");
289         } catch (JUploadException e) {
290             // Success !
291         }
292 
293         int width = 10;
294         int height = 10;
295         Canvas canvas = new Canvas();
296         canvas.setSize(width, height);
297         Image image = this.pictureFileData.getImage(canvas, false);
298         Assert.assertNull("No cache here: the offscreenImage should remain null", this.pictureFileData.offscreenImage);
299         // The orginal picture is a square: all dimension must be the same as
300         // the canvas's ones.
301         Assert.assertEquals("Width resizing check", width, image.getWidth(null));
302         Assert.assertEquals("Height resizing check", height, image.getHeight(null));
303 
304         // Check shadow management.
305         image = this.pictureFileData.getImage(canvas, true);
306         Assert.assertEquals("The returned image must be the one stored", image, this.pictureFileData.offscreenImage);
307         Assert.assertEquals("The newly returned image must still be the one stored (real image)", image,
308                 this.pictureFileData.getImage(canvas, true));
309     }
310 
311     /**
312      * @throws IOException
313      */
314     @Test
315     public void testAddRotation() throws IOException {
316         this.pictureFileData.offscreenImage = ImageIO.read(this.file);
317         Assert.assertEquals("Default rotation: 0", 0, this.pictureFileData.quarterRotation);
318         Assert.assertNotNull("Default rotation: 0 (offscreen image should not be changed)",
319                 this.pictureFileData.offscreenImage);
320         this.pictureFileData.addRotation(1);
321         Assert.assertEquals("First rotation", 1, this.pictureFileData.quarterRotation);
322         Assert.assertNull("First rotation:  offscreen image should be cleared", this.pictureFileData.offscreenImage);
323         this.pictureFileData.addRotation(1);
324         Assert.assertEquals("Second rotation", 2, this.pictureFileData.quarterRotation);
325         this.pictureFileData.addRotation(1);
326         Assert.assertEquals("Third rotation", 3, this.pictureFileData.quarterRotation);
327         this.pictureFileData.addRotation(1);
328         Assert.assertEquals("Fourth rotation", 0, this.pictureFileData.quarterRotation);
329 
330         this.pictureFileData.addRotation(2);
331         Assert.assertEquals("Double rotation", 2, this.pictureFileData.quarterRotation);
332         this.pictureFileData.addRotation(2);
333         Assert.assertEquals("Second double rotation", 0, this.pictureFileData.quarterRotation);
334 
335         this.pictureFileData.addRotation(-3);
336         Assert.assertEquals("Double rotation", 1, this.pictureFileData.quarterRotation);
337 
338         this.pictureFileData.addRotation(25);
339         Assert.assertEquals("'Big' rotation", 2, this.pictureFileData.quarterRotation);
340     }
341 
342     /**
343      * @throws IOException
344      */
345     @Test
346     public void testDeleteTransformedPictureFile() throws IOException {
347         File tempFile = null;
348         try {
349             // First test: call after initialieation (no transformed file)
350             Assert.assertNull("No transformed file at PictureFileData creation",
351                     this.pictureFileData.transformedPictureFile);
352             // The next line should do nothing.
353             this.pictureFileData.deleteTransformedPictureFile();
354             Assert.assertNull("No transformed file at PictureFileData creation",
355                     this.pictureFileData.transformedPictureFile);
356 
357             // Second: real case. There a file to delete.
358             tempFile = File.createTempFile("JUploadTest", "_testDeleteTransformedPictureFile");
359             Assert.assertTrue("The file should be removed from the file system", tempFile.canRead());
360             this.pictureFileData.transformedPictureFile = tempFile;
361             this.pictureFileData.deleteTransformedPictureFile();
362             Assert.assertNull("The transformed file should be deleted", this.pictureFileData.transformedPictureFile);
363             Assert.assertFalse("The file should be removed from the file system", tempFile.canRead());
364         } finally {
365             if (tempFile != null) {
366                 tempFile.delete();
367                 tempFile = null;
368             }
369         }
370     }
371 
372     /**
373      * @throws IOException
374      */
375     @Test
376     public void testDeleteWorkingCopyPictureFile() throws IOException {
377         File tempFile = null;
378         try {
379             // First test: call after initialization (no working file)
380             Assert.assertNull("No working copy file at PictureFileData creation",
381                     this.pictureFileData.workingCopyTempFile);
382             // The next line should do nothing.
383             this.pictureFileData.deleteWorkingCopyPictureFile();
384             Assert.assertNull("No working copy file at PictureFileData creation",
385                     this.pictureFileData.workingCopyTempFile);
386 
387             // Second: real case. There a file to delete.
388             tempFile = File.createTempFile("JUploadTest", "_testDeleteWorkingCopyTempFile");
389             Assert.assertTrue("The file should be removed from the file system", tempFile.canRead());
390             this.pictureFileData.workingCopyTempFile = tempFile;
391             this.pictureFileData.deleteWorkingCopyPictureFile();
392             Assert.assertNull("The working copy file should be deleted", this.pictureFileData.workingCopyTempFile);
393             Assert.assertFalse("The file should be removed from the file system", tempFile.canRead());
394         } finally {
395             if (tempFile != null) {
396                 tempFile.delete();
397                 tempFile = null;
398             }
399         }
400     }
401 
402     /**
403      * Check the the maxWidth is respected, and applied to all dimensions of the original picture.
404      * 
405      * @throws JUploadException
406      * @throws IOException
407      */
408     @Test
409     public void testInitTransformedPictureFile_Smaller_maxWidth() throws JUploadException, IOException {
410         int maxWidth = 11;// Should the max that is really used
411         int maxHeight = 1001;// Should be 'overriden' by maxWidth
412 
413         // We need to control the PictureUploadPolicy parameters. In the test
414         // case, we use the system properties for that.
415         System.setProperty("maxPicWidth", Integer.toString(maxWidth));
416         System.setProperty("maxPicHeight", Integer.toString(maxHeight));
417         setUp();
418         Assert.assertNull("No transformed file at startup", this.pictureFileData.transformedPictureFile);
419         this.pictureFileData.initTransformedPictureFile();
420         Assert.assertNotNull("The transformed file should now be created", this.pictureFileData.transformedPictureFile);
421         BufferedImage transformedImage = ImageIO.read(this.pictureFileData.transformedPictureFile);
422         Assert.assertEquals("maxWidth must be respected (width)", maxWidth, transformedImage.getWidth());
423         Assert.assertEquals("maxWidth must be respected (height)", maxWidth, transformedImage.getHeight());
424 
425         // Let's clean these files
426         this.pictureFileData.deleteTransformedPictureFile();
427         this.pictureFileData.deleteWorkingCopyPictureFile();
428     }
429 
430     /**
431      * Check the the maxHeight is respected, and applied to all dimensions of the original picture.
432      * 
433      * @throws JUploadException
434      * @throws IOException
435      */
436     @Test
437     public void testInitTransformedPictureFile_Smaller_maxHeight() throws JUploadException, IOException {
438         int maxWidth = 12345;// Should be 'overriden' by maxHeight
439         int maxHeight = 12;// Should the max that is really used
440 
441         // We need to control the PictureUploadPolicy parameters. In the test
442         // case, we use the system properties for that.
443         System.setProperty("maxPicWidth", Integer.toString(maxWidth));
444         System.setProperty("maxPicHeight", Integer.toString(maxHeight));
445         setUp();
446         Assert.assertNull("No transformed file at startup", this.pictureFileData.transformedPictureFile);
447         this.pictureFileData.initTransformedPictureFile();
448         Assert.assertNotNull("The transformed file should now be created", this.pictureFileData.transformedPictureFile);
449         BufferedImage transformedImage = ImageIO.read(this.pictureFileData.transformedPictureFile);
450         Assert.assertEquals("maxHeight must be respected (width)", maxHeight, transformedImage.getWidth());
451         Assert.assertEquals("maxHeight must be respected (height)", maxHeight, transformedImage.getHeight());
452 
453         // Let's clean these files
454         this.pictureFileData.deleteTransformedPictureFile();
455         this.pictureFileData.deleteWorkingCopyPictureFile();
456     }
457 
458     /**
459      * Check the the maxHeight is respected, and applied to all dimensions of the original picture.
460      * 
461      * @throws JUploadException
462      * @throws IOException
463      */
464     @Test
465     public void testInitTransformedPictureFile_Bigger_maxHeight() throws JUploadException, IOException {
466         int maxWidth = 12345;// Should be 'overriden' by maxHeight
467         int maxHeight = 120;// Should be ignored, as it's bigger from the
468         // original size
469 
470         // We need to control the PictureUploadPolicy parameters. In the test
471         // case, we use the system properties for that.
472         System.setProperty("maxPicWidth", Integer.toString(maxWidth));
473         System.setProperty("maxPicHeight", Integer.toString(maxHeight));
474         setUp();
475         Assert.assertNull("No transformed file at startup", this.pictureFileData.transformedPictureFile);
476         this.pictureFileData.initTransformedPictureFile();
477         // The original image is a square of 48x48 pixels. Should be unchanged.
478         Assert.assertNull("The transformed file should now be created", this.pictureFileData.transformedPictureFile);
479     }
480 
481     /**
482      * @throws JUploadIOException
483      */
484     @Test
485     public void testInitWidthAndHeight() throws JUploadIOException {
486         Assert.assertTrue("originalHeight is not set at startup", this.pictureFileData.originalHeight < 0);
487         Assert.assertTrue("originalWidth is not set at startup", this.pictureFileData.originalWidth < 0);
488         this.pictureFileData.initWidthAndHeight();
489         Assert.assertEquals("originalHeight is now set (attribute)", 48, this.pictureFileData.originalHeight);
490         Assert.assertEquals("originalHeight is now set (getter)", 48, this.pictureFileData.getOriginalHeight());
491         Assert.assertEquals("originalWidth is now set (attribute)", 48, this.pictureFileData.originalWidth);
492         Assert.assertEquals("originalWidth is now set (getter)", 48, this.pictureFileData.getOriginalWidth());
493     }
494 
495     /**
496      * @throws IOException
497      * @throws NoSuchMethodException
498      * @throws InvocationTargetException
499      * @throws IllegalAccessException
500      * @throws SecurityException
501      * @throws IllegalArgumentException
502      * @throws JUploadIOException
503      */
504     @Test
505     public void testCreateTransformedPictureFile() throws IOException, IllegalArgumentException, SecurityException,
506             IllegalAccessException, InvocationTargetException, NoSuchMethodException, JUploadIOException {
507         Assert.assertNull("Default transformedPictureFile is null", this.pictureFileData.transformedPictureFile);
508         this.pictureFileData.createTransformedTempFile();
509         // Let's check the creation of the file.
510         Assert.assertTrue("The transformedPictureFile is now created",
511                 this.pictureFileData.transformedPictureFile.canWrite());
512         // Let's check the call to registerUnload.
513         File f = this.pictureFileData.transformedPictureFile;
514         testLastRegisteredUnload(PictureFileData.class);
515         Assert.assertNull("The transformedPictureFile attribute has been cleaned",
516                 this.pictureFileData.transformedPictureFile);
517         Assert.assertFalse("The transformedPictureFile is now deleted", f.canWrite());
518     }
519 
520     /**
521      * @throws IOException
522      * @throws NoSuchMethodException
523      * @throws InvocationTargetException
524      * @throws IllegalAccessException
525      * @throws SecurityException
526      * @throws IllegalArgumentException
527      */
528     @Test
529     public void testCreateWorkingCopyTempFile() throws IOException, IllegalArgumentException, SecurityException,
530             IllegalAccessException, InvocationTargetException, NoSuchMethodException {
531         Assert.assertNull("Default workingCopyTempFile is null", this.pictureFileData.workingCopyTempFile);
532         this.pictureFileData.createWorkingCopyTempFile();
533         // Let's check the creation of the file.
534         Assert.assertTrue("The workingCopyTempFile is now created", this.pictureFileData.workingCopyTempFile.canWrite());
535         // Let's check the call to registerUnload.
536         File f = this.pictureFileData.workingCopyTempFile;
537         testLastRegisteredUnload(PictureFileData.class);
538         Assert.assertNull("The workingCopyTempFile is now deleted", this.pictureFileData.workingCopyTempFile);
539         Assert.assertFalse("The workingCopyTempFile is now deleted", f.canWrite());
540     }
541 
542     /**
543      * @throws JUploadIOException
544      * @throws NoSuchMethodException
545      * @throws InvocationTargetException
546      * @throws IllegalAccessException
547      * @throws SecurityException
548      * @throws IllegalArgumentException
549      */
550     @Test
551     public void testGetWorkingSourceFile() throws JUploadIOException, IllegalArgumentException, SecurityException,
552             IllegalAccessException, InvocationTargetException, NoSuchMethodException {
553         File fDummy = new File("This file does not exist");
554         this.pictureFileData.workingCopyTempFile = fDummy;
555         // First: let's check that the getter won't do anthing, if the file is
556         // already created.
557         Assert.assertEquals("Check the response of getWorkingSourceFile, when the file is set)", fDummy,
558                 this.pictureFileData.getWorkingSourceFile());
559 
560         // Then, check file creation.
561         this.pictureFileData.workingCopyTempFile = null;
562         // We'll just check the length.
563         Assert.assertEquals("Check the response of getWorkingSourceFile, when the file is set)", this.file.length(),
564                 this.pictureFileData.getWorkingSourceFile().length());
565 
566         File f = this.pictureFileData.workingCopyTempFile;
567         testLastRegisteredUnload(PictureFileData.class);
568         Assert.assertNull("The workingCopyTempFile is now deleted", this.pictureFileData.workingCopyTempFile);
569         Assert.assertFalse("The workingCopyTempFile is now deleted", f.canWrite());
570     }
571 
572     /**
573      * @throws JUploadException
574      * @throws IOException
575      */
576     @Test
577     public void testGetImageIcon() throws JUploadException, IOException {
578         int maxWidth = 20;
579         int maxHeight = 20;
580 
581         ImageIcon icon = PictureFileData.getImageIcon(this.file, maxWidth, maxHeight, this.uploadPolicy);
582         Assert.assertEquals("maxWidth should be exactly respected", maxWidth, icon.getIconWidth());
583         Assert.assertEquals("maxHeight should be exactly respected", maxHeight, icon.getIconHeight());
584 
585         maxWidth = 23;
586         maxHeight = 251;
587         icon = PictureFileData.getImageIcon(this.file, maxWidth, maxHeight, this.uploadPolicy);
588         Assert.assertEquals("maxWidth should be exactly respected", maxWidth, icon.getIconWidth());
589         Assert.assertTrue("maxHeight should be respected", maxHeight > icon.getIconHeight());
590 
591         // A test with a 'must be respected' height
592         maxWidth = 239;
593         maxHeight = 25;
594         icon = PictureFileData.getImageIcon(this.file, maxWidth, maxHeight, this.uploadPolicy);
595         Assert.assertTrue("maxWidth should be respected", maxWidth > icon.getIconWidth());
596         Assert.assertEquals("maxHeight should be exactly respected", maxHeight, icon.getIconHeight());
597     }
598 
599     /** */
600     @Test
601     public void testIsFileAPicture() {
602         File f = new File("/qdqd/test.gif");
603         Assert.assertTrue("gif files are valid pictures", PictureFileData.isFileAPicture(f));
604         f = new File("/qdqd/test.jpg");
605         Assert.assertTrue("jpg files are valid pictures", PictureFileData.isFileAPicture(f));
606         f = new File("/qdqd/test.jpeg");
607         Assert.assertTrue("jpeg files are valid pictures", PictureFileData.isFileAPicture(f));
608         f = new File("/qdqd/test.bmp");
609         Assert.assertTrue("bmp files are valid pictures", PictureFileData.isFileAPicture(f));
610         f = new File("/qdqd/test.abc");
611         Assert.assertFalse("abc files are not valid pictures", PictureFileData.isFileAPicture(f));
612         f = new File("/qdqd/test.txt");
613         Assert.assertFalse("txt files are not valid pictures", PictureFileData.isFileAPicture(f));
614     }
615 }