Search in sources :

Example 1 with ImportSubscriptionServiceAdapter

use of org.candlepin.service.impl.ImportSubscriptionServiceAdapter in project candlepin by candlepin.

the class OwnerResourceTest method testRefreshPoolsWithRemovedSubscriptions.

@Test
public void testRefreshPoolsWithRemovedSubscriptions() {
    Product prod = this.createProduct(owner);
    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));
    // This line is only present as a result of a (temporary?) fix for BZ 1452694. Once a
    // better fix has been implemented, the upstream pool ID can be removed.
    sub.setUpstreamPoolId("upstream_pool_id");
    subscriptions.add(sub);
    // Trigger the refresh:
    poolManager.getRefresher(subAdapter, ownerAdapter).add(owner).run();
    List<Pool> pools = poolCurator.listByOwnerAndProduct(owner, prod.getId());
    assertEquals(1, pools.size());
    Pool newPool = pools.get(0);
    String poolId = newPool.getId();
    // Now delete the subscription:
    subscriptions.remove(sub);
    // Trigger the refresh:
    poolManager.getRefresher(subAdapter, ownerAdapter).add(owner).run();
    assertNull("Pool not having subscription should have been deleted", poolCurator.find(poolId));
}
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 2 with ImportSubscriptionServiceAdapter

use of org.candlepin.service.impl.ImportSubscriptionServiceAdapter 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 3 with ImportSubscriptionServiceAdapter

use of org.candlepin.service.impl.ImportSubscriptionServiceAdapter 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 4 with ImportSubscriptionServiceAdapter

use of org.candlepin.service.impl.ImportSubscriptionServiceAdapter 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 5 with ImportSubscriptionServiceAdapter

use of org.candlepin.service.impl.ImportSubscriptionServiceAdapter in project candlepin by candlepin.

the class PoolManagerFunctionalTest method testRefreshPoolsWithChangedProductShouldUpdatePool.

@Test
public void testRefreshPoolsWithChangedProductShouldUpdatePool() {
    Product product1 = TestUtil.createProduct("product 1", "Product 1");
    Product product2 = TestUtil.createProduct("product 2", "Product 2");
    productCurator.create(product1);
    productCurator.create(product2);
    List<Subscription> subscriptions = new LinkedList<>();
    ImportSubscriptionServiceAdapter subAdapter = new ImportSubscriptionServiceAdapter(subscriptions);
    Subscription subscription = TestUtil.createSubscription(o, product1, new HashSet<>());
    subscription.setId(Util.generateDbUUID());
    subscription.setQuantity(5L);
    subscription.setStartDate(new Date());
    subscription.setEndDate(TestUtil.createDate(3020, 12, 12));
    subscription.setModified(new Date());
    subscriptions.add(subscription);
    // set up initial pool
    poolManager.getRefresher(subAdapter, ownerAdapter).add(o).run();
    List<Pool> pools = poolCurator.listByOwnerAndProduct(o, product1.getId());
    assertEquals(1, pools.size());
    // now alter the product behind the sub, and make sure the pool is also updated
    subscription.setProduct(product2.toDTO());
    // set up initial pool
    poolManager.getRefresher(subAdapter, ownerAdapter).add(o).run();
    pools = poolCurator.listByOwnerAndProduct(o, product2.getId());
    assertEquals(1, pools.size());
}
Also used : ImportSubscriptionServiceAdapter(org.candlepin.service.impl.ImportSubscriptionServiceAdapter) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Pool(org.candlepin.model.Pool) Subscription(org.candlepin.model.dto.Subscription) LinkedList(java.util.LinkedList) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Subscription (org.candlepin.model.dto.Subscription)13 ImportSubscriptionServiceAdapter (org.candlepin.service.impl.ImportSubscriptionServiceAdapter)13 LinkedList (java.util.LinkedList)12 Product (org.candlepin.model.Product)10 OwnerServiceAdapter (org.candlepin.service.OwnerServiceAdapter)9 DefaultOwnerServiceAdapter (org.candlepin.service.impl.DefaultOwnerServiceAdapter)9 Test (org.junit.Test)9 Pool (org.candlepin.model.Pool)8 Date (java.util.Date)3 HashSet (java.util.HashSet)3 Owner (org.candlepin.model.Owner)3 Matchers.anyString (org.mockito.Matchers.anyString)3 Consumer (org.candlepin.model.Consumer)2 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)2 ConsumerType (org.candlepin.model.ConsumerType)2 Before (org.junit.Before)2 Transactional (com.google.inject.persist.Transactional)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 EntityNotFoundException (javax.persistence.EntityNotFoundException)1