Search in sources :

Example 81 with Subscription

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

the class PoolManagerTest method testFabricateSubWithMultiplierAndInstanceMultiplier.

@Test
public void testFabricateSubWithMultiplierAndInstanceMultiplier() {
    Product product = TestUtil.createProduct("product", "Product");
    Pool pool = mock(Pool.class);
    Long quantity = new Long(64);
    Long multiplier = new Long(2);
    product.setMultiplier(multiplier);
    product.setAttribute(Product.Attributes.INSTANCE_MULTIPLIER, "4");
    when(pool.getQuantity()).thenReturn(quantity);
    when(pool.getProduct()).thenReturn(product);
    Subscription fabricated = manager.fabricateSubscriptionFromPool(pool);
    assertEquals((Long) 8L, fabricated.getQuantity());
}
Also used : ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) Test(org.junit.Test)

Example 82 with Subscription

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

the class PoolManagerTest method testRefreshPoolsSkipsDevelopmentPools.

@Test
public void testRefreshPoolsSkipsDevelopmentPools() {
    List<Subscription> subscriptions = new ArrayList<>();
    List<Pool> pools = new ArrayList<>();
    Product product = TestUtil.createProduct();
    Pool p = TestUtil.createPool(product);
    p.setSourceSubscription(null);
    // Mock a development pool
    p.setAttribute(Pool.Attributes.DEVELOPMENT_POOL, "true");
    pools.add(p);
    mockSubsList(subscriptions);
    mockPoolsList(pools);
    CandlepinQuery<Pool> cqmock = mock(CandlepinQuery.class);
    when(cqmock.list()).thenReturn(pools);
    when(cqmock.iterator()).thenReturn(pools.iterator());
    when(mockPoolCurator.listByOwnerAndType(eq(owner), any(PoolType.class))).thenReturn(cqmock);
    this.mockProductImport(owner, product);
    this.mockContentImport(owner, new Content[] {});
    Owner owner = getOwner();
    when(mockOwnerCurator.lookupByKey(owner.getKey())).thenReturn(owner);
    this.manager.getRefresher(mockSubAdapter, mockOwnerAdapter).add(owner).run();
    verify(this.manager, never()).deletePool(same(p));
}
Also used : Owner(org.candlepin.model.Owner) PoolType(org.candlepin.model.Pool.PoolType) ArrayList(java.util.ArrayList) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) Test(org.junit.Test)

Example 83 with Subscription

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

the class PoolManagerTest method testRefreshPoolsRemovesExpiredSubscriptionsAlongWithItsPoolsAndEnts.

