Added
Link Here
|
1 |
/* |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
3 |
* |
4 |
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. |
5 |
* |
6 |
* The contents of this file are subject to the terms of either the GNU |
7 |
* General Public License Version 2 only ("GPL") or the Common |
8 |
* Development and Distribution License("CDDL") (collectively, the |
9 |
* "License"). You may not use this file except in compliance with the |
10 |
* License. You can obtain a copy of the License at |
11 |
* http://www.netbeans.org/cddl-gplv2.html |
12 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the |
13 |
* specific language governing permissions and limitations under the |
14 |
* License. When distributing the software, include this License Header |
15 |
* Notice in each file and include the License file at |
16 |
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this |
17 |
* particular file as subject to the "Classpath" exception as provided |
18 |
* by Sun in the GPL Version 2 section of the License file that |
19 |
* accompanied this code. If applicable, add the following below the |
20 |
* License Header, with the fields enclosed by brackets [] replaced by |
21 |
* your own identifying information: |
22 |
* "Portions Copyrighted [year] [name of copyright owner]" |
23 |
* |
24 |
* Contributor(s): |
25 |
* |
26 |
* The Original Software is NetBeans. The Initial Developer of the Original |
27 |
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun |
28 |
* Microsystems, Inc. All Rights Reserved. |
29 |
* |
30 |
* If you wish your version of this file to be governed by only the CDDL |
31 |
* or only the GPL Version 2, indicate your decision by adding |
32 |
* "[Contributor] elects to include this software in this distribution |
33 |
* under the [CDDL or GPL Version 2] license." If you do not indicate a |
34 |
* single choice of license, a recipient has the option to distribute |
35 |
* your version of this file under either the CDDL, the GPL Version 2 or |
36 |
* to extend the choice of license to its licensees as provided above. |
37 |
* However, if you add GPL Version 2 code and therefore, elected the GPL |
38 |
* Version 2 license, then the option applies only if the new code is |
39 |
* made subject to such option by the copyright holder. |
40 |
*/ |
41 |
|
42 |
package org.netbeans.modules.java.j2seproject; |
43 |
|
44 |
import java.io.File; |
45 |
import org.netbeans.api.project.FileOwnerQuery; |
46 |
import org.netbeans.api.project.Project; |
47 |
import org.netbeans.junit.MockServices; |
48 |
import org.netbeans.junit.NbTestCase; |
49 |
import org.netbeans.modules.java.j2seproject.ui.SourceNodeFactory; |
50 |
import org.netbeans.spi.project.support.ant.AntProjectHelper; |
51 |
import org.netbeans.spi.project.ui.LogicalViewProvider; |
52 |
import org.netbeans.spi.project.ui.support.NodeList; |
53 |
import org.openide.filesystems.FileObject; |
54 |
import org.openide.filesystems.FileUtil; |
55 |
import org.openide.modules.SpecificationVersion; |
56 |
import org.openide.nodes.Node; |
57 |
|
58 |
/** |
59 |
* Generates project, tries to open a package and counts number of accesses |
60 |
* to it. |
61 |
* |
62 |
* @author Jaroslav Tulach |
63 |
*/ |
64 |
public class PackageViewTest extends NbTestCase { |
65 |
|
66 |
public PackageViewTest(String testName) { |
67 |
super(testName); |
68 |
} |
69 |
|
70 |
private static final String[] createFiles = { |
71 |
"build.xml", |
72 |
"nbproject/build-impl.xml", |
73 |
"nbproject/project.xml", |
74 |
"nbproject/project.properties", |
75 |
"src/", |
76 |
"src/net/sf/dvbcentral/Test.java", |
77 |
"src/net/sf/dvbcentral/Test1.java", |
78 |
"src/net/sf/dvbcentral/Test2.java", |
79 |
"src/net/sf/dvbcentral/Test3.java", |
80 |
"src/net/sf/dvbcentral/Test4.java", |
81 |
"test/", |
82 |
}; |
83 |
|
84 |
|
85 |
public void testCreateProject() throws Exception { |
86 |
File proj = getWorkDir(); |
87 |
clearWorkDir(); |
88 |
J2SEProjectGenerator.setDefaultSourceLevel(new SpecificationVersion ("1.4")); //NOI18N |
89 |
AntProjectHelper aph = J2SEProjectGenerator.createProject(proj, "test-project", null, "manifest.mf", null); |
90 |
J2SEProjectGenerator.setDefaultSourceLevel(null); |
91 |
assertNotNull(aph); |
92 |
FileObject fo = aph.getProjectDirectory(); |
93 |
for (int i=0; i < createFiles.length; i++) { |
94 |
if (createFiles[i].endsWith("/")) { |
95 |
FileUtil.createFolder(fo, createFiles[i]); |
96 |
} else { |
97 |
FileUtil.createData(fo, createFiles[i]); |
98 |
} |
99 |
assertNotNull(createFiles[i]+" file/folder cannot be found", fo.getFileObject(createFiles[i])); |
100 |
} |
101 |
|
102 |
Project prj = FileOwnerQuery.getOwner(fo); |
103 |
|
104 |
|
105 |
CountingSecurityManager.initialize(FileUtil.toFile(fo).getAbsolutePath()); |
106 |
|
107 |
SourceNodeFactory factory = new SourceNodeFactory(); |
108 |
NodeList arr = factory.createNodes(prj); |
109 |
assertNotNull("Not null root node created", arr); |
110 |
assertEquals("Arr is now 2", 2, arr.keys().size()); |
111 |
|
112 |
Node src = arr.node(arr.keys().get(0)); |
113 |
Node pkg = assertNode(src, "net.sf.dvbcentral"); |
114 |
assertNotNull("Package found"); |
115 |
|
116 |
CountingSecurityManager.assertCounts("Just few checks", 1); |
117 |
} |
118 |
|
119 |
|
120 |
private static Node assertNode(Node where, String what) { |
121 |
StringBuffer sb = new StringBuffer(); |
122 |
for (Node n : where.getChildren().getNodes(true)) { |
123 |
if (n.getName().equals(what)) { |
124 |
return n; |
125 |
} |
126 |
sb.append(" n: " + n.getName() + "\n"); |
127 |
} |
128 |
fail("Cannot find node " + what + " only " + where.getChildren().getNodesCount() + " is available:\n" + sb); |
129 |
return null; |
130 |
} |
131 |
} |