Search in sources :

Example 11 with Subscription

use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.

the class OwnerResourceTest method testRefreshPoolsWithChangedSubscriptions.

@Test
public void testRefreshPoolsWithChangedSubscriptions() {
    Product prod = this.createProduct(owner);
    Pool pool = createPool(owner, prod, 1000L, TestUtil.createDate(2009, 11, 30), TestUtil.createDate(2015, 11, 30));
    List<Subscription> subscriptions = new LinkedList<>();
    ImportSubscriptionServiceAdapter subAdapter = new ImportSubscriptionServiceAdapter(subscriptions);
    OwnerServiceAdapter ownerAdapter = new DefaultOwnerServiceAdapter(this.ownerCurator, this.i18n);
    Subscription sub = TestUtil.createSubscription(owner, prod, new HashSet<>());
    sub.setId(Util.generateDbUUID());
    sub.setQuantity(2000L);
    sub.setStartDate(TestUtil.createDate(2010, 2, 9));
    sub.setEndDate(TestUtil.createDate(3000, 2, 9));
    sub.setModified(TestUtil.createDate(2010, 2, 12));
    subscriptions.add(sub);
    assertTrue(pool.getQuantity() < sub.getQuantity());
    assertTrue(pool.getStartDate() != sub.getStartDate());
    assertTrue(pool.getEndDate() != sub.getEndDate());
    pool.getSourceSubscription().setSubscriptionId(sub.getId());
    poolCurator.merge(pool);
    poolManager.getRefresher(subAdapter, ownerAdapter).add(owner).run();
    pool = poolCurator.find(pool.getId());
    assertEquals(sub.getId(), pool.getSubscriptionId());
    assertEquals(sub.getQuantity(), pool.getQuantity());
    assertEquals(sub.getStartDate(), pool.getStartDate());
    assertEquals(sub.getEndDate(), pool.getEndDate());
}
Also used : ImportSubscriptionServiceAdapter(org.candlepin.service.impl.ImportSubscriptionServiceAdapter) OwnerServiceAdapter(org.candlepin.service.OwnerServiceAdapter) DefaultOwnerServiceAdapter(org.candlepin.service.impl.DefaultOwnerServiceAdapter) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Subscription(org.candlepin.model.dto.Subscription) LinkedList(java.util.LinkedList) DefaultOwnerServiceAdapter(org.candlepin.service.impl.DefaultOwnerServiceAdapter) Test(org.junit.Test)

Example 12 with Subscription

use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.

the class OwnerResourceTest method testRefreshPoolsWithRemovedMasterPool.

// test covers scenario from bug 1012386
@Test
public void testRefreshPoolsWithRemovedMasterPool() {
    Product prod = this.createProduct(owner);
    prod.setAttribute(Product.Attributes.VIRT_LIMIT, "4");
    productCurator.merge(prod);
    config.setProperty(ConfigProperties.STANDALONE, "false");
    List<Subscription> subscriptions = new LinkedList<>();
    ImportSubscriptionServiceAdapter subAdapter = new ImportSubscriptionServiceAdapter(subscriptions);
    OwnerServiceAdapter ownerAdapter = new DefaultOwnerServiceAdapter(this.ownerCurator, this.i18n);
    Subscription sub = TestUtil.createSubscription(owner, prod, new HashSet<>());
    sub.setId(Util.generateDbUUID());
    sub.setQuantity(2000L);
    sub.setStartDate(TestUtil.createDate(2010, 2, 9));
    sub.setEndDate(TestUtil.createDate(3000, 2, 9));
    sub.setModified(TestUtil.createDate(2010, 2, 12));
    subscriptions.add(sub);
    // Trigger the refresh:
    poolManager.getRefresher(subAdapter, ownerAdapter).add(owner).run();
    List<Pool> pools = poolCurator.lookupBySubscriptionId(owner, sub.getId());
    assertEquals(2, pools.size());
    String bonusId = "";
    String masterId = "";
    for (Pool p : pools) {
        if (p.getSourceSubscription().getSubscriptionSubKey().equals("master")) {
            poolCurator.delete(p);
            masterId = p.getId();
        } else {
            bonusId = p.getId();
        }
    }
    // Trigger the refresh:
    poolManager.getRefresher(subAdapter, ownerAdapter).add(owner).run();
    assertNull("Original Master Pool should be gone", poolCurator.find(masterId));
    assertNotNull("Bonus Pool should be the same", poolCurator.find(bonusId));
    // master pool should have been recreated
    pools = poolCurator.lookupBySubscriptionId(owner, sub.getId());
    assertEquals(2, pools.size());
    boolean newMaster = false;
    for (Pool p : pools) {
        if (p.getSourceSubscription().getSubscriptionSubKey().equals("master")) {
            newMaster = true;
        }
    }
    assertTrue(newMaster);
}
Also used : ImportSubscriptionServiceAdapter(org.candlepin.service.impl.ImportSubscriptionServiceAdapter) OwnerServiceAdapter(org.candlepin.service.OwnerServiceAdapter) DefaultOwnerServiceAdapter(org.candlepin.service.impl.DefaultOwnerServiceAdapter) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Matchers.anyString(org.mockito.Matchers.anyString) Subscription(org.candlepin.model.dto.Subscription) LinkedList(java.util.LinkedList) DefaultOwnerServiceAdapter(org.candlepin.service.impl.DefaultOwnerServiceAdapter) Test(org.junit.Test)

Example 13 with Subscription

use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.

the class OwnerResourceTest method testRefreshPoolsWithRemovedBonusPool.

