Exporter { public File getFullExport(Consumer consumer, String cdnLabel, String webUrl, String apiUrl, Map<String, String> extensionData) throws ExportCreationException { try { File tmpDir = syncUtils.makeTempDir("export"); File baseDir = new File(tmpDir.getAbsolutePath(), "export"); baseDir.mkdir(); exportMeta(baseDir, cdnLabel); exportConsumer(baseDir, consumer, webUrl, apiUrl); exportIdentityCertificate(baseDir, consumer); exportEntitlements(baseDir, consumer); exportEntitlementsCerts(baseDir, consumer, null, true); exportProducts(baseDir, consumer); exportConsumerTypes(baseDir); exportRules(baseDir); exportDistributorVersions(baseDir); exportContentDeliveryNetworks(baseDir); exportExtensionData(baseDir, consumer, extensionData); return makeArchive(consumer, tmpDir, baseDir); } catch (IOException e) { log.error("Error generating entitlement export", e); throw new ExportCreationException("Unable to create export archive", e); } } @Inject  Exporter(ConsumerTypeCurator consumerTypeCurator, OwnerCurator ownerCurator, MetaExporter meta,
        ConsumerExporter consumerExporter, ConsumerTypeExporter consumerType,
        RulesExporter rules, EntitlementCertExporter entCert,
        EntitlementCertServiceAdapter entCertAdapter, ProductExporter productExporter,
        ProductServiceAdapter productAdapter, ProductCertExporter productCertExporter,
        EntitlementCurator entitlementCurator, EntitlementExporter entExporter,
        PKIUtility pki, Configuration config, ExportRules exportRules,
        PrincipalProvider principalProvider, DistributorVersionCurator distVerCurator,
        DistributorVersionExporter distVerExporter,
        CdnCurator cdnCurator,
        CdnExporter cdnExporter,
        ProductCurator productCurator,
        SyncUtils syncUtils, ExportExtensionAdapter extensionAdapter,
        ModelTranslator translator); File getFullExport(Consumer consumer, String cdnLabel, String webUrl,
        String apiUrl, Map<String, String> extensionData); File getEntitlementExport(Consumer consumer, Set<Long> serials);  }
