use of org.candlepin.model.SourceSubscription in project candlepin by candlepin.
the class PoolManagerTest method testRefreshPoolsOnlyRegeneratesFloatingWhenNecessary.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testRefreshPoolsOnlyRegeneratesFloatingWhenNecessary() {
List<Subscription> subscriptions = new ArrayList<>();
Owner owner = this.getOwner();
Product product = TestUtil.createProduct();
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"));
pools.add(p);
// Should be regenerated because it has no subscription id
Pool floating = TestUtil.createPool(TestUtil.createProduct());
floating.setSourceSubscription(null);
pools.add(floating);
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> expectedFloating = new LinkedList();
// Make sure that only the floating pool was regenerated
expectedFloating.add(floating);
verify(this.manager).updateFloatingPools(eq(expectedFloating), eq(true), any(Map.class));
}
use of org.candlepin.model.SourceSubscription 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.SourceSubscription in project candlepin by candlepin.
the class PoolManagerTest method createPoolsForPoolMasterExist.
@Test
public void createPoolsForPoolMasterExist() {
Owner owner = this.getOwner();
Product prod = TestUtil.createProduct();
prod.setAttribute(Product.Attributes.VIRT_LIMIT, "4");
PoolRules pRules = new PoolRules(manager, mockConfig, entitlementCurator, mockOwnerProductCurator, mockProductCurator);
List<Pool> existingPools = new LinkedList<>();
Pool p = TestUtil.createPool(prod);
p.setSourceSubscription(new SourceSubscription(TestUtil.randomString(), "master"));
existingPools.add(p);
List<Pool> newPools = pRules.createAndEnrichPools(p, existingPools);
assertEquals(1, newPools.size());
assertEquals("derived", newPools.get(0).getSourceSubscription().getSubscriptionSubKey());
}
use of org.candlepin.model.SourceSubscription 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.SourceSubscription 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