UpdateDatabase implements ProgressTask<PackageListUpdateReport> { @Override public PackageListUpdateReport execute(ProgressReceiver progressReceiver) { final PackageListDownloader packageListDownloader = new PackageListDownloader(configuration, downloadManager); final PackageListUpdateReport report = new PackageListUpdateReport(); for (Source source : sourcesList.getSources()) { if (!source.isEnabled()) { LOG.info("Disabled source {} skipped.", source); continue; } updateProgress(progressReceiver, source); final LocalPackageList localPackageList = packageListDownloader.download(source, progressReceiver); List<Package> parsePackagesList = parsePackagesList(localPackageList).collect(Collectors.toList()); parsePackagesList.forEach((pkg) -> processPackage(source, pkg, report)); List<Package> outdatedPackages = collectOutdatedPackages(source, parsePackagesList); outdatedPackages.forEach(existingPkg -> { if (existingPkg.isInstalled()) { LOG.warn("Keep existing {} installed, but {} doesn't provide it anymore.", existingPkg.toStringWithNameAndVersion(), source); } else { LOG.info("Deleting existing {}, because {} doesn't provide it anymore.", existingPkg.toStringWithNameAndVersion(), source); db.getPackageRepository().delete(existingPkg); report.incRemoved(); } }); source.setLastUpdated(LocalDateTime.now()); db.getSourceRepository().save(source); } return report; } UpdateDatabase(PackageManagerConfiguration configuration, SourcesList sourcesList, PackageManagerDatabase db, DownloadManager downloadManager); @Override ProgressTaskDescription getDescription(Locale locale); @Override PackageListUpdateReport execute(ProgressReceiver progressReceiver);  }
@Test public void testUpdatePackages() { UpdateDatabase updater = createUpdateDatabase(); updater.execute(new NoopProgressReceiver()); assertEquals(PACKAGES_SIZE, packageRepository.count()); Optional<Package> zonkDev = packageRepository.findAll().stream().filter(p -> p.getName().equals("zonk-dev")).findFirst(); if (zonkDev.isPresent()) { String changeLog = zonkDev.get().getChangeLog(); assertTrue(StringUtils.isNotBlank(changeLog)); assertTrue(changeLog.contains("zonk-dev (2.0-1)")); assertTrue(changeLog.contains("Fixed something")); assertTrue(changeLog.contains("Mon, 28 Nov 2016 12:12:30 +0100")); assertFalse(changeLog.contains("zonk-dev (2.0-7)")); assertFalse(changeLog.contains("copy requested profile from skel")); assertFalse(changeLog.contains("Wed, 18 Jan 2017 02:02:30 +0100")); String license = zonkDev.get().getLicense(); assertNotNull("Expected a license value.", license); assertTrue(license.contains("Grundfunktionen und zahlreiche Anwendungen")); } else { fail("Expected package 'zonk-dev' not found, cannot test changelog entries."); } updater = new UpdateDatabase(configuration, getSourcesList(), db, downloadManager); updater.execute(new NoopProgressReceiver()); assertEquals(PACKAGES_SIZE, packageRepository.count()); }
@Test public void testUpdateWithRepositoryContainingAdditionalVersion() { testRepositoryServer.setRepository("test-repository_versioning/repo01"); UpdateDatabase updater = createUpdateDatabase(); updater.execute(new NoopProgressReceiver()); assertEquals(1, packageRepository.count()); final Package pkgBeforeUpdate = packageRepository.findAll().get(0); assertEquals("foo", pkgBeforeUpdate.getName()); assertEquals(Version.parse("2.0-1"), pkgBeforeUpdate.getVersion()); testRepositoryServer.setRepository("test-repository_versioning/repo02"); updater.execute(new NoopProgressReceiver()); assertEquals(2, packageRepository.count()); }
@Test public void testUpdateMultipleTimesWithoutChanges() { testRepositoryServer.setRepository("test-repository_versioning/repo01"); UpdateDatabase updater = createUpdateDatabase(); updater.execute(new NoopProgressReceiver()); assertEquals(1, packageRepository.count()); final Package pkgBeforeUpdate = packageRepository.findAll().get(0); assertEquals("foo", pkgBeforeUpdate.getName()); assertEquals(Version.parse("2.0-1"), pkgBeforeUpdate.getVersion()); updater.execute(new NoopProgressReceiver()); assertEquals(1, packageRepository.count()); updater.execute(new NoopProgressReceiver()); assertEquals(1, packageRepository.count()); }
@Test public void testUpdateWithoutChangesOfThePackageMetadata() { testRepositoryServer.setRepository("test-repository_versioning/repo01"); UpdateDatabase updater = createUpdateDatabase(); PackageListUpdateReport report = updater.execute(new NoopProgressReceiver()); assertEquals(1, packageRepository.count()); assertEquals(1, report.getAdded()); assertEquals(0, report.getUpdated()); assertEquals(0, report.getSkipped()); assertEquals(0, report.getRemoved()); final Package pkgBeforeUpdate = packageRepository.findAll().get(0); assertEquals("foo", pkgBeforeUpdate.getName()); assertEquals(Version.parse("2.0-1"), pkgBeforeUpdate.getVersion()); assertEquals("Lars Behrens <lbehrens@unknown>", pkgBeforeUpdate.getMaintainer()); assertEquals("<insert up to 60 chars description>", pkgBeforeUpdate.getShortDescription()); testRepositoryServer.setRepository("test-repository_versioning/repo01.1"); report = updater.execute(new NoopProgressReceiver()); assertEquals(1, packageRepository.count()); assertEquals(0, report.getAdded()); assertEquals(1, report.getUpdated()); assertEquals(0, report.getSkipped()); assertEquals(0, report.getRemoved()); final Package pkgAfterUpdate = packageRepository.findAll().get(0); assertEquals("The New Maintainer <someone@else.com>", pkgAfterUpdate.getMaintainer()); assertEquals("This now has a short description", pkgAfterUpdate.getShortDescription()); report = updater.execute(new NoopProgressReceiver()); assertEquals(1, packageRepository.count()); assertEquals(0, report.getAdded()); assertEquals(0, report.getUpdated()); assertEquals(1, report.getSkipped()); assertEquals(0, report.getRemoved()); }
@Test public void testUpdateWithVersionChanges() { testRepositoryServer.setRepository("test-repository_versioning/repo01"); UpdateDatabase updater = createUpdateDatabase(); updater.execute(new NoopProgressReceiver()); assertEquals(1, packageRepository.count()); final Package pkgBeforeUpdate = packageRepository.findAll().get(0); assertEquals("foo", pkgBeforeUpdate.getName()); assertEquals(Version.parse("2.0-1"), pkgBeforeUpdate.getVersion()); testRepositoryServer.setRepository("test-repository_versioning/repo03"); updater.execute(new NoopProgressReceiver()); assertEquals(1, packageRepository.count()); final Package pkgAfterUpdate = packageRepository.findAll().get(0); assertEquals("foo", pkgAfterUpdate.getName()); assertEquals(Version.parse("2.1-1"), pkgAfterUpdate.getVersion()); }