FileDocCategorySizeDatePackage
TouchTest.javaAPI DocApache Ant 1.705056Wed Dec 13 06:16:24 GMT 2006org.apache.tools.ant.taskdefs

TouchTest

public class TouchTest extends org.apache.tools.ant.BuildFileTest

Fields Summary
private static String
TOUCH_FILE
private static final org.apache.tools.ant.util.FileUtils
FILE_UTILS
Utilities used for file operations
Constructors Summary
public TouchTest(String name)


       
        super(name);
    
Methods Summary
public voidassertTimesNearlyMatch(long timestamp, long time)
assert that two times are within the current FS granularity;

param
timestamp
param
time

        long granularity= FILE_UTILS.getFileTimestampGranularity();
        assertTimesNearlyMatch(timestamp, time, granularity);
    
private voidassertTimesNearlyMatch(long timestamp, long time, long range)
assert that two times are within a specified range

param
timestamp
param
time
param
range

        assertTrue("Time " + timestamp + " is not within " + range + " ms of "
            + time, (Math.abs(time - timestamp) <= range));
    
public longgetTargetTime()


        File file = new File(System.getProperty("root"), TOUCH_FILE);
        if(!file.exists()) {
            throw new BuildException("failed to touch file " + file);
        }
        return file.lastModified();
    
public voidsetUp()

        configureProject("src/etc/testcases/taskdefs/touch.xml");
    
public voidtearDown()

        executeTarget("cleanup");
    
public voidtest2000()
verify that the millis test sets things up

        touchFile("test2000", 946080000000L);
    
public voidtestBadPattern()
test the pattern attribute again

        expectBuildExceptionContaining("testBadPattern",
            "No parsing exception thrown", "Unparseable");
    
public voidtestExplicitMappedFileset()
test the explicit mapped file set

        executeTarget("testExplicitMappedFileset");
    
public voidtestFilelist()
test the file list

        touchFile("testFilelist", 662256000000L);
    
public voidtestFileset()
test the file set

        touchFile("testFileset", 946080000000L);
    
public voidtestGoodPattern()
test the pattern attribute

        executeTarget("testGoodPattern");
    
public voidtestMappedFilelist()
test the mapped file list

        executeTarget("testMappedFilelist");
    
public voidtestMappedFileset()
test the mapped file set

        executeTarget("testMappedFileset");
    
public voidtestMillis()
verify that the millis test sets things up

        touchFile("testMillis", 662256000000L);
    
public voidtestNoSeconds()
No real test, simply checks whether the dateformat without seconds is accepted - by erroring out otherwise.

        executeTarget("noSeconds");
        long time = getTargetTime();
    
public voidtestNow()
verify that the default value defaults to now

        long now=System.currentTimeMillis();
        executeTarget("testNow");
        long time = getTargetTime();
        assertTimesNearlyMatch(time,now,5000);
    
public voidtestResourceCollection()
test the resource collection

        touchFile("testResourceCollection", 1662256000000L);
    
public voidtestSeconds()
No real test, simply checks whether the dateformat with seconds is accepted - by erroring out otherwise.

        executeTarget("seconds");
        long time=getTargetTime();
    
private voidtouchFile(java.lang.String targetName, long timestamp)
run a target to touch the test file; verify the timestamp is as expected

param
targetName
param
timestamp

        executeTarget(targetName);
        long time = getTargetTime();
        assertTimesNearlyMatch(timestamp, time);