use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.
the class PoolManagerTest method testCleanupExpiredPools.
@Test
public void testCleanupExpiredPools() {
Pool p = createPoolWithEntitlements();
p.setSubscriptionId("subid");
List<Pool> pools = new LinkedList<>();
pools.add(p);
when(mockPoolCurator.lockAndLoad(any(Pool.class))).thenReturn(p);
when(mockPoolCurator.listExpiredPools(anyInt())).thenReturn(pools);
when(mockPoolCurator.entitlementsIn(p)).thenReturn(new ArrayList<>(p.getEntitlements()));
Subscription sub = new Subscription();
sub.setId(p.getSubscriptionId());
when(mockSubAdapter.getSubscription(any(String.class))).thenReturn(sub);
when(mockSubAdapter.isReadOnly()).thenReturn(false);
PreUnbindHelper preHelper = mock(PreUnbindHelper.class);
ValidationResult result = new ValidationResult();
when(preHelper.getResult()).thenReturn(result);
manager.cleanupExpiredPools();
// And the pool should be deleted:
when(mockPoolCurator.lockAndLoadByIds(anyCollection())).thenReturn(pools);
}
use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.
the class PoolManagerTest method createPoolsForExistingSubscriptionsBonusExist.
@Test
public void createPoolsForExistingSubscriptionsBonusExist() {
Owner owner = this.getOwner();
PoolRules pRules = new PoolRules(manager, mockConfig, entitlementCurator, mockOwnerProductCurator, mockProductCurator);
List<Subscription> subscriptions = new ArrayList<>();
Product prod = TestUtil.createProduct();
Set<Product> products = new HashSet<>();
products.add(prod);
// productCache.addProducts(products);
prod.setAttribute(Product.Attributes.VIRT_LIMIT, "4");
Subscription s = TestUtil.createSubscription(owner, prod);
subscriptions.add(s);
this.mockProducts(owner, prod);
when(mockSubAdapter.getSubscriptions(any(Owner.class))).thenReturn(subscriptions);
when(mockConfig.getBoolean(ConfigProperties.STANDALONE)).thenReturn(false);
List<Pool> existingPools = new LinkedList<>();
Pool p = TestUtil.createPool(prod);
p.setSourceSubscription(new SourceSubscription(s.getId(), "derived"));
existingPools.add(p);
pRules.createAndEnrichPools(s, existingPools);
List<Pool> newPools = pRules.createAndEnrichPools(s, existingPools);
assertEquals(newPools.size(), 1);
assertEquals(newPools.get(0).getSourceSubscription().getSubscriptionSubKey(), "master");
}
use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.
the class PoolManagerTest method testRefreshPoolsSkipsOrphanedStackDerivedPools.
@Test
public void testRefreshPoolsSkipsOrphanedStackDerivedPools() {
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 stack ID:
p.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
p.setSourceStack(new SourceStack(new Consumer(), "blah"));
p.setSourceEntitlement(null);
pools.add(p);
mockSubsList(subscriptions);
mockPoolsList(pools);
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);
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 testFabricateSubWithMultiplier.
/**
* See BZ1292283
*/
@Test
public void testFabricateSubWithMultiplier() {
Product product = TestUtil.createProduct("product", "Product");
Pool pool = mock(Pool.class);
Long quantity = new Long(22);
Long multiplier = new Long(2);
product.setMultiplier(multiplier);
when(pool.getQuantity()).thenReturn(quantity);
when(pool.getProduct()).thenReturn(product);
Subscription fabricated = manager.fabricateSubscriptionFromPool(pool);
assertEquals((Long) (quantity / multiplier), fabricated.getQuantity());
}
use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.
the class PoolManagerTest method testRefreshPoolsOnlyRegeneratesWhenNecessary.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testRefreshPoolsOnlyRegeneratesWhenNecessary() {
List<Subscription> subscriptions = new ArrayList<>();
Owner owner = this.getOwner();
Product product = TestUtil.createProduct();
product.setLocked(true);
Subscription sub = TestUtil.createSubscription(owner, product);
sub.setId("testing-subid");
subscriptions.add(sub);
// Set up pools
List<Pool> pools = new ArrayList<>();
// Should be unchanged
Pool p = TestUtil.createPool(product);
p.setSourceSubscription(new SourceSubscription(sub.getId(), "master"));
p.setOwner(owner);
pools.add(p);
mockSubsList(subscriptions);
mockPoolsList(pools);
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);
this.manager.getRefresher(mockSubAdapter, mockOwnerAdapter).add(owner).run();
List<Pool> expectedModified = new LinkedList();
// Make sure that only the floating pool was regenerated
expectedModified.add(p);
verify(this.manager).updateFloatingPools(eq(new LinkedList()), eq(true), any(Map.class));
ArgumentCaptor<Pool> argPool = ArgumentCaptor.forClass(Pool.class);
verify(this.manager).updatePoolsForMasterPool(eq(expectedModified), argPool.capture(), eq(sub.getQuantity()), eq(false), any(Map.class));
TestUtil.assertPoolsAreEqual(TestUtil.copyFromSub(sub), argPool.getValue());
}
Aggregations