1 22 package org.objectweb.petals.jbi.management.autoload; 23 24 import java.io.File ; 25 import java.io.IOException ; 26 27 import junit.framework.TestCase; 28 29 import org.apache.commons.io.FileUtils; 30 31 36 public class InstalledDirectoryScannerTest extends TestCase { 37 private InstalledDirectoryScanner installedDirectoryScanner; 38 39 private String baseDir; 40 41 private AutoLoaderImplMock autoLoadImplMock; 42 43 public void setUp() throws IOException { 44 autoLoadImplMock = new AutoLoaderImplMock(); 45 baseDir = this.getClass().getResource(".").toString(); 46 baseDir = baseDir.substring(0, baseDir.indexOf("target")); 47 baseDir = baseDir.substring(baseDir.indexOf(":") + 1); 48 if (new File (baseDir + "target" + File.separator + "install").exists()) { 49 FileUtils.forceDelete(new File (baseDir + "target" + File.separator 50 + "install")); 51 } 52 new File (baseDir + "target" + File.separator + "install").mkdir(); 53 installedDirectoryScanner = new InstalledDirectoryScanner( 54 autoLoadImplMock, new File (baseDir + "target" + File.separator 55 + "install")); 56 } 57 58 public void testRunInstall() throws IOException { 59 FileUtils.copyFileToDirectory(new File (baseDir + "src" + File.separator 60 + "test-data" + File.separator + "packages" + File.separator 61 + "installation01.zip"), new File (baseDir + "target" 62 + File.separator + "install")); 63 installedDirectoryScanner.run(); 64 assertEquals(installedDirectoryScanner.previousFileList.iterator() 65 .next(), new File (baseDir + "target" + File.separator 66 + "install" + File.separator + "installation01.zip")); 67 } 68 69 public void testRunUninstall() throws IOException { 70 testRunInstall(); 71 FileUtils.forceDelete(new File (baseDir + "target" + File.separator 72 + "install" + File.separator + "installation01.zip")); 73 assertFalse(autoLoadImplMock.isUninstalled()); 74 installedDirectoryScanner.run(); 75 assertTrue(autoLoadImplMock.isUninstalled()); 76 assertEquals(installedDirectoryScanner.previousFileList.size(), 0); 77 } 78 } 79 | Popular Tags |