KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > platform > queries > PlatformSourceForBinaryQueryTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.java.platform.queries;
21
22 import java.io.File JavaDoc;
23 import java.io.FileOutputStream JavaDoc;
24 import java.util.zip.ZipEntry JavaDoc;
25 import java.util.zip.ZipOutputStream JavaDoc;
26 import java.util.zip.ZipOutputStream JavaDoc;
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 /**
34  *
35  * @author Tomas Zezula
36  */

37 public class PlatformSourceForBinaryQueryTest extends NbTestCase {
38     
39     public PlatformSourceForBinaryQueryTest(String JavaDoc testName) {
40         super(testName);
41     }
42
43     protected void setUp() throws Exception JavaDoc {
44         super.setUp();
45         clearWorkDir();
46     }
47     
48     
49     public void testUnregisteredPlatform() throws Exception JavaDoc {
50         File JavaDoc 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 JavaDoc {
76         File JavaDoc f = new File JavaDoc (FileUtil.toFile(pf),"src.zip");
77         ZipOutputStream JavaDoc zf = new ZipOutputStream JavaDoc (new FileOutputStream JavaDoc(f));
78         ZipEntry JavaDoc e = new ZipEntry JavaDoc ("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