KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > image > ImageTest


1 /*
2  * Copyright 2000-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 package org.apache.tools.ant.taskdefs.optional.image;
19
20 import org.apache.tools.ant.BuildFileTest;
21 import org.apache.tools.ant.taskdefs.condition.Os;
22
23 import java.io.IOException JavaDoc;
24 import java.io.File JavaDoc;
25 import java.io.InputStream JavaDoc;
26 import java.io.BufferedInputStream JavaDoc;
27 import java.io.FileInputStream JavaDoc;
28 import java.io.FileReader JavaDoc;
29 import java.io.BufferedReader JavaDoc;
30 import java.util.Properties JavaDoc;
31
32 /**
33  * Tests the Image task.
34  *
35  * @since Ant 1.5
36  */

37 public class ImageTest extends BuildFileTest {
38
39     private final static String JavaDoc TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/image/";
40     private final static String JavaDoc LARGEIMAGE = "largeimage.jpg";
41
42     public ImageTest(String JavaDoc name) {
43         super(name);
44     }
45
46
47     public void setUp() {
48         configureProject(TASKDEFS_DIR + "image.xml");
49     }
50
51
52     public void tearDown() {
53         executeTarget("cleanup");
54     }
55
56     public void testEchoToLog() {
57         expectLogContaining("testEchoToLog", "Processing File");
58     }
59
60     public void testSimpleScale(){
61       expectLogContaining("testSimpleScale", "Processing File");
62       File JavaDoc f = createRelativeFile( "/dest/" + LARGEIMAGE );
63           assertTrue(
64               "Did not create "+f.getAbsolutePath(),
65         f.exists() );
66
67     }
68
69     public void testOverwriteTrue() {
70       expectLogContaining("testSimpleScale", "Processing File");
71       File JavaDoc f = createRelativeFile( "/dest/" + LARGEIMAGE );
72       long lastModified = f.lastModified();
73        if (Os.isFamily("dos")) {
74            try {
75             Thread.sleep(2000);
76            }
77            catch (InterruptedException JavaDoc e) {}
78        }
79       expectLogContaining("testOverwriteTrue", "Processing File");
80       f = createRelativeFile( "/dest/" + LARGEIMAGE );
81       long overwrittenLastModified = f.lastModified();
82       assertTrue("File was not overwritten.",lastModified < overwrittenLastModified);
83     }
84
85     public void testOverwriteFalse() {
86       expectLogContaining("testSimpleScale", "Processing File");
87       File JavaDoc f = createRelativeFile( "/dest/" + LARGEIMAGE );
88       long lastModified = f.lastModified();
89       expectLogContaining("testOverwriteFalse", "Processing File");
90       f = createRelativeFile( "/dest/" + LARGEIMAGE );
91       long overwrittenLastModified = f.lastModified();
92       assertTrue("File was overwritten.",lastModified == overwrittenLastModified);
93     }
94
95
96     public void off_testFailOnError() {
97       try {
98         expectLogContaining("testFailOnError", "Unable to process image stream");
99       }
100       catch (RuntimeException JavaDoc re){
101         assertTrue("Run time exception should say 'Unable to process image stream'. :" + re.toString(),re.toString().indexOf("Unable to process image stream") > -1);
102       }
103     }
104
105
106
107   protected File JavaDoc createRelativeFile( String JavaDoc filename ) {
108         if (filename.equals( "." )) {
109             return getProjectDir();
110         }
111         // else
112
return new File JavaDoc( getProjectDir(), filename );
113     }
114 }
115
116
Popular Tags