// test covers a corollary scenario from bug 1012386
@Test
public void testRefreshPoolsWithRemovedBonusPool() {
    Product prod = this.createProduct(owner);
    prod.setAttribute(Product.Attributes.VIRT_LIMIT, "4");
    productCurator.merge(prod);
    config.setProperty(ConfigProperties.STANDALONE, "false");
    List<Subscription> subscriptions = new LinkedList<>();
    ImportSubscriptionServiceAdapter subAdapter = new ImportSubscriptionServiceAdapter(subscriptions);
    OwnerServiceAdapter ownerAdapter = new DefaultOwnerServiceAdapter(this.ownerCurator, this.i18n);
    Subscription sub = TestUtil.createSubscription(owner, prod, new HashSet<>());
    sub.setId(Util.generateDbUUID());
    sub.setQuantity(2000L);
    sub.setStartDate(TestUtil.createDate(2010, 2, 9));
    sub.setEndDate(TestUtil.createDate(3000, 2, 9));
    sub.setModified(TestUtil.createDate(2010, 2, 12));
    subscriptions.add(sub);
    // Trigger the refresh:
    poolManager.getRefresher(subAdapter, ownerAdapter).add(owner).run();
    List<Pool> pools = poolCurator.lookupBySubscriptionId(owner, sub.getId());
    assertEquals(2, pools.size());
    String bonusId = "";
    String masterId = "";
    for (Pool p : pools) {
        if (p.getSourceSubscription().getSubscriptionSubKey().equals("derived")) {
            poolCurator.delete(p);
            bonusId = p.getId();
        } else {
            masterId = p.getId();
        }
    }
    // Trigger the refresh:
    poolManager.getRefresher(subAdapter, ownerAdapter).add(owner).run();
    assertNull("Original bonus pool should be gone", poolCurator.find(bonusId));
    assertNotNull("Master pool should be the same", poolCurator.find(masterId));
    // master pool should have been recreated
    pools = poolCurator.lookupBySubscriptionId(owner, sub.getId());
    assertEquals(2, pools.size());
    boolean newBonus = false;
    for (Pool p : pools) {
        if (p.getSourceSubscription().getSubscriptionSubKey().equals("derived")) {
            newBonus = true;
        }
    }
    assertTrue(newBonus);
}
Also used : ImportSubscriptionServiceAdapter(org.candlepin.service.impl.ImportSubscriptionServiceAdapter) OwnerServiceAdapter(org.candlepin.service.OwnerServiceAdapter) DefaultOwnerServiceAdapter(org.candlepin.service.impl.DefaultOwnerServiceAdapter) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Matchers.anyString(org.mockito.Matchers.anyString) Subscription(org.candlepin.model.dto.Subscription) LinkedList(java.util.LinkedList) DefaultOwnerServiceAdapter(org.candlepin.service.impl.DefaultOwnerServiceAdapter) Test(org.junit.Test)

Example 14 with Subscription

use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.

the class OwnerResourceTest method createSubscription.

@Test
public void createSubscription() {
    Product p = this.createProduct(owner);
    Subscription s = TestUtil.createSubscription(owner, p);
    s.setId("MADETHISUP");
    assertEquals(0, poolCurator.listByOwner(owner).list().size());
    ownerResource.createSubscription(owner.getKey(), s);
    assertEquals(1, poolCurator.listByOwner(owner).list().size());
}
Also used : Product(org.candlepin.model.Product) Subscription(org.candlepin.model.dto.Subscription) Test(org.junit.Test)

Example 15 with Subscription

use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.

the class EntitlementImporterTest method fullImport.

@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);
    when(om.readValue(reader, EntitlementDTO.class)).thenReturn(dtoEnt);
    // Create our expected products
    Map<String, ProductDTO> productsById = buildProductCache(parentProduct, provided1, derivedProduct, derivedProvided1);
    Subscription 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, 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.toDTO(), sub.getProduct());
    assertEquals(providedProducts.size(), sub.getProvidedProducts().size());
    assertEquals(provided1.getId(), sub.getProvidedProducts().iterator().next().getId());
    assertEquals(derivedProduct.toDTO(), sub.getDerivedProduct());
    assertEquals(1, sub.getDerivedProvidedProducts().size());
    assertEquals(derivedProvided1.getId(), sub.getDerivedProvidedProducts().iterator().next().getId());
    assertNotNull(sub.getCertificate());
    CertificateSerial 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());
}
Also used : EntitlementDTO(org.candlepin.dto.manifest.v1.EntitlementDTO) Product(org.candlepin.model.Product) CertificateSerial(org.candlepin.model.CertificateSerial) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) Subscription(org.candlepin.model.dto.Subscription) ProductDTO(org.candlepin.dto.manifest.v1.ProductDTO) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Subscription (org.candlepin.model.dto.Subscription)101 Test (org.junit.Test)77 Pool (org.candlepin.model.Pool)60 Product (org.candlepin.model.Product)48 SourceSubscription (org.candlepin.model.SourceSubscription)36 LinkedList (java.util.LinkedList)35 ArrayList (java.util.ArrayList)34 Owner (org.candlepin.model.Owner)33 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)27 HashMap (java.util.HashMap)20 HashSet (java.util.HashSet)18 Matchers.anyString (org.mockito.Matchers.anyString)18 Entitlement (org.candlepin.model.Entitlement)16 Date (java.util.Date)15 PoolType (org.candlepin.model.Pool.PoolType)13 ImportSubscriptionServiceAdapter (org.candlepin.service.impl.ImportSubscriptionServiceAdapter)13 List (java.util.List)11 OwnerServiceAdapter (org.candlepin.service.OwnerServiceAdapter)11 ConsumerType (org.candlepin.model.ConsumerType)10 ProductData (org.candlepin.model.dto.ProductData)9