use of org.candlepin.model.SourceSubscription in project candlepin by candlepin.
the class PoolManagerTest method createPoolsForExistingSubscriptionsMasterExist.
@Test
public void createPoolsForExistingSubscriptionsMasterExist() {
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(), "master"));
existingPools.add(p);
List<Pool> newPools = pRules.createAndEnrichPools(s, existingPools);
assertEquals(newPools.size(), 1);
assertEquals(newPools.get(0).getSourceSubscription().getSubscriptionSubKey(), "derived");
}
use of org.candlepin.model.SourceSubscription in project candlepin by candlepin.
the class PoolManagerTest method refreshPoolsCreatingPoolsForExistingSubscriptions.
@Test
public void refreshPoolsCreatingPoolsForExistingSubscriptions() {
List<Subscription> subscriptions = new ArrayList<>();
List<Pool> pools = new ArrayList<>();
Owner owner = this.getOwner();
Product product = TestUtil.createProduct();
product.setLocked(true);
Subscription s = TestUtil.createSubscription(owner, product);
subscriptions.add(s);
mockSubsList(subscriptions);
mockPoolsList(pools);
List<Pool> newPools = new LinkedList<>();
Pool p = TestUtil.createPool(product);
p.setSourceSubscription(new SourceSubscription(s.getId(), "master"));
newPools.add(p);
ArgumentCaptor<Pool> argPool = ArgumentCaptor.forClass(Pool.class);
when(poolRulesMock.createAndEnrichPools(argPool.capture(), any(List.class))).thenReturn(newPools);
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);
cqmock = mock(CandlepinQuery.class);
when(cqmock.list()).thenReturn(Collections.<Pool>emptyList());
when(mockPoolCurator.getPoolsBySubscriptionId(anyString())).thenReturn(cqmock);
this.manager.getRefresher(mockSubAdapter, mockOwnerAdapter).add(owner).run();
TestUtil.assertPoolsAreEqual(TestUtil.copyFromSub(s), argPool.getValue());
verify(this.mockPoolCurator, times(1)).create(any(Pool.class));
}
use of org.candlepin.model.SourceSubscription in project candlepin by candlepin.
the class PoolManagerTest method testRefreshPoolsDeletesOrphanedHostedVirtBonusPool.
@Test
public void testRefreshPoolsDeletesOrphanedHostedVirtBonusPool() {
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"));
// Make it look like a hosted virt bonus pool:
p.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
p.setSourceStack(null);
p.setSourceEntitlement(null);
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);
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();
List<Pool> delPools = Arrays.asList(p);
verify(this.manager).deletePools(eq(delPools));
}
use of org.candlepin.model.SourceSubscription in project candlepin by candlepin.
the class PoolManagerTest method testRefreshPoolsRemovesOtherOwnerPoolsForSameSub.
@Test
public void testRefreshPoolsRemovesOtherOwnerPoolsForSameSub() {
PreUnbindHelper preHelper = mock(PreUnbindHelper.class);
Owner other = new Owner("otherkey", "othername");
List<Subscription> subscriptions = new ArrayList<>();
Owner owner = this.getOwner();
Product product = TestUtil.createProduct();
product.setLocked(true);
Subscription sub = TestUtil.createSubscription(owner, product);
sub.setId("123");
subscriptions.add(sub);
mockSubsList(subscriptions);
List<Pool> pools = new ArrayList<>();
Pool p = TestUtil.copyFromSub(sub);
p.setOwner(other);
p.setSourceSubscription(new SourceSubscription(sub.getId(), "master"));
p.setConsumed(1L);
pools.add(p);
when(mockPoolCurator.lockAndLoad(any(Pool.class))).thenReturn(p);
mockPoolsList(pools);
List<Entitlement> poolEntitlements = new ArrayList<>();
Entitlement ent = TestUtil.createEntitlement();
ent.setPool(p);
ent.setQuantity(1);
poolEntitlements.add(ent);
when(mockPoolCurator.entitlementsIn(eq(p))).thenReturn(poolEntitlements);
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);
this.manager.getRefresher(mockSubAdapter, mockOwnerAdapter).add(owner).run();
// The pool left over from the pre-migrated subscription should be deleted
// and granted entitlements should be revoked
List<Entitlement> entsToDelete = Arrays.asList(ent);
verify(mockPoolCurator).delete(eq(p));
verify(entitlementCurator).batchDelete(eq(entsToDelete));
// Make sure pools that don't match the owner were removed from the list
// They shouldn't cause us to attempt to update existing pools when we
// haven't created them in the first place
ArgumentCaptor<Pool> argPool = ArgumentCaptor.forClass(Pool.class);
verify(poolRulesMock).createAndEnrichPools(argPool.capture(), any(List.class));
TestUtil.assertPoolsAreEqual(TestUtil.copyFromSub(sub), argPool.getValue());
}
use of org.candlepin.model.SourceSubscription in project candlepin by candlepin.
the class PoolManagerTest method refreshPoolsCleanupPoolThatLostVirtLimit.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void refreshPoolsCleanupPoolThatLostVirtLimit() {
List<Subscription> subscriptions = new ArrayList<>();
List<Pool> pools = new ArrayList<>();
Owner owner = getOwner();
Product product = TestUtil.createProduct();
product.setLocked(true);
Subscription s = TestUtil.createSubscription(owner, product);
s.setId("01923");
subscriptions.add(s);
Pool p = TestUtil.createPool(product);
p.setSourceSubscription(new SourceSubscription(s.getId(), "master"));
p.setMarkedForDelete(true);
p.setOwner(owner);
pools.add(p);
mockSubsList(subscriptions);
mockPoolsList(pools);
List<PoolUpdate> updates = new LinkedList();
PoolUpdate u = new PoolUpdate(p);
u.setQuantityChanged(true);
u.setOrderChanged(true);
updates.add(u);
ArgumentCaptor<Pool> argPool = ArgumentCaptor.forClass(Pool.class);
when(poolRulesMock.updatePools(argPool.capture(), eq(pools), eq(s.getQuantity()), any(Map.class))).thenReturn(updates);
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();
verify(poolRulesMock).createAndEnrichPools(argPool.capture(), any(List.class));
TestUtil.assertPoolsAreEqual(TestUtil.copyFromSub(s), argPool.getValue());
}
Aggregations