EntitlementImporter { public SubscriptionDTO importObject(ObjectMapper mapper, Reader reader, Owner owner, Map<String, ProductDTO> productsById, String consumerUuid, Meta meta) throws IOException, SyncDataFormatException { EntitlementDTO entitlement = mapper.readValue(reader, EntitlementDTO.class); SubscriptionDTO subscription = new SubscriptionDTO(); log.debug("Building subscription for owner: {}", owner); log.debug("Using pool from entitlement: {}", entitlement.getPool()); subscription.setId(Util.generateDbUUID()); subscription.setUpstreamPoolId(entitlement.getPool().getId()); subscription.setUpstreamEntitlementId(entitlement.getId()); subscription.setUpstreamConsumerId(consumerUuid); subscription.setOwner(this.translator.translate(owner, OwnerDTO.class)); subscription.setStartDate(entitlement.getStartDate()); subscription.setEndDate(entitlement.getEndDate()); subscription.setAccountNumber(entitlement.getPool().getAccountNumber()); subscription.setContractNumber(entitlement.getPool().getContractNumber()); subscription.setOrderNumber(entitlement.getPool().getOrderNumber()); subscription.setQuantity(entitlement.getQuantity().longValue()); String cdnLabel = meta.getCdnLabel(); if (!StringUtils.isBlank(cdnLabel)) { Cdn cdn = cdnCurator.getByLabel(cdnLabel); if (cdn != null) { subscription.setCdn(this.translator.translate(cdn, CdnDTO.class)); } } this.associateProducts(productsById, entitlement.getPool(), subscription); Collection<CertificateDTO> certs = entitlement.getCertificates(); if (certs != null && !certs.isEmpty()) { if (certs.size() > 1) { log.error("More than one entitlement certificate found for subscription; using first: {}", subscription); } subscription.setCertificate(certs.iterator().next()); } else { log.error("No entitlement certificate found for subscription: {}", subscription); } return subscription; } EntitlementImporter(CertificateSerialCurator csCurator, CdnCurator cdnCurator, I18n i18n,
        ProductCurator productCurator, EntitlementCurator entitlementCurator, ModelTranslator translator); SubscriptionDTO importObject(ObjectMapper mapper, Reader reader, Owner owner,
        Map<String, ProductDTO> productsById, String consumerUuid, Meta meta); void associateProducts(Map<String, ProductDTO> productsById, PoolDTO upstreamPoolDTO,
        SubscriptionDTO subscription);  }
@Test public void fullImport() throws Exception { Product parentProduct = TestUtil.createProduct(); Product derivedProduct = TestUtil.createProduct(); Product provided1 = TestUtil.createProduct(); Set<Product> providedProducts = new HashSet<>(); providedProducts.add(new Product(provided1)); Product derivedProvided1 = TestUtil.createProduct(); Set<Product> derivedProvidedProducts = new HashSet<>(); derivedProvidedProducts.add(new Product(derivedProvided1)); Pool pool = TestUtil.createPool( owner, parentProduct, new HashSet<>(), derivedProduct, new HashSet<>(), 3); pool.setProvidedProducts(providedProducts); pool.setDerivedProvidedProducts(derivedProvidedProducts); Entitlement ent = TestUtil.createEntitlement(owner, consumer, pool, cert); ent.setQuantity(3); EntitlementDTO dtoEnt = this.translator.translate(ent, EntitlementDTO.class); BrandingDTO brandingDTO = new BrandingDTO(); brandingDTO.setName("brand_name"); brandingDTO.setProductId("eng_id_1"); brandingDTO.setType("OS"); brandingDTO.setId("db_id"); dtoEnt.getPool().addBranding(brandingDTO); when(om.readValue(reader, EntitlementDTO.class)).thenReturn(dtoEnt); Map<String, ProductDTO> productsById = buildProductCache( parentProduct, provided1, derivedProduct, derivedProvided1); SubscriptionDTO sub = importer.importObject( om, reader, owner, productsById, consumerDTO.getUuid(), meta); assertEquals(pool.getId(), sub.getUpstreamPoolId()); assertEquals(consumer.getUuid(), sub.getUpstreamConsumerId()); assertEquals(ent.getId(), sub.getUpstreamEntitlementId()); assertEquals(owner.getKey(), sub.getOwner().getKey()); assertEquals(ent.getStartDate(), sub.getStartDate()); assertEquals(ent.getEndDate(), sub.getEndDate()); assertEquals(pool.getAccountNumber(), sub.getAccountNumber()); assertEquals(pool.getContractNumber(), sub.getContractNumber()); assertEquals(pool.getOrderNumber(), sub.getOrderNumber()); assertEquals(ent.getQuantity().intValue(), sub.getQuantity().intValue()); assertEquals(parentProduct.getId(), sub.getProduct().getId()); assertEquals(providedProducts.size(), sub.getProvidedProducts().size()); assertEquals(provided1.getId(), sub.getProvidedProducts().iterator().next().getId()); assertEquals(derivedProduct.getId(), sub.getDerivedProduct().getId()); assertEquals(1, sub.getDerivedProvidedProducts().size()); assertEquals(derivedProvided1.getId(), sub.getDerivedProvidedProducts().iterator().next().getId()); assertNotNull(sub.getCertificate()); CertificateSerialDTO serial = sub.getCertificate().getSerial(); assertEquals(cert.getSerial().isCollected(), serial.isCollected()); assertEquals(cert.getSerial().getExpiration(), serial.getExpiration()); assertEquals(cert.getSerial().getCreated(), serial.getCreated()); assertEquals(cert.getSerial().getUpdated(), serial.getUpdated()); assertEquals(sub.getCdn().getLabel(), meta.getCdnLabel()); assertEquals(brandingDTO, sub.getProduct().getBranding().toArray()[0]); }