use of org.candlepin.sync.file.ManifestFile in project candlepin by candlepin.
the class ManifestManagerTest method testWriteStoredExportToResponseFailsWhenManifestFileNotFound.
@Test(expected = NotFoundException.class)
public void testWriteStoredExportToResponseFailsWhenManifestFileNotFound() throws Exception {
HttpServletResponse response = mock(HttpServletResponse.class);
Consumer exportedConsumer = this.createMockConsumer(true);
String manifestId = "124";
ManifestFile manifest = mock(ManifestFile.class);
when(manifest.getTargetId()).thenReturn(exportedConsumer.getUuid());
when(fileService.get(eq(manifestId))).thenReturn(null);
manager.writeStoredExportToResponse(manifestId, exportedConsumer.getUuid(), response);
}
use of org.candlepin.sync.file.ManifestFile in project candlepin by candlepin.
the class ManifestManagerTest method testImportStoredManifest.
@Test
public void testImportStoredManifest() throws Exception {
Owner owner = TestUtil.createOwner();
String fileId = "1234";
String filename = "manifest.zip";
ConflictOverrides overrides = new ConflictOverrides(Conflict.DISTRIBUTOR_CONFLICT);
ManifestFile manifest = mock(ManifestFile.class);
when(manifest.getId()).thenReturn(fileId);
when(fileService.get(eq(fileId))).thenReturn(manifest);
manager.importStoredManifest(owner, fileId, overrides, filename);
verify(importer).loadStoredExport(eq(manifest), eq(owner), eq(overrides), eq(filename));
verify(fileService).delete(fileId);
}
use of org.candlepin.sync.file.ManifestFile in project candlepin by candlepin.
the class ManifestManagerTest method testWriteStoredExportToResponseFailsWhenConsumerIdDoesntMatchManifest.
@Test(expected = BadRequestException.class)
public void testWriteStoredExportToResponseFailsWhenConsumerIdDoesntMatchManifest() throws Exception {
HttpServletResponse response = mock(HttpServletResponse.class);
Consumer exportedConsumer = this.createMockConsumer(true);
String manifestId = "124";
when(consumerCurator.verifyAndLookupConsumer(eq(exportedConsumer.getUuid()))).thenReturn(exportedConsumer);
ManifestFile manifest = mock(ManifestFile.class);
when(manifest.getTargetId()).thenReturn("another-consumer-uuid");
when(fileService.get(eq(manifestId))).thenReturn(manifest);
manager.writeStoredExportToResponse(manifestId, exportedConsumer.getUuid(), response);
}
use of org.candlepin.sync.file.ManifestFile in project candlepin by candlepin.
the class ManifestManager method generateAndStoreManifest.
/**
* Generates a manifest for the specifed consumer and stores the resulting file via the
* {@link ManifestFileService}.
*
* @param consumerUuid the target consumer's UUID.
* @param cdnLabel the CDN label to store in the meta file.
* @param webUrl the URL pointing to the manifest's originating web application.
* @param apiUrl the API URL pointing to the manifest's originating candlepin API.
* @param extensionData data to be passed to the {@link ExportExtensionAdapter} when creating
* a new export of the target consumer.
* @return an {@link ExportResult} containing the details of the stored file.
* @throws ExportCreationException if there are any issues generating the manifest.
*/
public ExportResult generateAndStoreManifest(String consumerUuid, String cdnLabel, String webUrl, String apiUrl, Map<String, String> extensionData) throws ExportCreationException {
Consumer consumer = validateConsumerForExport(consumerUuid, cdnLabel);
File export = null;
try {
poolManager.regenerateDirtyEntitlements(entitlementCurator.listByConsumer(consumer));
export = exporter.getFullExport(consumer, cdnLabel, webUrl, apiUrl, extensionData);
ManifestFile manifestFile = storeExport(export, consumer);
sink.queueEvent(eventFactory.exportCreated(consumer));
return new ExportResult(consumer.getUuid(), manifestFile.getId());
} catch (ManifestFileServiceException e) {
throw new ExportCreationException("Unable to create export archive", e);
} finally {
// We no longer need the export work directory since the archive has been saved in the DB.
if (export != null) {
File workDir = export.getParentFile();
try {
FileUtils.deleteDirectory(workDir);
} catch (IOException ioe) {
// It'll get cleaned up by the ManifestCleanerJob if it couldn't
// be deleted for some reason.
}
}
}
}
use of org.candlepin.sync.file.ManifestFile in project candlepin by candlepin.
the class ManifestManagerTest method testGenerateAndStoreManifest.
@Test
public void testGenerateAndStoreManifest() throws Exception {
Consumer consumer = this.createMockConsumer(true);
Cdn cdn = new Cdn("test-cdn", "Test CDN", "");
String webAppPrefix = "webapp-prefix";
String apiUrl = "api-url";
Map<String, String> extData = new HashMap<>();
Event event = mock(Event.class);
when(eventFactory.exportCreated(eq(consumer))).thenReturn(event);
UserPrincipal principal = TestUtil.createOwnerPrincipal();
when(principalProvider.get()).thenReturn(principal);
String exportId = "export-id";
ManifestFile manifest = mock(ManifestFile.class);
when(manifest.getId()).thenReturn(exportId);
when(fileService.store(eq(ManifestFileType.EXPORT), any(File.class), eq(principal.getName()), any(String.class))).thenReturn(manifest);
when(consumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid()))).thenReturn(consumer);
when(cdnCurator.lookupByLabel(eq(cdn.getLabel()))).thenReturn(cdn);
List<Entitlement> ents = new ArrayList<>();
when(entitlementCurator.listByConsumer(eq(consumer))).thenReturn(ents);
ExportResult result = manager.generateAndStoreManifest(consumer.getUuid(), cdn.getLabel(), webAppPrefix, apiUrl, extData);
assertEquals(consumer.getUuid(), result.getExportedConsumer());
assertEquals(exportId, result.getExportId());
verify(entitlementCurator).listByConsumer(eq(consumer));
verify(exporter).getFullExport(eq(consumer), eq(cdn.getLabel()), eq(webAppPrefix), eq(apiUrl), eq(extData));
verify(eventFactory).exportCreated(eq(consumer));
verify(eventSink).queueEvent(eq(event));
verify(fileService).delete(eq(ManifestFileType.EXPORT), eq(consumer.getUuid()));
}
Aggregations