Consumer consumer = TestUtil.createConsumer(owner);
ConsumerDto consumerDto = new ConsumerDto(consumer.getUuid(), consumer.getName(),
consumer.getType(), consumer.getOwner(), "", "");
Product parentProduct = TestUtil.createProduct();
ProvidedProduct pp1 = TestUtil.createProvidedProduct();
Set<ProvidedProduct> provided = new HashSet<ProvidedProduct>();
provided.add(pp1);
// Sub product setup
Product subProduct = TestUtil.createProduct();
DerivedProvidedProduct subProvided1 = TestUtil.createSubProvidedProduct();
Set<DerivedProvidedProduct> subProvidedProducts =
new HashSet<DerivedProvidedProduct>();
subProvidedProducts.add(subProvided1);
Pool pool = TestUtil.createPool(owner, parentProduct, provided, subProduct.getId(),
subProvidedProducts, 3);
EntitlementCertificate cert = createEntitlementCertificate("my-test-key",
"my-cert");
Entitlement ent = TestUtil.createEntitlement(owner, consumer, pool, cert);
ent.setQuantity(3);
Reader reader = mock(Reader.class);
when(om.readValue(reader, Entitlement.class)).thenReturn(ent);
// Create our expected products
Map<String, Product> productsById = new HashMap<String, Product>();
productsById.put(parentProduct.getId(), parentProduct);
productsById.put(pp1.getProductId(),
TestUtil.createProduct(pp1.getProductId(), pp1.getProductName()));
productsById.put(subProduct.getId(), subProduct);
productsById.put(subProvided1.getProductId(), TestUtil.createProduct(
subProvided1.getProductId(), subProvided1.getProductName()));
Meta meta = new Meta();
meta.setCdnLabel("test-cdn");
Cdn testCdn = new Cdn("test-cdn",
"Test CDN", "https://test.url.com");
when(cdnCurator.lookupByLabel("test-cdn")).thenReturn(testCdn);
Subscription sub = importer.importObject(om, reader, owner,
productsById, consumerDto, meta);
assertEquals(pool.getId(), sub.getUpstreamPoolId());
assertEquals(consumer.getUuid(), sub.getUpstreamConsumerId());
assertEquals(ent.getId(), sub.getUpstreamEntitlementId());
assertEquals(owner, sub.getOwner());
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, sub.getProduct());
assertEquals(provided.size(), sub.getProvidedProducts().size());
assertEquals(pp1.getProductId(), sub.getProvidedProducts().
iterator().next().getId());
assertEquals(subProduct, sub.getDerivedProduct());
assertEquals(1, sub.getDerivedProvidedProducts().size());
assertEquals(subProvided1.getProductId(), sub.getDerivedProvidedProducts().