KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > favorites > RootsTest


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.favorites;
21
22 import java.io.File JavaDoc;
23 import java.util.Arrays JavaDoc;
24 import java.util.HashSet JavaDoc;
25 import junit.textui.TestRunner;
26 import org.netbeans.junit.NbTestCase;
27 import org.netbeans.junit.NbTestSuite;
28 import org.openide.filesystems.FileUtil;
29 import org.openide.loaders.DataFolder;
30 import org.openide.modules.ModuleInfo;
31 import org.openide.nodes.Node;
32 import org.openide.util.Lookup;
33
34 public class RootsTest extends NbTestCase {
35     private File JavaDoc userDir, platformDir, clusterDir;
36
37     public RootsTest(String JavaDoc name) {
38         super (name);
39     }
40     
41     public static void main(String JavaDoc[] args) {
42         TestRunner.run(new NbTestSuite(RootsTest.class));
43     }
44     
45     
46     protected void setUp () throws Exception JavaDoc {
47         super.setUp ();
48         
49         // initialize module system with all modules
50
Lookup.getDefault().lookup (
51             ModuleInfo.class
52         );
53         
54 /*
55         // clear directories first
56         this.clearWorkDir();
57         
58         userDir = new File (getWorkDir(), "user");
59         assertTrue (userDir.mkdirs ());
60         platformDir = new File (getWorkDir(), "platform");
61         assertTrue (platformDir.mkdirs ());
62         clusterDir = new File (getWorkDir (), "clstr");
63         assertTrue (clusterDir.mkdirs ());
64         
65         System.setProperty("netbeans.home", platformDir.toString ());
66         System.setProperty("netbeans.user", userDir.toString ());
67         */

68     }
69     
70     /* UI was changed. There are no more FS roots displayed in Favorites tab */
71     /*public void testRootNodeContainsAllFileSystemRoots () throws Exception {
72         HashSet roots = new HashSet ();
73         {
74             File[] arr = File.listRoots();
75             for (int i = 0; i < arr.length; i++) {
76                 roots.add (arr[i]);
77             }
78         }
79         
80         Node[] arr = Favorites.getNode ().getChildren ().getNodes (true);
81         
82         for (int i = 0; i < arr.length; i++) {
83             File f = Favorites.fileForNode (arr[i]);
84             if (f != null) {
85                 roots.remove (f);
86             }
87         }
88
89         if (!roots.isEmpty()) {
90             fail (
91                 "All roots should be children, but these were missing:\n" +
92                 roots +
93                 " this is the list of children nodes:\n" +
94                 Arrays.asList (arr)
95             );
96         }
97     }*/

98     
99     public void testLinkToHomeDirIsThere () throws Exception JavaDoc {
100         Node[] arr = Favorites.getNode ().getChildren ().getNodes (true);
101         
102         File JavaDoc home = new File JavaDoc (System.getProperty("user.home")).getCanonicalFile();
103
104         HashSet JavaDoc folders = new HashSet JavaDoc ();
105         for (int i = 0; i < arr.length; i++) {
106             DataFolder f = (DataFolder)arr[i].getCookie(DataFolder.class);
107             if (f == null) continue;
108             
109             folders.add (f);
110             
111             File JavaDoc file = FileUtil.toFile (
112                 f.getPrimaryFile()
113             );
114             assertNotNull ("All folders have files", file);
115             
116             file = file.getCanonicalFile();
117             
118             if (file.equals (home)) {
119                 return;
120             }
121         }
122         
123         fail ("none of the folders represent user home: " + home + "\n" + folders);
124     }
125
126     
127     public void testNodesUnderRootRepresentTheirFiles () throws Exception JavaDoc {
128         HashSet JavaDoc roots = new HashSet JavaDoc (Arrays.asList (File.listRoots()));
129         
130         Node[] arr = Favorites.getNode ().getChildren ().getNodes (true);
131         
132         for (int i = 0; i < arr.length; i++) {
133             File JavaDoc f = Favorites.fileForNode (arr[i]);
134             if (roots.remove (f)) {
135                 Node[] nexts = arr[i].getChildren().getNodes (true);
136                 for (int j = 0; j < nexts.length; j++) {
137                     File JavaDoc file = Favorites.fileForNode (nexts[i]);
138                     assertNotNull ("For node: " + nexts[i] + " there has to be file", file);
139                     assertEquals ("Correct parent for " + nexts[i], f, file.getParentFile());
140                 }
141             }
142         }
143     }
144 }
145
Popular Tags