Importer { protected ConsumerDTO importConsumer(Owner owner, File consumerFile, File[] upstreamConsumer, ConflictOverrides forcedConflicts, Meta meta) throws IOException, SyncDataFormatException { IdentityCertificate idcert = null; for (File uc : upstreamConsumer) { if (uc.getName().endsWith(".json")) { log.debug("Import upstream consumeridentity certificate: {}", uc.getName()); try (Reader reader = new FileReader(uc)) { CertificateDTO dtoCert = mapper.readValue(reader, CertificateDTO.class); idcert = new IdentityCertificate(); ImporterUtils.populateEntity(idcert, dtoCert); idcert.setId(dtoCert.getId()); } } else { log.warn("Extra file found in upstream_consumer directory: {}", uc.getName()); } } ConsumerImporter importer = new ConsumerImporter(ownerCurator, idCertCurator, i18n, csCurator); Reader reader = null; ConsumerDTO consumer = null; try { reader = new FileReader(consumerFile); consumer = importer.createObject(mapper, reader); ConsumerType type = consumerTypeCurator.getByLabel(consumer.getType().getLabel()); consumer.setType(this.translator.translate(type, ConsumerTypeDTO.class)); if (StringUtils.isEmpty(consumer.getUrlWeb())) { consumer.setUrlWeb(meta.getWebAppPrefix()); } importer.store(owner, consumer, forcedConflicts, idcert); } finally { if (reader != null) { reader.close(); } } return consumer; } @Inject  Importer(ConsumerTypeCurator consumerTypeCurator, ProductCurator productCurator,
        RulesImporter rulesImporter, OwnerCurator ownerCurator, IdentityCertificateCurator idCertCurator,
        ContentCurator contentCurator, PoolManager pm, PKIUtility pki, Configuration config,
        ExporterMetadataCurator emc, CertificateSerialCurator csc, EventSink sink, I18n i18n,
        DistributorVersionCurator distVerCurator, CdnCurator cdnCurator, SyncUtils syncUtils,
        ImportRecordCurator importRecordCurator, SubscriptionReconciler subscriptionReconciler,
        EntitlementCurator entitlementCurator, ContentAccessManager contentAccessManager,
        ModelTranslator translator); ImportRecord loadExport(Owner owner, File archive, ConflictOverrides overrides,
        String uploadedFileName); ImportRecord loadStoredExport(ManifestFile export, Owner owner, ConflictOverrides overrides,
        String uploadedFileName); ImportRecord recordImportSuccess(Owner owner, Map<String, Object> data,
        ConflictOverrides forcedConflicts, String filename); void recordImportFailure(Owner owner, Throwable error, String filename); @SuppressWarnings("checkstyle:methodlength") @Transactional(rollbackOn = {IOException.class, ImporterException.class, RuntimeException.class, ImportConflictException.class}) // WARNING: Keep this method public, otherwise @Transactional is ignored: List<SubscriptionDTO> importObjects(Owner owner, Map<String, File> importFiles,
        ConflictOverrides overrides);  }
@Test public void importConsumer() throws Exception { ConsumerType type = new ConsumerType(ConsumerTypeEnum.CANDLEPIN); type.setId("test-ctype"); this.mockConsumerType(type); File[] upstream = createUpstreamFiles(); Owner owner = new Owner("admin", "Admin Owner"); ConsumerDTO consumerDTO = new ConsumerDTO(); consumerDTO.setUuid("eb5e04bf-be27-44cf-abe3-0c0b1edd523e"); consumerDTO.setName("mymachine"); ConsumerTypeDTO typeDTO = new ConsumerTypeDTO(); typeDTO.setLabel("candlepin"); typeDTO.setManifest(true); consumerDTO.setType(typeDTO); consumerDTO.setUrlWeb("foo.example.com/subscription"); consumerDTO.setUrlApi("/candlepin"); consumerDTO.setContentAccessMode("access_mode"); OwnerDTO ownerDTO = new OwnerDTO(); ownerDTO.setKey("admin"); ownerDTO.setDisplayName("Admin Owner"); consumerDTO.setOwner(ownerDTO); File consumerfile = new File(this.tmpFolder, "consumer.json"); this.mapper.writeValue(consumerfile, consumerDTO); ConflictOverrides forcedConflicts = mock(ConflictOverrides.class); when(forcedConflicts.isForced(any(Importer.Conflict.class))).thenReturn(false); Meta meta = new Meta("1.0", new Date(), "admin", "/candlepin/owners", null); Importer importer = this.buildImporter(); importer.importConsumer(owner, consumerfile, upstream, forcedConflicts, meta); verify(this.mockOwnerCurator).merge(eq(owner)); }