@Test(expected = ExportCreationException.class) public void doNotExportDirtyEntitlements() throws Exception { config.setProperty(ConfigProperties.SYNC_WORK_DIR, "/tmp/"); Consumer consumer = mock(Consumer.class); Entitlement ent = mock(Entitlement.class); Principal principal = mock(Principal.class); IdentityCertificate idcert = new IdentityCertificate(); List<Entitlement> entitlements = new ArrayList<>(); entitlements.add(ent); when(pki.getSHA256WithRSAHash(any(InputStream.class))).thenReturn( "signature".getBytes()); when(pprov.get()).thenReturn(principal); when(principal.getUsername()).thenReturn("testUser"); when(ec.listByConsumer(consumer)).thenReturn(entitlements); when(ent.isDirty()).thenReturn(true); idcert.setSerial(new CertificateSerial(10L, new Date())); idcert.setKey("euh0876puhapodifbvj094"); idcert.setCert("hpj-08ha-w4gpoknpon*)&^%#"); idcert.setCreated(new Date()); idcert.setUpdated(new Date()); when(consumer.getIdCert()).thenReturn(idcert); KeyPair keyPair = createKeyPair(); when(consumer.getKeyPair()).thenReturn(keyPair); when(pki.getPemEncoded(keyPair.getPrivateKey())).thenReturn("privateKey".getBytes()); CandlepinQuery cqmock = mock(CandlepinQuery.class); when(cqmock.iterator()).thenReturn(Arrays.asList(new ConsumerType("system")).iterator()); when(ctc.listAll()).thenReturn(cqmock); Exporter e = new Exporter(ctc, oc, me, ce, cte, re, ece, ecsa, pe, psa, pce, ec, ee, pki, config, exportRules, pprov, dvc, dve, cdnc, cdne, pc, su, exportExtensionAdapter, translator); e.getFullExport(consumer, null, null, null, new HashMap<>()); }
@Test public void exportMetadata() throws ExportCreationException, IOException { config.setProperty(ConfigProperties.SYNC_WORK_DIR, "/tmp/"); Date start = new Date(); Rules mrules = mock(Rules.class); Consumer consumer = mock(Consumer.class); Principal principal = mock(Principal.class); IdentityCertificate idcert = new IdentityCertificate(); when(mrules.getRules()).thenReturn("foobar"); when(pki.getSHA256WithRSAHash(any(InputStream.class))).thenReturn("signature".getBytes()); when(rc.getRules()).thenReturn(mrules); when(pprov.get()).thenReturn(principal); when(principal.getUsername()).thenReturn("testUser"); idcert.setSerial(new CertificateSerial(10L, new Date())); idcert.setKey("euh0876puhapodifbvj094"); idcert.setCert("hpj-08ha-w4gpoknpon*)&^%#"); idcert.setCreated(new Date()); idcert.setUpdated(new Date()); when(consumer.getIdCert()).thenReturn(idcert); KeyPair keyPair = createKeyPair(); when(consumer.getKeyPair()).thenReturn(keyPair); when(pki.getPemEncoded(keyPair.getPrivateKey())).thenReturn("privateKey".getBytes()); CandlepinQuery cqmock = mock(CandlepinQuery.class); when(cqmock.iterator()).thenReturn(Arrays.asList(new ConsumerType("system")).iterator()); when(ctc.listAll()).thenReturn(cqmock); CandlepinQuery emptyIteratorMock = mock(CandlepinQuery.class); when(emptyIteratorMock.iterate()).thenReturn(new MockResultIterator(Arrays.asList().iterator())); when(cdnc.listAll()).thenReturn(emptyIteratorMock); Exporter e = new Exporter(ctc, oc, me, ce, cte, re, ece, ecsa, pe, psa, pce, ec, ee, pki, config, exportRules, pprov, dvc, dve, cdnc, cdne, pc, su, exportExtensionAdapter, translator); File export = e.getFullExport(consumer, null, null, null, new HashMap<>()); assertNotNull(export); assertTrue(export.exists()); verifyContent(export, "export/meta.json", new VerifyMetadata(start)); FileUtils.deleteDirectory(export.getParentFile()); assertTrue(new File("/tmp/consumer_export.zip").delete()); assertTrue(new File("/tmp/meta.json").delete()); }
@Test public void verifyExportExtension() throws Exception { CandlepinQuery emptyIteratorMock = mock(CandlepinQuery.class); when(emptyIteratorMock.iterate()).thenReturn(new MockResultIterator(Arrays.asList().iterator())); when(emptyIteratorMock.iterator()).thenReturn(Arrays.asList().iterator()); when(cdnc.listAll()).thenReturn(emptyIteratorMock); when(ctc.listAll()).thenReturn(emptyIteratorMock); Map<String, String> extensionData = new HashMap<>(); Exporter e = new Exporter(ctc, oc, me, ce, cte, re, ece, ecsa, pe, psa, pce, ec, ee, pki, config, exportRules, pprov, dvc, dve, cdnc, cdne, pc, su, exportExtensionAdapter, translator); Principal principal = mock(Principal.class); when(pprov.get()).thenReturn(principal); when(principal.getUsername()).thenReturn("testUser"); Consumer consumer = mock(Consumer.class); Rules mrules = mock(Rules.class); when(mrules.getRules()).thenReturn("foobar"); when(pki.getSHA256WithRSAHash(any(InputStream.class))).thenReturn("signature".getBytes()); when(rc.getRules()).thenReturn(mrules); IdentityCertificate idcert = new IdentityCertificate(); idcert.setSerial(new CertificateSerial(10L, new Date())); idcert.setKey("euh0876puhapodifbvj094"); idcert.setCert("hpj-08ha-w4gpoknpon*)&^%#"); idcert.setCreated(new Date()); idcert.setUpdated(new Date()); when(consumer.getIdCert()).thenReturn(idcert); e.getFullExport(consumer, "cdn-key", "webapp-prefix", "api-url", extensionData); verify(exportExtensionAdapter).extendManifest(any(File.class), eq(consumer), eq(extensionData)); }