KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > queries > SubprojectProviderImplTest


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.apisupport.project.queries;
21
22 import java.io.File JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.SortedSet JavaDoc;
25 import java.util.TreeSet JavaDoc;
26 import org.netbeans.api.project.Project;
27 import org.netbeans.api.project.ProjectManager;
28 import org.netbeans.modules.apisupport.project.TestBase;
29 import org.netbeans.spi.project.SubprojectProvider;
30 import org.netbeans.spi.project.support.ant.PropertyUtils;
31 import org.openide.filesystems.FileObject;
32 import org.openide.filesystems.FileUtil;
33
34 /**
35  * Test subprojects.
36  * @author Jesse Glick
37  */

38 public class SubprojectProviderImplTest extends TestBase {
39     
40     public SubprojectProviderImplTest(String JavaDoc name) {
41         super(name);
42     }
43     
44     public void testNetBeansOrgSubprojects() throws Exception JavaDoc {
45         // Keep in synch with ant/nbproject/project.xml:
46
checkSubprojects("ant", new String JavaDoc[] {
47             "openide/fs",
48             "openide/util",
49             "openide/modules",
50             "openide/nodes",
51             "openide/awt",
52             "openide/dialogs",
53             "openide/windows",
54             "openide/text",
55             "openide/actions",
56             "openide/execution",
57             "openide/io",
58             "openide/loaders",
59             "xml/api",
60             "core/navigator",
61             "openide/explorer",
62             "core/options",
63             "libs/swing-layout",
64             "core/progress",
65             "projects/projectapi",
66             "projects/projectuiapi",
67         });
68     }
69     
70     public void testExternalSubprojects() throws Exception JavaDoc {
71         checkSubprojects(resolveEEPPath("/suite1/action-project"), new String JavaDoc[] {
72             resolveEEPPath("/suite1/support/lib-project"),
73             file("openide/dialogs").getAbsolutePath(),
74         });
75         checkSubprojects(resolveEEPPath("/suite1/support/lib-project"), new String JavaDoc[0]);
76         // No sources for beans available, so no subprojects reported:
77
checkSubprojects(resolveEEPPath("/suite3/dummy-project"), new String JavaDoc[0]);
78     }
79     
80     /** @see "#63824" */
81     public void testAdHocSubprojects() throws Exception JavaDoc {
82         assertDepends("mdr/module", "mdr");
83         assertDepends("ide/applemenu", "ide/applemenu/eawtstub");
84     }
85     
86     /** @see "#77533" */
87     public void testSelfRefWithClassPathExts() throws Exception JavaDoc {
88         checkSubprojects("apisupport/samples/PaintApp-suite/ColorChooser", new String JavaDoc[0]);
89     }
90     
91     /** @see "#81878" */
92     public void testInclusionOfHigherBin() throws Exception JavaDoc {
93         checkSubprojects("httpserver/servletapi", new String JavaDoc[0]);
94     }
95     
96     private void checkSubprojects(String JavaDoc project, String JavaDoc[] subprojects) throws Exception JavaDoc {
97         Project p = project(project);
98         SubprojectProvider spp = (SubprojectProvider) p.getLookup().lookup(SubprojectProvider.class);
99         assertNotNull("have SPP in " + p, spp);
100         SortedSet JavaDoc/*<String>*/ expected = new TreeSet JavaDoc();
101         for (int i = 0; i < subprojects.length; i++) {
102             File JavaDoc f = new File JavaDoc(subprojects[i]);
103             if (!f.isAbsolute()) {
104                 f = file(subprojects[i]);
105             }
106             expected.add(f.toURI().toString());
107         }
108         SortedSet JavaDoc/*<String>*/ actual = new TreeSet JavaDoc();
109         Iterator JavaDoc it = spp.getSubprojects().iterator();
110         while (it.hasNext()) {
111             actual.add(((Project) it.next()).getProjectDirectory().getURL().toExternalForm());
112         }
113         assertEquals("correct subprojects for " + project, expected.toString(), actual.toString());
114     }
115     
116     private Project project(String JavaDoc path) throws Exception JavaDoc {
117         FileObject dir = FileUtil.toFileObject(PropertyUtils.resolveFile(nbCVSRootFile(), path));
118 // FileObject dir = nbCVSRoot().getFileObject(path);
119
assertNotNull("have " + path, dir);
120         Project p = ProjectManager.getDefault().findProject(dir);
121         assertNotNull("have project in " + path, p);
122         return p;
123     }
124     
125     private void assertDepends(String JavaDoc parent, String JavaDoc child) throws Exception JavaDoc {
126         Project p1 = project(parent);
127         Project p2 = project(child);
128         SubprojectProvider spp = (SubprojectProvider) p1.getLookup().lookup(SubprojectProvider.class);
129         assertNotNull("have SPP in " + p1, spp);
130         assertTrue(parent + " includes " + child, spp.getSubprojects().contains(p2));
131     }
132     
133 }
134
Popular Tags