1 19 20 package org.netbeans.modules.java.platform.queries; 21 22 import java.io.File ; 23 import java.io.FileOutputStream ; 24 import java.util.zip.ZipEntry ; 25 import java.util.zip.ZipOutputStream ; 26 import java.util.zip.ZipOutputStream ; 27 import org.netbeans.api.java.queries.SourceForBinaryQuery; 28 import org.netbeans.junit.NbTestCase; 29 import org.openide.filesystems.FileObject; 30 import org.openide.filesystems.FileUtil; 31 32 33 37 public class PlatformSourceForBinaryQueryTest extends NbTestCase { 38 39 public PlatformSourceForBinaryQueryTest(String testName) { 40 super(testName); 41 } 42 43 protected void setUp() throws Exception { 44 super.setUp(); 45 clearWorkDir(); 46 } 47 48 49 public void testUnregisteredPlatform() throws Exception { 50 File wd = getWorkDir(); 51 FileObject wdo = FileUtil.toFileObject(wd); 52 assertNotNull(wdo); 53 FileObject p1 = wdo.createFolder("platform1"); 54 FileObject fo = p1.createFolder("jre"); 55 fo = fo.createFolder("lib"); 56 FileObject rt1 = fo.createData("rt.jar"); 57 FileObject src1 = FileUtil.getArchiveRoot(createSrcZip (p1)); 58 59 FileObject p2 = wdo.createFolder("platform2"); 60 fo = p2.createFolder("jre"); 61 fo = fo.createFolder("lib"); 62 FileObject rt2 = fo.createData("rt.jar"); 63 64 PlatformSourceForBinaryQuery q = new PlatformSourceForBinaryQuery (); 65 66 SourceForBinaryQuery.Result result = q.findSourceRoots(FileUtil.getArchiveRoot(rt1.getURL())); 67 assertEquals(1, result.getRoots().length); 68 assertEquals(src1, result.getRoots()[0]); 69 70 result = q.findSourceRoots(FileUtil.getArchiveRoot(rt2.getURL())); 71 assertNull(result); 72 73 } 74 75 private static FileObject createSrcZip (FileObject pf) throws Exception { 76 File f = new File (FileUtil.toFile(pf),"src.zip"); 77 ZipOutputStream zf = new ZipOutputStream (new FileOutputStream (f)); 78 ZipEntry e = new ZipEntry ("Test.java"); 79 zf.putNextEntry(e); 80 zf.write("class Test {}".getBytes()); 81 zf.close(); 82 return FileUtil.toFileObject(f); 83 } 84 85 } 86 | Popular Tags |