KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > store > images > ImageResizerTest


1 /*
2  * Created on Dec 8, 2004
3  */

4 package com.openedit.store.images;
5
6 import java.awt.Dimension JavaDoc;
7 import java.awt.image.BufferedImage JavaDoc;
8 import java.io.File JavaDoc;
9
10 import javax.imageio.ImageIO JavaDoc;
11
12 import com.openedit.modules.image.ImageResizer;
13 import com.openedit.store.StoreTestCase;
14
15 /**
16  * @author dbrown
17  *
18  */

19 public class ImageResizerTest extends StoreTestCase
20 {
21     public ImageResizerTest( String JavaDoc inName )
22     {
23         super( inName );
24     }
25
26     public void testResizeImage() throws Exception JavaDoc
27     {
28         final int MAX_WIDTH = 150;
29         ImageResizer resizer = new ImageResizer();
30         resizer.setMaxScaledSize( new Dimension JavaDoc( MAX_WIDTH, Integer.MAX_VALUE ) );
31
32         File JavaDoc imageDir = new File JavaDoc( "store" + File.separatorChar + "images" );
33         // TODO: we need to add a test image to the appropriate place
34
File JavaDoc inputFile = new File JavaDoc( imageDir, "testImage.jpg" );
35         if ( inputFile.exists()) //so we dont have to check in junk images
36
{
37             File JavaDoc outputFile = new File JavaDoc( imageDir, "scaledTestImage.jpg" );
38             outputFile.delete();
39     
40             resizer.resizeImage( inputFile, outputFile );
41     
42             BufferedImage JavaDoc scaledImage = ImageIO.read( outputFile );
43             assertTrue( scaledImage.getWidth() <= MAX_WIDTH );
44         }
45     }
46 }
47
Popular Tags