1 19 20 package org.openide.filesystems; 21 22 23 import java.io.OutputStream ; 24 import java.net.URL ; 25 import java.util.jar.JarOutputStream ; 26 import java.util.zip.ZipEntry ; 27 import org.netbeans.junit.*; 28 29 34 public class IsArchiveFileTest extends NbTestCase { 35 38 private LocalFileSystem lfs; 39 private FileObject directory; 40 private FileObject brokenArchive; 41 private FileObject archive; 42 private FileObject file; 43 private FileObject emptyFile; 44 45 48 public IsArchiveFileTest(String name) { 49 super(name); 50 } 51 52 public static void main(String [] args) throws Exception { 53 junit.textui.TestRunner.run(new NbTestSuite(IsArchiveFileTest.class)); 54 } 55 56 59 protected void setUp() throws Exception { 60 super.setUp(); 61 clearWorkDir(); 62 lfs = new LocalFileSystem (); 63 lfs.setRootDirectory(this.getWorkDir()); 64 Repository.getDefault().addFileSystem(lfs); 65 FileObject root = lfs.getRoot(); 66 directory = root.createFolder("dir"); 67 brokenArchive = root.createData ("brokenArchive.jar"); 68 archive = root.createData("archive.jar"); 69 FileLock lock = archive.lock(); 70 try { 71 JarOutputStream out = new JarOutputStream (archive.getOutputStream(lock)); 72 try { 73 out.putNextEntry(new ZipEntry ("foo")); 74 out.closeEntry(); 75 } finally { 76 out.close(); 77 } 78 } finally { 79 lock.releaseLock(); 80 } 81 file = root.createData ("file.txt"); 82 lock = file.lock (); 83 try { 84 OutputStream out = file.getOutputStream(lock); 85 try { 86 out.write ("Test file".getBytes()); 87 } finally { 88 out.close(); 89 } 90 } finally { 91 lock.releaseLock(); 92 } 93 emptyFile = root.createData("emptyFile.txt"); 94 } 95 96 protected void tearDown() throws Exception { 97 Repository.getDefault().removeFileSystem(lfs); 98 super.tearDown(); 99 } 100 101 102 public void testIsArchivFile () throws Exception { 103 assertFalse (FileUtil.isArchiveFile(directory)); 104 assertFalse (FileUtil.isArchiveFile(brokenArchive)); 105 assertTrue (FileUtil.isArchiveFile(archive)); 106 assertFalse (FileUtil.isArchiveFile(file)); 107 assertFalse (FileUtil.isArchiveFile(emptyFile)); 108 109 assertFalse (FileUtil.isArchiveFile(new URL ("jar:file:/foo.jar!/"))); 110 assertFalse (FileUtil.isArchiveFile(new URL ("file:/foo/"))); 111 assertTrue (FileUtil.isArchiveFile(new URL ("file:/foo.jar"))); 112 } 113 114 115 } 116 117 118 119 | Popular Tags |