ManifestManager { 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 { if (export != null) { File workDir = export.getParentFile(); try { FileUtils.deleteDirectory(workDir); } catch (IOException ioe) { } } } } @Inject  ManifestManager(ManifestFileService manifestFileService, Exporter exporter, Importer importer,
        ConsumerCurator consumerCurator, ConsumerTypeCurator consumerTypeCurator,
        EntitlementCurator entitlementCurator, CdnCurator cdnCurator, PoolManager poolManager,
        PrincipalProvider principalProvider, I18n i18n, EventSink eventSink, EventFactory eventFactory); JobConfig generateManifestAsync(String consumerUuid, Owner owner, String cdnLabel,
        String webUrl, String apiUrl, Map<String, String> extensionData); File generateManifest(String consumerUuid, String cdnLabel, String webUrl, String apiUrl,
        Map<String, String> extensionData); JobConfig importManifestAsync(Owner owner, File archive, String uploadedFileName,
        ConflictOverrides overrides); ImportRecord importManifest(Owner owner, File archive, String uploadedFileName,
        ConflictOverrides overrides); void recordImportFailure(Owner owner, Throwable error, String filename); @Transactional ImportRecord importStoredManifest(Owner targetOwner, String fileId, ConflictOverrides overrides,
        String uploadedFileName); @Transactional int cleanup(int maxAgeInMinutes); @Transactional void writeStoredExportToResponse(String exportId, String exportedConsumerUuid,
        HttpServletResponse response); ExportResult generateAndStoreManifest(String consumerUuid, String cdnLabel, String webUrl,
        String apiUrl, Map<String, String> extensionData); @Transactional void deleteStoredManifest(String manifestFileId); File generateEntitlementArchive(Consumer consumer, Set<Long> serials);  }
@Test public void ensureEventSentWhenManifestGeneratedAndStored() throws Exception { Consumer consumer = this.createMockConsumer(true); Cdn cdn = new Cdn("test-cdn", "Test CDN", ""); String webAppPrefix = "webapp-prefix"; String apiUrl = "api-url"; Event event = mock(Event.class); when(eventFactory.exportCreated(eq(consumer))).thenReturn(event); UserPrincipal principal = TestUtil.createOwnerPrincipal(); when(principalProvider.get()).thenReturn(principal); ManifestFile manifest = mock(ManifestFile.class); when(fileService.store(eq(ManifestFileType.EXPORT), nullable(File.class), eq(principal.getName()), any(String.class))).thenReturn(manifest); when(consumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid()))).thenReturn(consumer); when(cdnCurator.getByLabel(eq(cdn.getLabel()))).thenReturn(cdn); manager.generateAndStoreManifest(consumer.getUuid(), cdn.getLabel(), webAppPrefix, apiUrl, new HashMap<>()); verify(eventFactory).exportCreated(eq(consumer)); verify(eventSink).queueEvent(eq(event)); }
@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), nullable(File.class), eq(principal.getName()), any(String.class))).thenReturn(manifest); when(consumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid()))).thenReturn(consumer); when(cdnCurator.getByLabel(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())); }