1 package net.sourceforge.cvsgrab; 2 3 import java.io.File ; 4 import java.io.FileInputStream ; 5 import java.io.InputStream ; 6 import java.util.Properties ; 7 8 9 16 public class LocalRepositoryTest extends AbstractTestCase { 17 18 private LocalRepository localRepository; 19 private File localRepoDir; 20 private RemoteRepository remoteRepository; 21 22 26 public LocalRepositoryTest(String name) { 27 super(name); 28 } 29 30 34 protected void setUp() throws Exception { 35 super.setUp(); 36 File localRootDir = new File (basedir, "target/testRepo"); 37 CVSGrab cvsGrab = new CVSGrab(); 38 cvsGrab.setCvsRoot("testRoot"); 39 cvsGrab.setDestDir(localRootDir.getPath()); 40 cvsGrab.getWebOptions().setRootUrl("rootUrl"); 41 cvsGrab.getWebOptions().setPackagePath("package"); 42 cvsGrab.setCleanUpdate(true); 43 localRepoDir = new File (localRootDir, "package"); 44 localRepoDir.mkdirs(); 45 localRepository = new LocalRepository(cvsGrab); 46 remoteRepository = new RemoteRepository("testRoot", localRepository); 47 File file = new File (basedir, "src/conf/FileTypes.properties"); 48 Properties fileTypes = new Properties (); 49 InputStream is = new FileInputStream (file); 50 fileTypes.load(is); 51 RemoteFile.setFileTypes(fileTypes); 52 } 53 54 58 protected void tearDown() throws Exception { 59 super.tearDown(); 60 cleanDir(localRepoDir); 61 localRepoDir.delete(); 62 } 63 64 private void cleanDir(File dir) { 65 final File [] contents = dir.listFiles(); 66 if (contents == null) { 67 return; 68 } 69 70 for (int i = 0; i < contents.length; i++) { 71 if (contents[i].isDirectory()) { 72 cleanDir(contents[i]); 73 } 74 contents[i].delete(); 75 } 76 } 77 78 public void testPruneEmptyDirs() throws Exception { 79 RemoteDirectory dirRootRemote = new RemoteDirectory(remoteRepository, "package", "package"); 80 localRepository.add(dirRootRemote); 81 File a = new File (localRepoDir, "a.txt"); 82 a.createNewFile(); 83 RemoteFile aRemote = new RemoteFile("a.txt", "1.1"); 84 aRemote.setDirectory(dirRootRemote); 85 localRepository.updateFileVersion(aRemote); 86 File dir1 = new File (localRepoDir, "dir1"); 87 dir1.mkdir(); 88 RemoteDirectory dir1Remote = new RemoteDirectory(dirRootRemote, "dir1"); 89 localRepository.add(dir1Remote); 90 File b = new File (dir1, "b.txt"); 91 b.createNewFile(); 92 RemoteFile bRemote = new RemoteFile("b.txt", "1.1"); 93 bRemote.setDirectory(dir1Remote); 94 localRepository.updateFileVersion(bRemote); 95 96 File dir2 = new File (localRepoDir, "dir2"); 97 dir2.mkdir(); 98 RemoteDirectory dir2Remote = new RemoteDirectory(dirRootRemote, "dir2"); 99 localRepository.add(dir2Remote); 100 101 File dir21 = new File (dir2, "dir21"); 102 dir21.mkdir(); 103 RemoteDirectory dir21Remote = new RemoteDirectory(dir2Remote, "dir21"); 104 localRepository.add(dir21Remote); 105 106 File c = new File (dir21, "c.txt"); 107 c.createNewFile(); 108 RemoteFile cRemote = new RemoteFile("c.txt", "1.1"); 109 cRemote.setDirectory(dir21Remote); 110 localRepository.updateFileVersion(cRemote); 111 112 c.delete(); 113 localRepository.cleanRemovedFiles(dir21Remote); 114 115 File dir3 = new File (localRepoDir, "dir3"); 116 dir3.mkdir(); 117 RemoteDirectory dir3Remote = new RemoteDirectory(dirRootRemote, "dir3"); 118 localRepository.add(dir3Remote); 119 120 File d = new File (dir3, "d.txt"); 122 d.createNewFile(); 123 124 localRepository.pruneEmptyDirectories(); 125 126 assertFalse(dir21.exists()); 127 assertFalse(dir2.exists()); 128 assertTrue(dir1.exists()); 129 assertTrue(dir3.exists()); 130 assertTrue(d.exists()); 131 } 132 } 133 | Popular Tags |