use of org.candlepin.policy.js.entitlement.PreUnbindHelper 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.policy.js.entitlement.PreUnbindHelper in project candlepin by candlepin.
the class PoolManagerTest method testRevokeCleansUpPoolsWithSourceEnt.
@Test
public void testRevokeCleansUpPoolsWithSourceEnt() throws Exception {
Entitlement e = new Entitlement(pool, TestUtil.createConsumer(owner), owner, 1);
List<Pool> poolsWithSource = createPoolsWithSourceEntitlement(e, product);
CandlepinQuery<Pool> cqmock = mock(CandlepinQuery.class);
when(cqmock.list()).thenReturn(poolsWithSource);
when(mockPoolCurator.listBySourceEntitlement(e)).thenReturn(cqmock);
PreUnbindHelper preHelper = mock(PreUnbindHelper.class);
ValidationResult result = new ValidationResult();
when(preHelper.getResult()).thenReturn(result);
when(mockConfig.getBoolean(ConfigProperties.STANDALONE)).thenReturn(true);
when(mockPoolCurator.lockAndLoad(any(Pool.class))).thenReturn(pool);
manager.revokeEntitlement(e);
List<Entitlement> entsToDelete = Arrays.asList(e);
verify(entitlementCurator).batchDelete(eq(entsToDelete));
}
use of org.candlepin.policy.js.entitlement.PreUnbindHelper 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));
}
Aggregations