@Test
public void testRefreshPoolsRemovesExpiredSubscriptionsAlongWithItsPoolsAndEnts() {
    PreUnbindHelper preHelper = mock(PreUnbindHelper.class);
    Date expiredStart = TestUtil.createDate(2004, 5, 5);
    Date expiredDate = TestUtil.createDate(2005, 5, 5);
    List<Subscription> subscriptions = new ArrayList<>();
    Owner owner = this.getOwner();
    Product product = TestUtil.createProduct();
    Subscription sub = TestUtil.createSubscription(owner, product);
    sub.setStartDate(expiredStart);
    sub.setEndDate(expiredDate);
    sub.setId("123");
    subscriptions.add(sub);
    mockSubsList(subscriptions);
    List<Pool> pools = new ArrayList<>();
    Pool p = TestUtil.createPool(owner, product);
    p.setId("test-pool");
    p.setSourceSubscription(new SourceSubscription(sub.getId(), "master"));
    p.setStartDate(expiredStart);
    p.setEndDate(expiredDate);
    p.setConsumed(1L);
    pools.add(p);
    when(mockPoolCurator.lockAndLoadByIds(anyCollection())).thenReturn(pools);
    mockPoolsList(pools);
    List<Entitlement> poolEntitlements = new ArrayList<>();
    Entitlement ent = TestUtil.createEntitlement();
    ent.setId("test-ent");
    ent.setPool(p);
    ent.setQuantity(1);
    poolEntitlements.add(ent);
    p.getEntitlements().addAll(poolEntitlements);
    when(mockPoolCurator.getEntitlementIdsForPools(anyCollection())).thenReturn(Arrays.asList(ent.getId()));
    CandlepinQuery<Entitlement> cqmockEnt = mock(CandlepinQuery.class);
    when(cqmockEnt.list()).thenReturn(poolEntitlements);
    when(cqmockEnt.iterator()).thenReturn(poolEntitlements.iterator());
    when(entitlementCurator.listAllByIds(anyCollection())).thenReturn(cqmockEnt);
    ValidationResult result = new ValidationResult();
    when(preHelper.getResult()).thenReturn(result);
    when(mockOwnerCurator.lookupByKey(owner.getKey())).thenReturn(owner);
    this.mockProducts(owner, product);
    this.mockProductImport(owner, product);
    this.mockContentImport(owner, new Content[] {});
    CandlepinQuery<Pool> cqmock = mock(CandlepinQuery.class);
    when(cqmock.list()).thenReturn(pools);
    when(cqmock.iterator()).thenReturn(pools.iterator());
    when(mockPoolCurator.listByOwnerAndType(eq(owner), any(PoolType.class))).thenReturn(cqmock);
    cqmock = mock(CandlepinQuery.class);
    when(cqmock.list()).thenReturn(Collections.<Pool>emptyList());
    when(mockPoolCurator.getPoolsBySubscriptionIds(anyList())).thenReturn(cqmock);
    this.manager.getRefresher(mockSubAdapter, mockOwnerAdapter).add(owner).run();
    verify(mockPoolCurator).batchDelete(eq(pools), anyCollectionOf(String.class));
    verify(entitlementCurator).batchDelete(eq(poolEntitlements));
}
Also used : PreUnbindHelper(org.candlepin.policy.js.entitlement.PreUnbindHelper) Owner(org.candlepin.model.Owner) PoolType(org.candlepin.model.Pool.PoolType) ArrayList(java.util.ArrayList) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) CandlepinQuery(org.candlepin.model.CandlepinQuery) Matchers.anyString(org.mockito.Matchers.anyString) ValidationResult(org.candlepin.policy.ValidationResult) Date(java.util.Date) SourceSubscription(org.candlepin.model.SourceSubscription) Pool(org.candlepin.model.Pool) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 84 with Subscription

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

the class PoolManagerTest method testFabricateSubWithZeroInstanceMultiplier.

@Test
public void testFabricateSubWithZeroInstanceMultiplier() {
    // Product product = TestUtil.createProduct("product", "Product");
    Pool pool = mock(Pool.class);
    Long quantity = new Long(64);
    Long multiplier = new Long(2);
    product.setMultiplier(multiplier);
    product.setAttribute(Product.Attributes.INSTANCE_MULTIPLIER, "0");
    when(pool.getQuantity()).thenReturn(quantity);
    when(pool.getProduct()).thenReturn(product);
    Subscription fabricated = manager.fabricateSubscriptionFromPool(pool);
    assertEquals((Long) 32L, fabricated.getQuantity());
}
Also used : Pool(org.candlepin.model.Pool) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) Test(org.junit.Test)

Example 85 with Subscription

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

the class PoolManagerTest method testRefreshPoolsSkipsOrphanedEntitlementDerivedPools.

@Test
public void testRefreshPoolsSkipsOrphanedEntitlementDerivedPools() {
    List<Subscription> subscriptions = new ArrayList<>();
    List<Pool> pools = new ArrayList<>();
    Product product = TestUtil.createProduct();
    Pool p = TestUtil.createPool(product);
    p.setSourceSubscription(new SourceSubscription("112", "master"));
    // Mock a pool with a source entitlement:
    p.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
    p.setSourceStack(null);
    p.setSourceEntitlement(new Entitlement());
    pools.add(p);
    mockSubsList(subscriptions);
    mockPoolsList(pools);
    Owner owner = getOwner();
    when(mockOwnerCurator.lookupByKey(owner.getKey())).thenReturn(owner);
    this.mockProductImport(owner, product);
    this.mockContentImport(owner, new Content[] {});
    CandlepinQuery<Pool> cqmock = mock(CandlepinQuery.class);
    when(cqmock.list()).thenReturn(pools);
    when(cqmock.iterator()).thenReturn(pools.iterator());
    when(mockPoolCurator.listByOwnerAndType(eq(owner), any(PoolType.class))).thenReturn(cqmock);
    this.manager.getRefresher(mockSubAdapter, mockOwnerAdapter).add(owner).run();
    verify(this.manager, never()).deletePool(same(p));
}
Also used : Owner(org.candlepin.model.Owner) SourceSubscription(org.candlepin.model.SourceSubscription) PoolType(org.candlepin.model.Pool.PoolType) ArrayList(java.util.ArrayList) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) Entitlement(org.candlepin.model.Entitlement) 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