ManifestManager { public File generateManifest(String consumerUuid, String cdnLabel, String webUrl, String apiUrl, Map<String, String> extensionData) throws ExportCreationException { log.info("Exporting consumer {}", consumerUuid); Consumer consumer = validateConsumerForExport(consumerUuid, cdnLabel); poolManager.regenerateDirtyEntitlements(consumer); File export = exporter.getFullExport(consumer, cdnLabel, webUrl, apiUrl, extensionData); sink.queueEvent(eventFactory.exportCreated(consumer)); return export; } @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 ensureGenerateManifestRefreshesEnitlements() 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<>(); extData.put("version", "1.0"); List<Entitlement> ents = new ArrayList<>(); when(entitlementCurator.listByConsumer(eq(consumer))).thenReturn(ents); when(consumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid()))).thenReturn(consumer); when(cdnCurator.getByLabel(eq(cdn.getLabel()))).thenReturn(cdn); manager.generateManifest(consumer.getUuid(), cdn.getLabel(), webAppPrefix, apiUrl, extData); verify(exporter).getFullExport(eq(consumer), eq(cdn.getLabel()), eq(webAppPrefix), eq(apiUrl), eq(extData)); }
@Test public void ensureEventSentOnManifestGeneration() 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); when(consumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid()))).thenReturn(consumer); when(cdnCurator.getByLabel(eq(cdn.getLabel()))).thenReturn(cdn); manager.generateManifest(consumer.getUuid(), cdn.getLabel(), webAppPrefix, apiUrl, new HashMap<>()); verify(eventFactory).exportCreated(eq(consumer)); verify(eventSink).queueEvent(eq(event)); }
@Test public void testGenerateManifest() 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); List<Entitlement> ents = new ArrayList<>(); when(entitlementCurator.listByConsumer(eq(consumer))).thenReturn(ents); when(consumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid()))).thenReturn(consumer); when(cdnCurator.getByLabel(eq(cdn.getLabel()))).thenReturn(cdn); File manifestFile = mock(File.class); when(exporter.getFullExport(eq(consumer), eq(cdn.getLabel()), eq(webAppPrefix), eq(apiUrl), eq(extData))).thenReturn(manifestFile); File result = manager.generateManifest(consumer.getUuid(), cdn.getLabel(), webAppPrefix, apiUrl, extData); assertEquals(manifestFile, result); verify(exporter).getFullExport(eq(consumer), eq(cdn.getLabel()), eq(webAppPrefix), eq(apiUrl), eq(extData)); verify(eventFactory).exportCreated(eq(consumer)); verify(eventSink).queueEvent(eq(event)); verifyZeroInteractions(fileService); }
@Test public void verifyConsumerIsDistributorBeforeGeneratingManifest() throws Exception { Consumer consumer = this.createMockConsumer(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.generateManifest(consumer.getUuid(), 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); } }