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());
}
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));
}
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));
}
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());
}
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));
}
Aggregations