KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.*;
23 import java.io.File JavaDoc;
24 import org.netbeans.modules.autoupdate.AbstractTestHid.Lkp;
25
26 public class NbmsTest extends AbstractTestHid {
27     public NbmsTest(String JavaDoc name) {
28         super (name);
29     }
30
31     
32     public void testNBMFileIsGenerated () throws Exception JavaDoc {
33         File JavaDoc f = generateBasicNbm ("3.8");
34
35         ModuleUpdate mu = ModuleUpdate.getModuleUpdate (f);
36         download (mu);
37         installNBM (Downloader.getNBM (mu));
38         
39         
40         Map userFiles = findFiles (userDir);
41         assertNotNull ("Contains x.jar", userFiles.get ("modules/x.jar"));
42         assertNotNull ("Contains y.jar", userFiles.get ("modules/y.jar"));
43         assertNotNull ("Contains update tracking", userFiles.get ("update_tracking/org-openide.xml"));
44         
45         assertEquals ("Empty platform dir", 0, findFiles (platformDir).size ());
46     }
47
48     public void testNBMFileIsInstalledWithNonCanonicalPaths () throws Exception JavaDoc {
49         File JavaDoc f = generateBasicNbm ("3.8");
50
51         ModuleUpdate mu = ModuleUpdate.getModuleUpdate (f);
52         download (mu);
53         
54         File JavaDoc file = Downloader.getNBM (mu);
55         File JavaDoc noncanonical = new File JavaDoc (
56             new File JavaDoc (
57                 new File JavaDoc (file.getParentFile (), ".."),
58                 file.getParentFile ().getName ()
59             ),
60             file.getName ()
61         );
62         assertFalse ("Files are different", noncanonical.equals (file));
63         assertEquals ("But point to the same file", noncanonical.getCanonicalFile (), file.getCanonicalFile ());
64         
65         installNBM (noncanonical);
66         
67         
68         Map userFiles = findFiles (userDir);
69         assertNotNull ("Contains x.jar", userFiles.get ("modules/x.jar"));
70         assertNotNull ("Contains y.jar", userFiles.get ("modules/y.jar"));
71         assertNotNull ("Contains update tracking", userFiles.get ("update_tracking/org-openide.xml"));
72         
73         assertEquals ("Empty platform dir", 0, findFiles (platformDir).size ());
74     }
75     
76     public void testIfUpdateTrackingExistsButNoAutoUpdateFilePresentThenItCannotBeInstalledGlobally () throws Exception JavaDoc {
77         File JavaDoc f = generateBasicNbm ("3.8", Boolean.TRUE, null);
78
79         File JavaDoc update = new File JavaDoc (platformDir, "update_tracking");
80         update.mkdirs ();
81         File JavaDoc noAU = new File JavaDoc(platformDir, ".noautoupdate");
82         noAU.createNewFile();
83
84         ModuleUpdate mu = ModuleUpdate.getModuleUpdate (f);
85
86         assertNull ("Cannot be installed globally", mu.findInstallDirectory ());
87         assertTrue ("We should not be allowed to install", Downloader.bannedWriteToInstall (mu));
88     }
89     
90     public void testIfUpdateTrackingExistsInstallIntoSharedDir () throws Exception JavaDoc {
91         File JavaDoc f = generateBasicNbm ("3.8", Boolean.TRUE, null);
92         
93         File JavaDoc update = new File JavaDoc (platformDir, "update_tracking");
94         update.mkdirs ();
95
96         ModuleUpdate mu = ModuleUpdate.getModuleUpdate (f);
97         
98         assertEquals ("Install globally", platformDir, mu.findInstallDirectory ());
99     }
100     
101     public void testUpdateTrackingExistsNbDirsAsWell () throws Exception JavaDoc {
102         initClusters ();
103         
104         File JavaDoc f = generateBasicNbm ("3.8", Boolean.TRUE, null);
105
106         File JavaDoc update = new File JavaDoc (platformDir, "update_tracking");
107         update.mkdirs ();
108         update = new File JavaDoc (clusterDir, "update_tracking");
109         update.mkdirs ();
110         update = new File JavaDoc (nextDir, "update_tracking");
111         update.mkdirs ();
112
113         ModuleUpdate mu = ModuleUpdate.getModuleUpdate (f);
114         
115         assertEquals (
116             "If the NBM is not installed yet, then it goes to the first " +
117             "netbeans.dir cluster",
118             clusterDir, mu.findInstallDirectory ()
119         );
120         
121         download (mu);
122         
123         File JavaDoc downloadedNbm = Downloader.getNBM (mu);
124         assertTrue ("Downloaded NBM " + downloadedNbm + " exists.", downloadedNbm.exists ());
125         
126         mu.setToInstallDir (true);
127         assertTrue ("Moved to install cluster", Downloader.tryMove (mu));
128         assertTrue (mu.findInstallDirectory ().toString ().endsWith ("clstr"));
129         assertFalse ("Downloaded NBM " + downloadedNbm + " is moved to install dir and removed in user dir.", downloadedNbm.exists ());
130         File JavaDoc movedNbm = Downloader.getMovedNBM (mu);
131         installNBM (movedNbm);
132         
133         
134         assertEquals ("Empty user dir", 0, findFiles (userDir).size ());
135         assertEquals ("Empty platform dir", 0, findFiles (platformDir).size ());
136         
137         Map platFiles = findFiles (clusterDir);
138         assertNotNull ("Contains x.jar", platFiles.get ("modules/x.jar"));
139         assertNotNull ("Contains y.jar", platFiles.get ("modules/y.jar"));
140         assertNotNull ("Contains update tracking", platFiles.get ("update_tracking/org-openide.xml"));
141         
142     }
143
144     public void testCheckWeCannotInstallIntoUserDirIfWeContainSomethingInstalledInCore () throws Exception JavaDoc {
145         doTestInstallToUserDirForPrefix ("core", false, false);
146     }
147     
148     public void testCheckWeCannotInstallIntoUserDirIfWeContainSomethingInstalledInLib () throws Exception JavaDoc {
149         doTestInstallToUserDirForPrefix ("lib", false, false);
150     }
151     
152     public void testDefaultClusterIfInstallGlobally () throws Exception JavaDoc {
153         initClusters ();
154         
155         File JavaDoc f = generateBasicNbm ("3.8", Boolean.TRUE, null);
156         
157         File JavaDoc update = new File JavaDoc (platformDir, "update_tracking");
158         update.mkdirs ();
159         update = new File JavaDoc (clusterDir, "update_tracking");
160         update.mkdirs ();
161         update = new File JavaDoc (nextDir, "update_tracking");
162         update.mkdirs ();
163
164         ModuleUpdate mu = ModuleUpdate.getModuleUpdate (f);
165         assertTrue ("ModuleUpdate is global.", mu.isGlobal ().booleanValue ());
166         
167         assertEquals (
168             "If the NBM is not installed yet, then it goes to the first " +
169             "netbeans.dir cluster",
170             clusterDir, mu.findInstallDirectory ()
171         );
172         
173         download (mu);
174         
175         assertTrue ("Moved to install cluster", Downloader.tryMove (mu));
176         File JavaDoc movedNbm = Downloader.getMovedNBM (mu);
177         installNBM (movedNbm);
178         
179         assertEquals ("Empty user dir", 0, findFiles (userDir).size ());
180         assertEquals ("Empty platform dir", 0, findFiles (platformDir).size ());
181         assertEquals ("Empty next dir", 0, findFiles (nextDir).size ());
182         assertEquals ("Non empty cluster dir", 5, findFiles (clusterDir).size ());
183
184         Map platFiles = findFiles (clusterDir);
185         assertNotNull ("Contains x.jar", platFiles.get ("modules/x.jar"));
186         assertNotNull ("Contains y.jar", platFiles.get ("modules/y.jar"));
187         assertNotNull ("Contains update tracking", platFiles.get ("update_tracking/org-openide.xml"));
188         
189     }
190         
191     public void testDefaultClusterDoesntExist () throws Exception JavaDoc {
192         initClusters ();
193         
194         File JavaDoc f = generateBasicNbm ("3.8", Boolean.TRUE, null);
195         
196         File JavaDoc update = new File JavaDoc (platformDir, "update_tracking");
197         update.mkdirs ();
198         clusterDir.delete ();
199
200         ModuleUpdate mu = ModuleUpdate.getModuleUpdate (f);
201         assertTrue ("ModuleUpdate is global.", mu.isGlobal ().booleanValue ());
202         
203         assertFalse ("Cluster clstr doesn't exist.", clusterDir.exists ());
204         assertEquals (
205             "If the NBM is not installed yet, then it goes to the first " +
206             "netbeans.dir cluster",
207             clusterDir, mu.findInstallDirectory ()
208         );
209         
210         download (mu);
211         
212         assertTrue ("Moved to install cluster", Downloader.tryMove (mu));
213         File JavaDoc movedNbm = Downloader.getMovedNBM (mu);
214         installNBM (movedNbm);
215         
216         assertEquals ("Empty user dir", 0, findFiles (userDir).size ());
217         assertEquals ("Empty platform dir", 0, findFiles (platformDir).size ());
218         assertEquals ("Empty next dir", 0, findFiles (nextDir).size ());
219         assertEquals ("Non empty cluster dir", 5, findFiles (clusterDir).size ());
220
221         Map platFiles = findFiles (clusterDir);
222         assertNotNull ("Contains x.jar", platFiles.get ("modules/x.jar"));
223         assertNotNull ("Contains y.jar", platFiles.get ("modules/y.jar"));
224         assertNotNull ("Contains update tracking", platFiles.get ("update_tracking/org-openide.xml"));
225         
226     }
227         
228     public void testTargetClusterIfInstallGlobally () throws Exception JavaDoc {
229         initClusters ();
230         
231         File JavaDoc f = generateBasicNbm ("3.8", Boolean.TRUE, "nxtclstr");
232         
233         File JavaDoc update = new File JavaDoc (platformDir, "update_tracking");
234         update.mkdirs ();
235         update = new File JavaDoc (clusterDir, "update_tracking");
236         update.mkdirs ();
237         update = new File JavaDoc (nextDir, "update_tracking");
238         update.mkdirs ();
239
240         ModuleUpdate mu = ModuleUpdate.getModuleUpdate (f);
241         assertTrue ("ModuleUpdate is global.", mu.isGlobal ().booleanValue ());
242         
243         assertEquals (
244             "If the NBM is not installed yet, then it goes to the target cluster nxtclstr",
245             nextDir, mu.findInstallDirectory ()
246         );
247         
248         download (mu);
249         
250         assertTrue ("Moved to install cluster", Downloader.tryMove (mu));
251         File JavaDoc movedNbm = Downloader.getMovedNBM (mu);
252         installNBM (movedNbm);
253         
254         assertEquals ("Empty user dir", 0, findFiles (userDir).size ());
255         assertEquals ("Empty platform dir", 0, findFiles (platformDir).size ());
256         assertEquals ("Empty cluster dir", 0, findFiles (clusterDir).size ());
257         assertEquals ("Non empty next dir", 5, findFiles (nextDir).size ());
258
259         Map platFiles = findFiles (nextDir);
260         assertNotNull ("Contains x.jar", platFiles.get ("modules/x.jar"));
261         assertNotNull ("Contains y.jar", platFiles.get ("modules/y.jar"));
262         assertNotNull ("Contains update tracking", platFiles.get ("update_tracking/org-openide.xml"));
263         
264     }
265         
266     public void testTargetClusterIfDeclaredButNotExist () throws Exception JavaDoc {
267         initClusters ();
268         
269         File JavaDoc f = generateBasicNbm ("3.8", Boolean.TRUE, "other1");
270         
271         File JavaDoc update = new File JavaDoc (platformDir, "update_tracking");
272         update.mkdirs ();
273         update = new File JavaDoc (clusterDir, "update_tracking");
274         update.mkdirs ();
275
276         assertFalse (otherDir + " cluster doesn't exist.", otherDir.exists ());
277
278         ModuleUpdate mu = ModuleUpdate.getModuleUpdate (f);
279         assertTrue ("ModuleUpdate is global.", mu.isGlobal ().booleanValue ());
280         
281         assertEquals (
282             "If target cluster doesn't exist but in declared clusters then it goes to " + otherDir + " cluster",
283             otherDir, mu.findInstallDirectory ()
284         );
285         
286         download (mu);
287         
288         assertTrue ("Moved to install cluster", Downloader.tryMove (mu));
289         File JavaDoc movedNbm = Downloader.getMovedNBM (mu);
290         installNBM (movedNbm);
291
292         assertEquals ("Empty user dir", 0, findFiles (userDir).size ());
293         assertEquals ("Empty platform dir", 0, findFiles (platformDir).size ());
294         assertEquals ("Empty cluster dir", 0, findFiles (clusterDir).size ());
295         assertEquals ("Non empty other dir", 5, findFiles (otherDir).size ());
296
297         Map filesInCluster = findFiles (otherDir);
298         assertNotNull ("Contains x.jar", filesInCluster.get ("modules/x.jar"));
299         assertNotNull ("Contains y.jar", filesInCluster.get ("modules/y.jar"));
300         assertNotNull ("Contains update tracking", filesInCluster.get ("update_tracking/org-openide.xml"));
301         
302     }
303         
304     public void testTargetClusterNotDeclaredInClusters () throws Exception JavaDoc {
305         initClusters ();
306         
307         File JavaDoc f = generateBasicNbm ("3.8", Boolean.TRUE, "strange");
308         
309         File JavaDoc update = new File JavaDoc (platformDir, "update_tracking");
310         update.mkdirs ();
311         update = new File JavaDoc (clusterDir, "update_tracking");
312         update.mkdirs ();
313         File JavaDoc strangeDir = new File JavaDoc (getWorkDir (), "strange");
314
315         assertFalse (strangeDir + " cluster doesn't exist.", otherDir.exists ());
316
317         ModuleUpdate mu = ModuleUpdate.getModuleUpdate (f);
318         assertTrue ("ModuleUpdate is global.", mu.isGlobal ().booleanValue ());
319         
320         assertEquals (
321             "If target cluster not among known clusters then it goes to the first " +
322             "netbeans.dir cluster",
323             clusterDir, mu.findInstallDirectory ()
324         );
325         
326         download (mu);
327         
328         assertTrue ("Moved to install cluster", Downloader.tryMove (mu));
329         File JavaDoc movedNbm = Downloader.getMovedNBM (mu);
330         installNBM (movedNbm);
331
332         assertEquals ("Empty user dir", 0, findFiles (userDir).size ());
333         assertEquals ("Empty platform dir", 0, findFiles (platformDir).size ());
334         assertEquals ("Non empty cluster dir", 5, findFiles (clusterDir).size ());
335
336         Map filesInCluster = findFiles (clusterDir);
337         assertNotNull ("Contains x.jar", filesInCluster.get ("modules/x.jar"));
338         assertNotNull ("Contains y.jar", filesInCluster.get ("modules/y.jar"));
339         assertNotNull ("Contains update tracking", filesInCluster.get ("update_tracking/org-openide.xml"));
340         
341     }
342
343     public void testTargetClusterNotDeclaredInClustersButThereIsAClusterCreator() throws Exception JavaDoc {
344         initClusters ();
345         
346         MockClusterCreator mcc = new MockClusterCreator();
347         Lkp.ic.add(mcc);
348         
349         
350         File JavaDoc f = generateBasicNbm ("3.8", Boolean.TRUE, "strange");
351         
352         File JavaDoc update = new File JavaDoc (platformDir, "update_tracking");
353         update.mkdirs ();
354         update = new File JavaDoc (clusterDir, "update_tracking");
355         update.mkdirs ();
356         File JavaDoc strangeDir = new File JavaDoc (getWorkDir (), "strange");
357
358         assertFalse (strangeDir + " cluster doesn't exist.", strangeDir.exists ());
359
360         mcc.expectedCluster = strangeDir;
361         
362         ModuleUpdate mu = ModuleUpdate.getModuleUpdate (f);
363         assertTrue ("ModuleUpdate is global.", mu.isGlobal ().booleanValue ());
364         assertEquals("strange", mu.getTargetCluster());
365         
366         assertEquals (
367             "If the cluster does not exists, our MockClusterCreator is queried about it",
368             strangeDir, mu.findInstallDirectory ()
369         );
370         
371         assertEquals("The findInstallDirectory method called with", "strange", mcc.cluster);
372         assertFalse("Nothing created", mcc.registered);
373         
374         download (mu);
375         
376         mcc.allClusters = new File JavaDoc[] { clusterDir, nextDir, strangeDir, otherDir };
377             
378         assertTrue ("Moved to install cluster", Downloader.tryMove (mu));
379         File JavaDoc movedNbm = Downloader.getMovedNBM (mu);
380         installNBM (movedNbm);
381
382         assertEquals ("Empty user dir", 0, findFiles (userDir).size ());
383         assertEquals ("Empty platform dir", 0, findFiles (platformDir).size ());
384         assertEquals ("Empty cluster dir", 0, findFiles (platformDir).size ());
385         assertEquals ("Non empty strange dir: " + findFiles (strangeDir), 5, findFiles (strangeDir).size ());
386
387         Map filesInCluster = findFiles (strangeDir);
388         assertNotNull ("Contains x.jar", filesInCluster.get ("modules/x.jar"));
389         assertNotNull ("Contains y.jar", filesInCluster.get ("modules/y.jar"));
390         assertNotNull ("Contains update tracking", filesInCluster.get ("update_tracking/org-openide.xml"));
391         
392     }
393     
394     public void testTargetClusterIfApproximatelyDeclared () throws Exception JavaDoc {
395         initClusters ();
396         
397         File JavaDoc f = generateBasicNbm ("3.8", Boolean.TRUE, "other.");
398         
399         File JavaDoc update = new File JavaDoc (platformDir, "update_tracking");
400         update.mkdirs ();
401         update = new File JavaDoc (clusterDir, "update_tracking");
402         update.mkdirs ();
403
404         ModuleUpdate mu = ModuleUpdate.getModuleUpdate (f);
405         assertTrue ("ModuleUpdate is global.", mu.isGlobal ().booleanValue ());
406         
407         assertEquals (
408             "Module with target cluster 'other.' goes to " + otherDir + " cluster",
409             otherDir, mu.findInstallDirectory ()
410         );
411         
412         download (mu);
413         
414         assertTrue ("Moved to install cluster", Downloader.tryMove (mu));
415         File JavaDoc movedNbm = Downloader.getMovedNBM (mu);
416         installNBM (movedNbm);
417
418         assertEquals ("Empty user dir", 0, findFiles (userDir).size ());
419         assertEquals ("Empty platform dir", 0, findFiles (platformDir).size ());
420         assertEquals ("Empty cluster dir", 0, findFiles (clusterDir).size ());
421         assertEquals ("Non empty other dir", 5, findFiles (otherDir).size ());
422
423         Map filesInCluster = findFiles (otherDir);
424         assertNotNull ("Contains x.jar", filesInCluster.get ("modules/x.jar"));
425         assertNotNull ("Contains y.jar", filesInCluster.get ("modules/y.jar"));
426         assertNotNull ("Contains update tracking", filesInCluster.get ("update_tracking/org-openide.xml"));
427         
428     }
429         
430     public void testCheckWeCanInstallIntoUserDirIfWeContainSomethingInstalledInCore () throws Exception JavaDoc {
431         doTestInstallToUserDirForPrefix ("core", true, true);
432     }
433     
434     public void testCheckWeCannotInstallIntoUserDirIfWeWantToInstallInLib () throws Exception JavaDoc {
435         doTestInstallToUserDirForPrefix ("lib", true, false);
436     }
437         
438     private void doTestInstallToUserDirForPrefix (String JavaDoc prefix, boolean newModule, boolean can) throws Exception JavaDoc {
439         File JavaDoc update = new File JavaDoc (platformDir, prefix);
440         update.mkdirs ();
441                 
442         if (! newModule) {
443             File JavaDoc f = new File JavaDoc (update, "dummy.jar");
444             f.createNewFile ();
445         }
446         
447         File JavaDoc f = generateBasicNbmWithFiles (
448             "3.9", // new version
449
new String JavaDoc[] {
450                 "netbeans/" + prefix,
451                 "netbeans/" + prefix + "/dummy.jar"
452             }
453         );
454         ModuleUpdate mu = ModuleUpdate.getModuleUpdate (f);
455         download (mu);
456
457         if (newModule && can) {
458             assertFalse ("By default we need to install to user dir", mu.isToInstallDir ());
459         } else {
460             assertTrue ("By default we need to install to install dir", mu.isToInstallDir ());
461         }
462         try {
463             mu.setToInstallDir (false);
464         } catch (IllegalArgumentException JavaDoc iae) {
465             // can ignore this, Autoupdate in GUI shouldn't set to false when forcedGlobal
466
}
467         assertEquals ("Can change toInstallDir?", can, ! mu.isToInstallDir ());
468     }
469     
470     public void testInstallUpdate () throws Exception JavaDoc {
471         
472         File JavaDoc update = new File JavaDoc (platformDir, "update_tracking");
473         update.mkdirs ();
474         
475         File JavaDoc f = generateBasicNbm ("3.8", Boolean.TRUE, null);
476         ModuleUpdate mu = ModuleUpdate.getModuleUpdate (f);
477         download (mu);
478         
479         assertEquals (
480             "We do not have any clusters, we go into platformDir",
481             platformDir, mu.findInstallDirectory ()
482         );
483         
484         mu.setToInstallDir (true);
485         
486         assertTrue ("Moved to install cluster", Downloader.tryMove (mu));
487         File JavaDoc movedNbm = Downloader.getMovedNBM (mu);
488         installNBM (movedNbm);
489         
490         Map platFiles = findFiles (platformDir);
491         assertNotNull ("Contains x.jar", platFiles.get ("modules/x.jar"));
492         assertNotNull ("Contains y.jar", platFiles.get ("modules/y.jar"));
493         assertNotNull ("Contains update tracking", platFiles.get ("update_tracking/org-openide.xml"));
494         
495         assertEquals ("Empty user dir", 0, findFiles (userDir).size ());
496         
497         
498         update = new File JavaDoc (clusterDir, "update_tracking");
499         update.mkdirs ();
500         update = new File JavaDoc (nextDir, "update_tracking");
501         update.mkdirs ();
502         initClusters ();
503         
504         f = generateBasicNbmWithFiles (
505             "3.9", // new version
506
new String JavaDoc[] {
507                 "netbeans/modules/kuk.jar"
508             }
509         );
510         mu = ModuleUpdate.getModuleUpdate (f);
511         download (mu);
512         mu.setToInstallDir (true);
513         
514         
515         File JavaDoc id = mu.findInstallDirectory ();
516         assertEquals (
517             "If the NBM is installed it will offer override", platformDir, id
518         );
519         
520         assertTrue ("Moved to platform cluster", Downloader.tryMove (mu));
521         movedNbm = Downloader.getMovedNBM (mu);
522         installNBM (movedNbm);
523         
524         platFiles = findFiles (platformDir);
525         assertNull ("No x.jar anymore", platFiles.get ("modules/x.jar"));
526         assertNull ("No y.jar anymore", platFiles.get ("modules/y.jar"));
527         assertNotNull ("Contains update tracking", platFiles.get ("update_tracking/org-openide.xml"));
528         assertNotNull ("kuk.jar is there", platFiles.get ("modules/kuk.jar"));
529         
530         assertEquals ("Empty userdir still", 0, findFiles (userDir).size ());
531         
532         org.netbeans.updater.UpdateTracking ut;
533         ut = org.netbeans.updater.UpdateTracking.getTracking (platformDir, false);
534         String JavaDoc cb = mu.getInfoCodenamebase ();
535         assertTrue ("Installed", ut.isModuleInstalled (cb));
536             
537     }
538     
539     public void testBackupFileInCorrectCluster72960 () throws Exception JavaDoc {
540         initClusters ();
541
542         File JavaDoc f = generateBasicNbm ("3.8", Boolean.TRUE, null);
543         ModuleUpdate mu = ModuleUpdate.getModuleUpdate (f);
544
545         File JavaDoc update = new File JavaDoc (platformDir, "update_tracking");
546         update.mkdirs ();
547         update = new File JavaDoc (clusterDir, "update_tracking");
548         update.mkdirs ();
549         update = new File JavaDoc (nextDir, "update_tracking");
550         update.mkdirs ();
551
552         download (mu);
553
554         assertEquals (
555             "Install into clusterDir",
556             clusterDir, mu.findInstallDirectory ()
557         );
558         
559         mu.setToInstallDir (true);
560         
561         assertTrue ("Moved to install cluster", Downloader.tryMove (mu));
562         File JavaDoc movedNbm = Downloader.getMovedNBM (mu);
563         installNBM (movedNbm);
564         
565         Map clusterFiles = findFiles (clusterDir);
566         assertNotNull ("Contains x.jar", clusterFiles.get ("modules/x.jar"));
567         assertNotNull ("Contains y.jar", clusterFiles.get ("modules/y.jar"));
568         assertNotNull ("Contains update tracking", clusterFiles.get ("update_tracking/org-openide.xml"));
569         
570         assertEquals ("Empty user dir", 0, findFiles (userDir).size ());
571
572         File JavaDoc backupDirInClusterDir = new File JavaDoc (clusterDir, "update/backup");
573         if (! backupDirInClusterDir.isDirectory ()) backupDirInClusterDir.mkdirs ();
574         File JavaDoc backupDirInPlatformDir = new File JavaDoc (platformDir, "update/backup");
575         if (! backupDirInPlatformDir.isDirectory ()) backupDirInPlatformDir.mkdirs ();
576
577         assertEquals ("Empty backup dir in clusterDir", 0, findFiles (backupDirInClusterDir).size ());
578         assertEquals ("Empty backup dir in platformDir", 0, findFiles (backupDirInPlatformDir).size ());
579
580         f = generateBasicNbmWithFiles (
581             "3.9", // new version
582
new String JavaDoc[] {
583                 "netbeans/modules/x.jar"
584             }
585         );
586         mu = ModuleUpdate.getModuleUpdate (f);
587         download (mu);
588         mu.setToInstallDir (true);
589         
590         
591         File JavaDoc id = mu.findInstallDirectory ();
592         assertEquals (
593             "If the NBM is installed it will offer override", clusterDir, id
594         );
595         
596         assertTrue ("Moved to cluster dir", Downloader.tryMove (mu));
597         movedNbm = Downloader.getMovedNBM (mu);
598         installNBM (movedNbm);
599         
600         clusterFiles = findFiles (clusterDir);
601
602         assertEquals ("Empty userdir still", 0, findFiles (userDir).size ());
603
604         assertEquals ("Empty backup dir in platformDir", 0, findFiles (backupDirInPlatformDir).size ());
605         assertEquals ("Backup dir in clusterDir", 1, findFiles (backupDirInClusterDir).size ());
606
607         Map backupFiles = findFiles (backupDirInClusterDir);
608         assertNotNull ("clusterDir contains x.jar", clusterFiles.get ("update/backup/netbeans/modules/x.jar"));
609         assertNotNull ("Backup directory contains x.jar", backupFiles.get ("netbeans/modules/x.jar"));
610
611         org.netbeans.updater.UpdateTracking ut;
612         ut = org.netbeans.updater.UpdateTracking.getTracking (clusterDir, false);
613         String JavaDoc cb = mu.getInfoCodenamebase ();
614         assertTrue ("Installed", ut.isModuleInstalled (cb));
615             
616     }
617     
618     public void testPostInstallCluster72918 () throws Exception JavaDoc {
619         initClusters ();
620
621         File JavaDoc f = generateBasicNbmWithFiles (
622                 "3.8",
623                 new String JavaDoc[] {
624                     "netbeans/modules/x.jar",
625                     "main/Hello.class"
626                 }
627         );
628
629         ModuleUpdate mu = ModuleUpdate.getModuleUpdate (f);
630         mu.setToInstallDir (true);
631
632         File JavaDoc update = new File JavaDoc (platformDir, "update_tracking");
633         update.mkdirs ();
634         update = new File JavaDoc (clusterDir, "update_tracking");
635         update.mkdirs ();
636         update = new File JavaDoc (nextDir, "update_tracking");
637         update.mkdirs ();
638
639         download (mu);
640
641         assertEquals (
642             "Install into clusterDir",
643             clusterDir, mu.findInstallDirectory ()
644         );
645         
646         mu.setToInstallDir (true);
647         
648         assertTrue ("Moved to install cluster", Downloader.tryMove (mu));
649         File JavaDoc movedNbm = Downloader.getMovedNBM (mu);
650         installNBM (movedNbm);
651         
652         assertEquals ("Empty user dir", 0, findFiles (userDir).size ());
653         assertEquals ("Empty platformDir", 0, findFiles (platformDir).size ());
654         
655         Map clusterFiles = findFiles (clusterDir);
656         assertNotNull ("Contains x.jar", clusterFiles.get ("modules/x.jar"));
657         assertNotNull ("Contains Hello.class", clusterFiles.get ("update/main/Hello.class"));
658     }
659     
660     public void testInstallLaterXMLCreatedInSharedDirIssue47077 () throws Exception JavaDoc {
661         initClusters ();
662         
663         File JavaDoc f = generateBasicNbm ("3.8", Boolean.TRUE, null);
664         
665         File JavaDoc update = new File JavaDoc (platformDir, "update_tracking");
666         update.mkdirs ();
667         update = new File JavaDoc (clusterDir, "update_tracking");
668         update.mkdirs ();
669         update = new File JavaDoc (nextDir, "update_tracking");
670         update.mkdirs ();
671
672         ModuleUpdate mu = ModuleUpdate.getModuleUpdate (f);
673         download (mu);
674         mu.setToInstallDir (true);
675         assertTrue ("Moved to platform cluster", Downloader.tryMove (mu));
676         File JavaDoc movedNbm = Downloader.getMovedNBM (mu);
677         
678         PreparedModules.getPrepared().addModule( mu );
679         PreparedModules.getPrepared ().write ();
680         
681         assertEquals ("Empty user dir", 0, findFiles (userDir).size ());
682         assertEquals ("Empty platform dir", 0, findFiles (platformDir).size ());
683         
684         Map platFiles = findFiles (clusterDir);
685         
686         assertNotNull ("Contains install_later.xml", platFiles.get ("update/download/install_later.xml"));
687         
688         if (platFiles.size () != 2) {
689             fail ("Unexcepted files (else than nbm and install_later.xml): " + platFiles);
690         }
691     }
692
693     public void testInstallLaterXMLCreatedIssue47077 () throws Exception JavaDoc {
694         initClusters ();
695         
696         File JavaDoc f = generateBasicNbm ("3.8");
697         
698         File JavaDoc update = new File JavaDoc (platformDir, "update_tracking");
699         update.mkdirs ();
700         update = new File JavaDoc (clusterDir, "update_tracking");
701         update.mkdirs ();
702         update = new File JavaDoc (nextDir, "update_tracking");
703         update.mkdirs ();
704
705         ModuleUpdate mu = ModuleUpdate.getModuleUpdate (f);
706         
707         assertNull ("ModuleUpdate is local.", mu.isGlobal ());
708
709         download (mu);
710         
711         PreparedModules.getPrepared().addModule( mu );
712         PreparedModules.getPrepared ().write ();
713         
714         assertEquals ("Empty cluster dir", 0, findFiles (clusterDir).size ());
715         assertEquals ("Empty platform dir", 0, findFiles (platformDir).size ());
716         
717         Map platFiles = findFiles (userDir);
718         
719         assertNotNull ("Contains install_later.xml", platFiles.get ("update/download/install_later.xml"));
720         
721         if (platFiles.size () != 2) {
722             fail ("Unexcepted files (else than nbm and install_later.xml): " + platFiles);
723         }
724     }
725
726     //
727
// Utilities
728
//
729

730     /** Generates sample basic NBM.
731      * @param revision a number like 4.15
732      */

733     private File JavaDoc generateBasicNbm (String JavaDoc revision) throws Exception JavaDoc {
734         return generateBasicNbm (revision, null, null);
735     }
736
737     private File JavaDoc generateBasicNbm (String JavaDoc revision, Boolean JavaDoc global, String JavaDoc targetcluster) throws Exception JavaDoc {
738         return generateBasicNbmWithFiles (revision, new String JavaDoc[] {
739             "netbeans/modules/x.jar",
740             "netbeans/modules/y.jar",
741             "netbeans/platform5/core/openide.jar"
742         }, global, targetcluster);
743     }
744     
745     /** Generates sample basic NBM.
746      * @param revision a number like 4.15
747      * @param list of files that should be in the NBM
748      */

749     private File JavaDoc generateBasicNbmWithFiles (String JavaDoc revision, String JavaDoc[] fileList) throws Exception JavaDoc {
750         return generateBasicNbmWithFiles (revision, fileList, null, null);
751     }
752
753     private File JavaDoc generateBasicNbmWithFiles (String JavaDoc revision, String JavaDoc[] fileList, Boolean JavaDoc global, String JavaDoc targetcluster) throws Exception JavaDoc {
754         String JavaDoc manifest =
755             "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
756             "<!DOCTYPE module PUBLIC \"-//NetBeans//DTD Autoupdate Module Info 2.4//EN\" \"http://www.netbeans.org/dtds/autoupdate-info-2_4.dtd\">\n" +
757             "<module codenamebase=\"org.openide\"\n" +
758             "homepage=\"http://openide.netbeans.org/\"\n" +
759             "distribution=\"http://www.netbeans.org/download/nbms/40/openide.nbm\"\n" +
760             (global != null ? (global.booleanValue () ? "global=\"true\"\n" : "global=\"false\"\n") : "") +
761             (targetcluster != null ? "targetcluster=\"" + targetcluster + "\"\n" : "") +
762             "license=\"standard-nbm-license.txt\"\n" +
763             "downloadsize=\"0\"\n" +
764             ">\n" +
765             "<manifest OpenIDE-Module=\"org.openide/1\"\n" +
766             "OpenIDE-Module-Display-Category=\"Infrastructure\"\n" +
767             "OpenIDE-Module-Implementation-Version=\"031128\"\n" +
768             "OpenIDE-Module-Long-Description=\"This pseudo-module represents the Open APIs (org.openide.*), which are used by all other NetBeans modules.\"\n" +
769             "OpenIDE-Module-Name=\"Open APIs\"\n" +
770             "OpenIDE-Module-Short-Description=\"The NetBeans Open APIs.\"\n" +
771             "OpenIDE-Module-Specification-Version=\"" + revision + "\"\n" +
772             "/>\n" +
773             "<license name=\"standard-nbm-license.txt\"><![CDATA[This module is part of NetBeans and is open-source.\n" +
774             "You can see http://www.netbeans.org/license.html for details.\n" +
775             "\n" +
776             "You may use the binary however you like. The source file license is:\n" +
777             "\n" +
778             "The Original Code is NetBeans. The Initial Developer of the Original\n" +
779             "Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun\n" +
780             "Microsystems, Inc. All Rights Reserved.\n" +
781             "]]></license>\n" +
782             "</module>\n";
783
784         File JavaDoc f = generateNBM (fileList, manifest);
785         
786         return f;
787     }
788
789     
790     public static final class MockClusterCreator extends AutoupdateClusterCreator {
791
792         File JavaDoc expectedCluster;
793         File JavaDoc[] allClusters;
794         String JavaDoc cluster;
795         boolean registered;
796         
797         public MockClusterCreator() {
798         }
799
800         protected File JavaDoc findCluster(String JavaDoc clusterName) {
801             assertNotNull(expectedCluster);
802             cluster = clusterName;
803             return expectedCluster;
804         }
805
806         protected File JavaDoc[] registerCluster(String JavaDoc clusterName, File JavaDoc f) {
807             assertNotNull(allClusters);
808             assertEquals("Same name", cluster, clusterName);
809             assertEquals("Same dir", expectedCluster, f);
810             registered = true;
811             return allClusters;
812         }
813     }
814 }
815
Popular Tags