Exporter { private void exportIdentityCertificate(File baseDir, Consumer consumer) throws IOException { File idcertdir = new File(baseDir.getCanonicalPath(), "upstream_consumer"); idcertdir.mkdir(); IdentityCertificate cert = consumer.getIdCert(); File file = new File(idcertdir.getCanonicalPath(), cert.getSerial().getId() + ".json"); try (FileWriter writer = new FileWriter(file)) { mapper.writeValue(writer, this.translator.translate(cert, CertificateDTO.class)); } } @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 public void exportIdentityCertificate() throws Exception { config.setProperty(ConfigProperties.SYNC_WORK_DIR, "/tmp/"); Rules mrules = mock(Rules.class); Consumer consumer = mock(Consumer.class); Principal principal = mock(Principal.class); 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"); 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); 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(emptyIteratorMock.iterator()).thenReturn(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/upstream_consumer/10.pem", new VerifyIdentityCert("10.pem")); }