RestoreMetadataTask extends TaskSupport implements Cancelable { @Override protected Void execute() throws Exception { String blobStoreId = checkNotNull(getConfiguration().getString(BLOB_STORE_NAME_FIELD_ID)); boolean dryRun = getConfiguration().getBoolean(DRY_RUN, false); boolean restoreBlobs = getConfiguration().getBoolean(RESTORE_BLOBS, false); boolean undeleteBlobs = getConfiguration().getBoolean(UNDELETE_BLOBS, false); boolean integrityCheck = getConfiguration().getBoolean(INTEGRITY_CHECK, false); restore(blobStoreId, restoreBlobs, undeleteBlobs, dryRun); blobStoreIntegrityCheck(integrityCheck, blobStoreId); return null; } @Inject  RestoreMetadataTask(final BlobStoreManager blobStoreManager,
                             final RepositoryManager repositoryManager,
                             final Map<String, RestoreBlobStrategy> restoreBlobStrategies,
                             final BlobStoreUsageChecker blobStoreUsageChecker,
                             final DryRunPrefix dryRunPrefix,
                             final Map<String, IntegrityCheckStrategy> integrityCheckStrategies,
                             final BucketStore bucketStore,
                             final MaintenanceService maintenanceService); @Override String getMessage();  }
@Test public void testNoRestoreMetadataNoUnDeleteNoIntegrityCheck() throws Exception { configuration.setBoolean(RESTORE_BLOBS, false); configuration.setBoolean(UNDELETE_BLOBS, false); configuration.setBoolean(INTEGRITY_CHECK, false); underTest.configure(configuration); underTest.execute(); verifyZeroInteractions(blobStoreManager); }
@Test public void testIntegrityCheck_BlobStoreDoesNotExist() throws Exception { configuration.setBoolean(RESTORE_BLOBS, false); configuration.setBoolean(UNDELETE_BLOBS, false); configuration.setBoolean(INTEGRITY_CHECK, true); underTest.configure(configuration); when(blobStoreManager.get(anyString())).thenReturn(null); underTest.execute(); verifyZeroInteractions(repositoryManager); }
@Test public void testIntegrityCheck_SkipGroupRepositories() throws Exception { configuration.setBoolean(RESTORE_BLOBS, false); configuration.setBoolean(UNDELETE_BLOBS, false); configuration.setBoolean(INTEGRITY_CHECK, true); underTest.configure(configuration); when(repository.getType()).thenReturn(new GroupType()); when(repositoryManager.browseForBlobStore(any())).thenReturn(singletonList(repository)); underTest.execute(); verifyZeroInteractions(integrityCheckStrategies); }
@Test public void testIntegrityCheck_DefaultStrategy() throws Exception { configuration.setBoolean(RESTORE_BLOBS, false); configuration.setBoolean(UNDELETE_BLOBS, false); configuration.setBoolean(INTEGRITY_CHECK, true); underTest.configure(configuration); when(repositoryManager.browseForBlobStore(any())).thenReturn(singletonList(repository)); when(mavenFormat.getValue()).thenReturn("foo"); underTest.execute(); verify(defaultIntegrityCheckStrategy).check(any(), any(), any(), any()); verifyZeroInteractions(testIntegrityCheckStrategy); }
@Test public void testIntegrityCheck() throws Exception { configuration.setBoolean(RESTORE_BLOBS, false); configuration.setBoolean(UNDELETE_BLOBS, false); configuration.setBoolean(INTEGRITY_CHECK, true); underTest.configure(configuration); when(repositoryManager.browseForBlobStore(any())).thenReturn(singletonList(repository)); underTest.execute(); verifyZeroInteractions(defaultIntegrityCheckStrategy); verify(testIntegrityCheckStrategy).check(eq(repository), eq(fileBlobStore), any(), any()); }
@Test public void updateAfterAssetsWhenCallAfter() throws Exception { configuration.setBoolean(RESTORE_BLOBS, true); configuration.setBoolean(UNDELETE_BLOBS, true); configuration.setBoolean(INTEGRITY_CHECK, false); underTest.configure(configuration); underTest.execute(); verify(restoreBlobStrategy).after(true, repository); }
@Test public void doNotUpdateAfterAssetsWhenDryRun() throws Exception { configuration.setBoolean(RESTORE_BLOBS, true); configuration.setBoolean(UNDELETE_BLOBS, true); configuration.setBoolean(INTEGRITY_CHECK, false); configuration.setBoolean(DRY_RUN, true); underTest.configure(configuration); underTest.execute(); verify(restoreBlobStrategy, never()).after(false, repository); }
@Test public void doNotUpdateAfterAssetsWhenRestoreFalse() throws Exception { configuration.setBoolean(RESTORE_BLOBS, false); configuration.setBoolean(UNDELETE_BLOBS, true); configuration.setBoolean(INTEGRITY_CHECK, false); configuration.setBoolean(DRY_RUN, true); underTest.configure(configuration); underTest.execute(); verify(restoreBlobStrategy, never()).after(false, repository); }
@Test public void whenAfterCallRunningShouldBeCancelable() throws Exception { configuration.setBoolean(RESTORE_BLOBS, true); configuration.setBoolean(UNDELETE_BLOBS, true); configuration.setBoolean(INTEGRITY_CHECK, false); RestoreMetadataTask underTest = new RestoreMetadataTask(blobStoreManager, repositoryManager, ImmutableMap.of("maven2", restoreBlobStrategy), blobstoreUsageChecker, dryRunPrefix, integrityCheckStrategies, bucketStore, maintenanceService) { @Override public boolean isCanceled() { return true; } }; underTest.configure(configuration); underTest.execute(); verify(restoreBlobStrategy, never()).after(true, repository); }
@Test public void whenUnknownFormatAfterCallWillNotRun() throws Exception { when(mavenFormat.getValue()).thenReturn("unknownFormat"); configuration.setBoolean(RESTORE_BLOBS, true); configuration.setBoolean(UNDELETE_BLOBS, true); configuration.setBoolean(INTEGRITY_CHECK, false); underTest.configure(configuration); underTest.execute(); verify(restoreBlobStrategy, never()).after(true, repository); }
@Test public void whenBlobsFromDifferentRepositoriesNeedUpdatingAfterIsCalledForEachRepository() throws Exception { BlobAttributes blobAttributes2 = mock(BlobAttributes.class); Properties properties = mock(Properties.class); Repository repository2 = mock(Repository.class); BlobId blobId2 = new BlobId("86e20baa-0bca-4915-a7dc-9a4f34e72322"); when(fileBlobStore.get(blobId2, true)).thenReturn(blob); when(fileBlobStore.getBlobAttributes(blobId2)).thenReturn(blobAttributes2); when(blobAttributes2.getProperties()).thenReturn(properties); when(properties.getProperty(HEADER_PREFIX + REPO_NAME_HEADER)).thenReturn("maven-central2"); when(repositoryManager.get("maven-central2")).thenReturn(repository2); when(repository2.getFormat()).thenReturn(mavenFormat); when(fileBlobStore.getBlobIdStream()).thenReturn(Stream.of(blobId, blobId2)); configuration.setBoolean(RESTORE_BLOBS, true); configuration.setBoolean(UNDELETE_BLOBS, true); configuration.setBoolean(INTEGRITY_CHECK, false); underTest.configure(configuration); underTest.execute(); verify(restoreBlobStrategy).after(true, repository); verify(restoreBlobStrategy).after(true, repository2); }