ManifestManager { public JobConfig generateManifestAsync(String consumerUuid, Owner owner, String cdnLabel, String webUrl, String apiUrl, Map<String, String> extensionData) { log.info("Scheduling Async Export for consumer {}", consumerUuid); Consumer consumer = validateConsumerForExport(consumerUuid, cdnLabel); return ExportJob.createJobConfig() .setConsumer(consumer) .setOwner(owner) .setCdnLabel(cdnLabel) .setWebAppPrefix(webUrl) .setApiUrl(apiUrl) .setExtensionData(extensionData); } @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 ensureGenerateAsyncManifestDoesNotRefreshEntitlementsBeforeStartingJob() throws Exception { Owner owner = TestUtil.createOwner(); Consumer consumer = this.createMockConsumer(owner, true); Cdn cdn = new Cdn("test-cdn", "Test CDN", ""); String webAppPrefix = "webapp-prefix"; String apiUrl = "api-url"; when(consumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid()))).thenReturn(consumer); when(cdnCurator.getByLabel(eq(cdn.getLabel()))).thenReturn(cdn); manager.generateManifestAsync(consumer.getUuid(), owner, cdn.getLabel(), webAppPrefix, apiUrl, new HashMap<>()); verify(poolManager, never()).regenerateDirtyEntitlements(anyCollection()); }
@Test public void verifyConsumerIsDistributorBeforeSchedulingManifestGeneration() throws Exception { Owner owner = TestUtil.createOwner(); Consumer consumer = this.createMockConsumer(owner, false); ConsumerType ctype = consumerTypeCurator.getConsumerType(consumer); Cdn cdn = new Cdn("test-cdn", "Test CDN", ""); String webAppPrefix = "webapp-prefix"; String apiUrl = "api-url"; Map<String, String> extData = new HashMap<>(); when(consumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid()))).thenReturn(consumer); when(cdnCurator.getByLabel(eq(cdn.getLabel()))).thenReturn(cdn); try { manager.generateManifestAsync(consumer.getUuid(), owner, cdn.getLabel(), webAppPrefix, apiUrl, extData); fail("Expected ForbiddenException not thrown"); } catch (Exception e) { assertTrue(e instanceof ForbiddenException); String expectedMsg = String.format("Unit %s cannot be exported. A manifest cannot be made for " + "units of type \"%s\".", consumer.getUuid(), ctype.getLabel()); assertEquals(e.getMessage(), expectedMsg); } }
@Test public void verifyCdnExistsBeforeGeneratingManifest() throws Exception { Owner owner = TestUtil.createOwner(); Consumer consumer = this.createMockConsumer(owner, true); Cdn cdn = new Cdn("test-cdn", "Test CDN", ""); String webAppPrefix = "webapp-prefix"; String apiUrl = "api-url"; Map<String, String> extData = new HashMap<>(); when(consumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid()))).thenReturn(consumer); when(cdnCurator.getByLabel(eq(cdn.getLabel()))).thenReturn(null); try { manager.generateManifestAsync(consumer.getUuid(), owner, cdn.getLabel(), webAppPrefix, apiUrl, extData); fail("Expected ForbiddenException not thrown"); } catch (Exception e) { assertTrue(e instanceof ForbiddenException); String expectedMsg = String.format("A CDN with label %s does not exist on this system.", cdn.getLabel()); assertEquals(e.getMessage(), expectedMsg); } }
@Test public void verifyCdnExistsBeforeSchedulingManifestGeneration() throws Exception { Owner owner = TestUtil.createOwner(); Consumer consumer = this.createMockConsumer(owner, true); Cdn cdn = new Cdn("test-cdn", "Test CDN", ""); String webAppPrefix = "webapp-prefix"; String apiUrl = "api-url"; Map<String, String> extData = new HashMap<>(); when(consumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid()))).thenReturn(consumer); when(cdnCurator.getByLabel(eq(cdn.getLabel()))).thenReturn(null); try { manager.generateManifestAsync(consumer.getUuid(), owner, cdn.getLabel(), webAppPrefix, apiUrl, extData); fail("Expected ForbiddenException not thrown"); } catch (Exception e) { assertTrue(e instanceof ForbiddenException); String expectedMsg = String.format("A CDN with label %s does not exist on this system.", cdn.getLabel()); assertEquals(e.getMessage(), expectedMsg); } }