Search in sources :

Example 1 with StandaloneTempFileDeleter

use of org.pentaho.platform.engine.core.system.StandaloneTempFileDeleter in project pentaho-platform by pentaho.

the class StandaloneSessionTest method testTempFileDeleter.

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

Aggregations

File (java.io.File)1 StandaloneApplicationContext (org.pentaho.platform.engine.core.system.StandaloneApplicationContext)1 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)1 StandaloneTempFileDeleter (org.pentaho.platform.engine.core.system.StandaloneTempFileDeleter)1