KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > autoupdate > AutoupdaterTest


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.autoupdate;
21
22 import java.io.File JavaDoc;
23 import java.util.List JavaDoc;
24 import junit.framework.TestCase;
25 import org.netbeans.junit.NbTestCase;
26 import org.netbeans.updater.UpdateTracking;
27
28 /** Test issue 82341: http://www.netbeans.org/issues/show_bug.cgi?id=82341
29  *
30  * @author Jiri Rechtacek
31  */

32 public class AutoupdaterTest extends NbTestCase {
33
34     private File JavaDoc platformDir;
35
36     private File JavaDoc userDir;
37
38     private File JavaDoc filesDir;
39
40     private File JavaDoc strangeDir;
41     
42     public AutoupdaterTest (String JavaDoc testName) {
43         super (testName);
44     }
45     
46     protected void setUp () throws Exception JavaDoc {
47         super.setUp ();
48         
49         // clear directories first
50
this.clearWorkDir();
51         
52         platformDir = new File JavaDoc (getWorkDir(), "platform");
53         assertTrue (platformDir.mkdirs ());
54         filesDir = new File JavaDoc (getWorkDir(), "program files");
55         assertTrue (filesDir.mkdirs ());
56         userDir = new File JavaDoc (getWorkDir(), "documents and settings");
57         assertTrue (userDir.mkdirs ());
58         strangeDir = new File JavaDoc (getWorkDir(), "strange");
59         assertTrue (strangeDir.mkdirs ());
60         
61         System.setProperty("netbeans.dirs", filesDir.toString ());
62         System.setProperty("netbeans.home", platformDir.toString ());
63         assertEquals (platformDir.toString (), System.getProperty ("netbeans.home"));
64         System.setProperty("netbeans.user", userDir.toString ());
65         assertEquals (userDir.toString (), System.getProperty ("netbeans.user"));
66     }
67     
68     public void testGetClustersWithUser () throws Exception JavaDoc {
69         List JavaDoc l = UpdateTracking.clusters (true);
70         assertTrue (platformDir + " among clusters " + l, l.contains (platformDir));
71         assertTrue (filesDir + " among clusters " + l, l.contains (filesDir));
72         assertTrue (userDir + " among clusters " + l, l.contains (userDir));
73         assertFalse (strangeDir + " is not among clusters " + l, l.contains (strangeDir));
74     }
75     
76     public void testGetClustersWithoutUser () throws Exception JavaDoc {
77         List JavaDoc l = UpdateTracking.clusters (false);
78         assertTrue (platformDir + " among clusters " + l, l.contains (platformDir));
79         assertTrue (filesDir + " among clusters " + l, l.contains (filesDir));
80         assertFalse (userDir + " is not among clusters " + l, l.contains (userDir));
81         assertFalse (strangeDir + " is not among clusters " + l, l.contains (strangeDir));
82     }
83     
84     public void testPatchesDir () throws Exception JavaDoc {
85         List JavaDoc l = Autoupdater.Support.getPatchDirectories ();
86         File JavaDoc platformDirPatches = new File JavaDoc (new File JavaDoc (platformDir, "lib"), "patches");
87         File JavaDoc userDirPatches = new File JavaDoc (new File JavaDoc (userDir, "lib"), "patches");
88         File JavaDoc filesDirPatches = new File JavaDoc (new File JavaDoc (filesDir, "lib"), "patches");
89         File JavaDoc strangeDirPatches = new File JavaDoc (new File JavaDoc (strangeDir, "lib"), "patches");
90         assertTrue (platformDirPatches + " among patches dirs " + l, l.contains (platformDirPatches));
91         assertTrue (filesDirPatches + " among patches dirs " + l, l.contains (filesDirPatches));
92         assertTrue (userDirPatches + " among patches dirs " + l, l.contains (userDirPatches));
93         assertFalse (strangeDirPatches + " is not among patches dirs " + l, l.contains (strangeDirPatches));
94     }
95 }
96
Popular Tags