001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.tools.ant.taskdefs.optional.image;
020:
021: import org.apache.tools.ant.BuildFileTest;
022: import org.apache.tools.ant.util.FileUtils;
023:
024: import java.io.File;
025:
026: /**
027: * Tests the Image task.
028: *
029: * @since Ant 1.5
030: */
031: public class ImageTest extends BuildFileTest {
032:
033: private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/image/";
034: private final static String LARGEIMAGE = "largeimage.jpg";
035:
036: private static final FileUtils FILE_UTILS = FileUtils
037: .getFileUtils();
038:
039: public ImageTest(String name) {
040: super (name);
041: }
042:
043: public void setUp() {
044: configureProject(TASKDEFS_DIR + "image.xml");
045: }
046:
047: public void tearDown() {
048: executeTarget("cleanup");
049: }
050:
051: public void testEchoToLog() {
052: expectLogContaining("testEchoToLog", "Processing File");
053: }
054:
055: public void testSimpleScale() {
056: expectLogContaining("testSimpleScale", "Processing File");
057: File f = createRelativeFile("/dest/" + LARGEIMAGE);
058: assertTrue("Did not create " + f.getAbsolutePath(), f.exists());
059:
060: }
061:
062: public void testOverwriteTrue() {
063: expectLogContaining("testSimpleScale", "Processing File");
064: File f = createRelativeFile("/dest/" + LARGEIMAGE);
065: long lastModified = f.lastModified();
066: try {
067: Thread.sleep(FILE_UTILS.getFileTimestampGranularity());
068: } catch (InterruptedException e) {
069: }
070: expectLogContaining("testOverwriteTrue", "Processing File");
071: f = createRelativeFile("/dest/" + LARGEIMAGE);
072: long overwrittenLastModified = f.lastModified();
073: assertTrue("File was not overwritten.",
074: lastModified < overwrittenLastModified);
075: }
076:
077: public void testOverwriteFalse() {
078: expectLogContaining("testSimpleScale", "Processing File");
079: File f = createRelativeFile("/dest/" + LARGEIMAGE);
080: long lastModified = f.lastModified();
081: expectLogContaining("testOverwriteFalse", "Processing File");
082: f = createRelativeFile("/dest/" + LARGEIMAGE);
083: long overwrittenLastModified = f.lastModified();
084: assertTrue("File was overwritten.",
085: lastModified == overwrittenLastModified);
086: }
087:
088: public void off_testFailOnError() {
089: try {
090: expectLogContaining("testFailOnError",
091: "Unable to process image stream");
092: } catch (RuntimeException re) {
093: assertTrue("Run time exception should say "
094: + "'Unable to process image stream'. :"
095: + re.toString(), re.toString().indexOf(
096: "Unable to process image stream") > -1);
097: }
098: }
099:
100: protected File createRelativeFile(String filename) {
101: if (filename.equals(".")) {
102: return getProjectDir();
103: }
104: // else
105: return new File(getProjectDir(), filename);
106: }
107: }
|