}
}
public void testTempFileDeleter() throws Exception {
StandaloneSession session = new StandaloneSession( "tempfiledeleter", UUIDUtil.getUUIDAsString() ); // get one with an id. //$NON-NLS-1$
StandaloneTempFileDeleter deleter = new StandaloneTempFileDeleter();
StandaloneApplicationContext appContext = new StandaloneApplicationContext( getSolutionRoot(), "" ); //$NON-NLS-1$ //$NON-NLS-2$
File file1 = appContext.createTempFile( session, "testTempFileDeleter", "txt", true ); //$NON-NLS-1$ //$NON-NLS-2$
assertNotNull( file1 ); // File object was returned
assertTrue( file1.exists() ); // File exists
assertFalse( deleter.hasTempFile( file1.getName() ) ); // Deleter wasn't bound to session, so no delete
// Bind deleter to the session
session.setAttribute( ITempFileDeleter.DELETER_SESSION_VARIABLE, deleter );
File file2 = appContext.createTempFile( session, "testTempFileDeleter", "txt", true ); //$NON-NLS-1$ //$NON-NLS-2$
assertNotNull( file2 ); // File object was returned
assertTrue( file2.exists() ); // File exists
assertTrue( deleter.hasTempFile( file2.getName() ) ); // Deleter is bound to session
// File names should be unique
assertFalse( file1.getName().equals( file2.getName() ) );
deleter.doTempFileCleanup();
assertTrue( file1.exists() ); // This file will be left over
assertFalse( file2.exists() ); // The deleter should have removed this
assertFalse( deleter.hasTempFile( file2.getName() ) ); // After doTempFileCleanup() the list should be empty
// The tearDown should blow away everything else...
deleter.trackTempFile( file2 ); // Add known deleted file to the deleter
deleter.doTempFileCleanup(); // Validates cleanup doesn't choke on missing files
// Test that IllegalArgumentException if passed a null
try {
deleter.trackTempFile( null );
fail();
} catch ( IllegalArgumentException expected ) {
//ignored
}
}