KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > j2seplatform > platformdefinition > JavadocForBinaryQueryPlatformImplTest


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.j2seplatform.platformdefinition;
21
22 import java.io.File JavaDoc;
23 import java.io.FileOutputStream JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.io.OutputStream JavaDoc;
26 import java.net.URI JavaDoc;
27 import java.net.URL JavaDoc;
28 import java.util.ArrayList JavaDoc;
29 import java.util.jar.JarOutputStream JavaDoc;
30 import java.util.zip.ZipEntry JavaDoc;
31 import junit.framework.Test;
32 import junit.framework.TestCase;
33 import junit.framework.TestSuite;
34 import org.netbeans.api.java.classpath.ClassPath;
35 import org.netbeans.api.java.platform.JavaPlatform;
36 import org.netbeans.api.java.queries.JavadocForBinaryQuery;
37 import org.netbeans.api.project.TestUtil;
38 import org.netbeans.junit.NbTestCase;
39 import org.openide.filesystems.FileLock;
40 import org.openide.filesystems.FileObject;
41 import org.openide.filesystems.FileSystem;
42 import org.openide.filesystems.FileUtil;
43 import org.openide.filesystems.URLMapper;
44 import org.openide.util.Lookup;
45 import org.openide.util.Utilities;
46 import org.openide.util.lookup.Lookups;
47 import org.netbeans.core.startup.layers.ArchiveURLMapper;
48 import org.netbeans.modules.masterfs.MasterURLMapper;
49
50 // XXX needs to test listening as well
51

52 /**
53  * JavadocForBinaryQueryPlatformImpl test
54  *
55  * @author David Konecny
56  */

57 public class JavadocForBinaryQueryPlatformImplTest extends NbTestCase implements Lookup.Provider {
58     
59     
60     public JavadocForBinaryQueryPlatformImplTest(java.lang.String JavaDoc testName) {
61         super(testName);
62         TestUtil.setLookup (Lookups.proxy(this));
63     }
64     
65     private Lookup lookup;
66     
67     protected void setUp() throws Exception JavaDoc {
68         System.setProperty("netbeans.user", getWorkDirPath());
69         super.setUp();
70         clearWorkDir();
71     }
72     
73     private File JavaDoc getBaseDir() throws Exception JavaDoc {
74         File JavaDoc dir = getWorkDir();
75         if (Utilities.isWindows()) {
76             dir = new File JavaDoc(dir.getCanonicalPath());
77         }
78         return dir;
79     }
80     
81     public void testQuery() throws Exception JavaDoc {
82         JavaPlatform platform = JavaPlatform.getDefault();
83         
84         ClassPath cp = platform.getBootstrapLibraries();
85         ClassPath.Entry entry = (ClassPath.Entry)cp.entries().iterator().next();
86         URL JavaDoc url = entry.getURL();
87         if (FileUtil.getArchiveFile(url) != null) {
88             url = FileUtil.getArchiveFile(url);
89         }
90         File JavaDoc root = new File JavaDoc(url.getFile());
91         
92         FileObject pfo = cp.getRoots()[0];
93         URL JavaDoc u = URLMapper.findURL(pfo, URLMapper.EXTERNAL);
94         URL JavaDoc urls[] = JavadocForBinaryQuery.findJavadoc(u).getRoots();
95         assertEquals(0, urls.length);
96
97         ArrayList JavaDoc l = new ArrayList JavaDoc();
98         File JavaDoc javadocFile = getBaseDir();
99         l.add(javadocFile.toURI().toURL());
100         J2SEPlatformImpl platformImpl = (J2SEPlatformImpl)platform;
101         platformImpl.setJavadocFolders(l);
102         urls = JavadocForBinaryQuery.findJavadoc(u).getRoots();
103         assertEquals(1, urls.length);
104         assertEquals(javadocFile.toURI().toURL(), urls[0]);
105     }
106     
107     public synchronized Lookup getLookup() {
108         if (lookup == null) {
109             lookup = Lookups.fixed(new Object JavaDoc[] {
110                 new JavaPlatformProviderImpl (),
111                 new ArchiveURLMapper(),
112                 new JavadocForBinaryQueryPlatformImpl(),
113                 new MasterURLMapper(),
114             });
115         }
116         return lookup;
117     }
118     
119 }
120
Popular Tags