1 19 20 package org.netbeans.modules.autoupdate; 21 22 import java.util.*; 23 import java.io.File ; 24 import org.netbeans.modules.autoupdate.AbstractTestHid.Lkp; 25 26 public class NbmsTest extends AbstractTestHid { 27 public NbmsTest(String name) { 28 super (name); 29 } 30 31 32 public void testNBMFileIsGenerated () throws Exception { 33 File 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 { 49 File f = generateBasicNbm ("3.8"); 50 51 ModuleUpdate mu = ModuleUpdate.getModuleUpdate (f); 52 download (mu); 53 54 File file = Downloader.getNBM (mu); 55 File noncanonical = new File ( 56 new File ( 57 new File (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 { 77 File f = generateBasicNbm ("3.8", Boolean.TRUE, null); 78 79 File update = new File (platformDir, "update_tracking"); 80 update.mkdirs (); 81 File noAU = new File (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 { 91 File f = generateBasicNbm ("3.8", Boolean.TRUE, null); 92 93 File update = new File (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 { 102 initClusters (); 103 104 File f = generateBasicNbm ("3.8", Boolean.TRUE, null); 105 106 File update = new File (platformDir, "update_tracking"); 107 update.mkdirs (); 108 update = new File (clusterDir, "update_tracking"); 109 update.mkdirs (); 110 update = new File (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 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 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 { 145 doTestInstallToUserDirForPrefix ("core", false, false); 146 } 147 148 public void testCheckWeCannotInstallIntoUserDirIfWeContainSomethingInstalledInLib () throws Exception { 149 doTestInstallToUserDirForPrefix ("lib", false, false); 150 } 151 152 public void testDefaultClusterIfInstallGlobally () throws Exception { 153 initClusters (); 154 155 File f = generateBasicNbm ("3.8", Boolean.TRUE, null); 156 157 File update = new File (platformDir, "update_tracking"); 158 update.mkdirs (); 159 update = new File (clusterDir, "update_tracking"); 160 update.mkdirs (); 161 update = new File (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 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 { 192 initClusters (); 193 194 File f = generateBasicNbm ("3.8", Boolean.TRUE, null); 195 196 File update = new File (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 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 { 229 initClusters (); 230 231 File f = generateBasicNbm ("3.8", Boolean.TRUE, "nxtclstr"); 232 233 File update = new File (platformDir, "update_tracking"); 234 update.mkdirs (); 235 update = new File (clusterDir, "update_tracking"); 236 update.mkdirs (); 237 update = new File (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 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 { 267 initClusters (); 268 269 File f = generateBasicNbm ("3.8", Boolean.TRUE, "other1"); 270 271 File update = new File (platformDir, "update_tracking"); 272 update.mkdirs (); 273 update = new File (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 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 { 305 initClusters (); 306 307 File f = generateBasicNbm ("3.8", Boolean.TRUE, "strange"); 308 309 File update = new File (platformDir, "update_tracking"); 310 update.mkdirs (); 311 update = new File (clusterDir, "update_tracking"); 312 update.mkdirs (); 313 File strangeDir = new File (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 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 { 344 initClusters (); 345 346 MockClusterCreator mcc = new MockClusterCreator(); 347 Lkp.ic.add(mcc); 348 349 350 File f = generateBasicNbm ("3.8", Boolean.TRUE, "strange"); 351 352 File update = new File (platformDir, "update_tracking"); 353 update.mkdirs (); 354 update = new File (clusterDir, "update_tracking"); 355 update.mkdirs (); 356 File strangeDir = new File (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 [] { clusterDir, nextDir, strangeDir, otherDir }; 377 378 assertTrue ("Moved to install cluster", Downloader.tryMove (mu)); 379 File 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 { 395 initClusters (); 396 397 File f = generateBasicNbm ("3.8", Boolean.TRUE, "other."); 398 399 File update = new File (platformDir, "update_tracking"); 400 update.mkdirs (); 401 update = new File (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 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 { 431 doTestInstallToUserDirForPrefix ("core", true, true); 432 } 433 434 public void testCheckWeCannotInstallIntoUserDirIfWeWantToInstallInLib () throws Exception { 435 doTestInstallToUserDirForPrefix ("lib", true, false); 436 } 437 438 private void doTestInstallToUserDirForPrefix (String prefix, boolean newModule, boolean can) throws Exception { 439 File update = new File (platformDir, prefix); 440 update.mkdirs (); 441 442 if (! newModule) { 443 File f = new File (update, "dummy.jar"); 444 f.createNewFile (); 445 } 446 447 File f = generateBasicNbmWithFiles ( 448 "3.9", new String [] { 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 iae) { 465 } 467 assertEquals ("Can change toInstallDir?", can, ! mu.isToInstallDir ()); 468 } 469 470 public void testInstallUpdate () throws Exception { 471 472 File update = new File (platformDir, "update_tracking"); 473 update.mkdirs (); 474 475 File 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 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 (clusterDir, "update_tracking"); 499 update.mkdirs (); 500 update = new File (nextDir, "update_tracking"); 501 update.mkdirs (); 502 initClusters (); 503 504 f = generateBasicNbmWithFiles ( 505 "3.9", new String [] { 507 "netbeans/modules/kuk.jar" 508 } 509 ); 510 mu = ModuleUpdate.getModuleUpdate (f); 511 download (mu); 512 mu.setToInstallDir (true); 513 514 515 File 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 cb = mu.getInfoCodenamebase (); 535 assertTrue ("Installed", ut.isModuleInstalled (cb)); 536 537 } 538 539 public void testBackupFileInCorrectCluster72960 () throws Exception { 540 initClusters (); 541 542 File f = generateBasicNbm ("3.8", Boolean.TRUE, null); 543 ModuleUpdate mu = ModuleUpdate.getModuleUpdate (f); 544 545 File update = new File (platformDir, "update_tracking"); 546 update.mkdirs (); 547 update = new File (clusterDir, "update_tracking"); 548 update.mkdirs (); 549 update = new File (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 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 backupDirInClusterDir = new File (clusterDir, "update/backup"); 573 if (! backupDirInClusterDir.isDirectory ()) backupDirInClusterDir.mkdirs (); 574 File backupDirInPlatformDir = new File (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 String [] { 583 "netbeans/modules/x.jar" 584 } 585 ); 586 mu = ModuleUpdate.getModuleUpdate (f); 587 download (mu); 588 mu.setToInstallDir (true); 589 590 591 File 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 cb = mu.getInfoCodenamebase (); 614 assertTrue ("Installed", ut.isModuleInstalled (cb)); 615 616 } 617 618 public void testPostInstallCluster72918 () throws Exception { 619 initClusters (); 620 621 File f = generateBasicNbmWithFiles ( 622 "3.8", 623 new String [] { 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 update = new File (platformDir, "update_tracking"); 633 update.mkdirs (); 634 update = new File (clusterDir, "update_tracking"); 635 update.mkdirs (); 636 update = new File (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 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 { 661 initClusters (); 662 663 File f = generateBasicNbm ("3.8", Boolean.TRUE, null); 664 665 File update = new File (platformDir, "update_tracking"); 666 update.mkdirs (); 667 update = new File (clusterDir, "update_tracking"); 668 update.mkdirs (); 669 update = new File (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 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 { 694 initClusters (); 695 696 File f = generateBasicNbm ("3.8"); 697 698 File update = new File (platformDir, "update_tracking"); 699 update.mkdirs (); 700 update = new File (clusterDir, "update_tracking"); 701 update.mkdirs (); 702 update = new File (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 730 733 private File generateBasicNbm (String revision) throws Exception { 734 return generateBasicNbm (revision, null, null); 735 } 736 737 private File generateBasicNbm (String revision, Boolean global, String targetcluster) throws Exception { 738 return generateBasicNbmWithFiles (revision, new String [] { 739 "netbeans/modules/x.jar", 740 "netbeans/modules/y.jar", 741 "netbeans/platform5/core/openide.jar" 742 }, global, targetcluster); 743 } 744 745 749 private File generateBasicNbmWithFiles (String revision, String [] fileList) throws Exception { 750 return generateBasicNbmWithFiles (revision, fileList, null, null); 751 } 752 753 private File generateBasicNbmWithFiles (String revision, String [] fileList, Boolean global, String targetcluster) throws Exception { 754 String 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 f = generateNBM (fileList, manifest); 785 786 return f; 787 } 788 789 790 public static final class MockClusterCreator extends AutoupdateClusterCreator { 791 792 File expectedCluster; 793 File [] allClusters; 794 String cluster; 795 boolean registered; 796 797 public MockClusterCreator() { 798 } 799 800 protected File findCluster(String clusterName) { 801 assertNotNull(expectedCluster); 802 cluster = clusterName; 803 return expectedCluster; 804 } 805 806 protected File [] registerCluster(String clusterName, File 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 |