use of org.candlepin.policy.js.entitlement.PreUnbindHelper in project candlepin by candlepin.
the class PoolManagerTest method testCleanup.
@Test
public void testCleanup() throws Exception {
Pool p = createPoolWithEntitlements();
when(mockPoolCurator.lockAndLoad(any(Pool.class))).thenReturn(p);
when(mockPoolCurator.entitlementsIn(p)).thenReturn(new ArrayList<>(p.getEntitlements()));
PreUnbindHelper preHelper = mock(PreUnbindHelper.class);
ValidationResult result = new ValidationResult();
when(preHelper.getResult()).thenReturn(result);
manager.deletePool(p);
// And the pool should be deleted:
verify(mockPoolCurator).delete(p);
// Check that appropriate events were sent out:
verify(eventFactory).poolDeleted(p);
verify(mockEventSink, times(1)).queueEvent((Event) any());
}
use of org.candlepin.policy.js.entitlement.PreUnbindHelper in project candlepin by candlepin.
the class PoolManagerTest method testRevokeAllEntitlements.
@Test
public void testRevokeAllEntitlements() {
Consumer c = TestUtil.createConsumer(owner);
Entitlement e1 = new Entitlement(pool, c, owner, 1);
Entitlement e2 = new Entitlement(pool, c, owner, 1);
List<Entitlement> entitlementList = new ArrayList<>();
entitlementList.add(e1);
entitlementList.add(e2);
when(entitlementCurator.listByConsumer(eq(c))).thenReturn(entitlementList);
when(mockPoolCurator.lockAndLoad(any(Pool.class))).thenReturn(pool);
PreUnbindHelper preHelper = mock(PreUnbindHelper.class);
ValidationResult result = new ValidationResult();
when(preHelper.getResult()).thenReturn(result);
int total = manager.revokeAllEntitlements(c);
assertEquals(2, total);
verify(entitlementCurator, times(1)).markDependentEntitlementsDirty(any(List.class));
// TODO assert batch revokes have been called
}
use of org.candlepin.policy.js.entitlement.PreUnbindHelper 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.policy.js.entitlement.PreUnbindHelper in project candlepin by candlepin.
the class PoolManagerTest method testCleanupExpiredPoolsReadOnlySubscriptions.
@Test
public void testCleanupExpiredPoolsReadOnlySubscriptions() {
Pool p = createPoolWithEntitlements();
p.setSubscriptionId("subid");
List<Pool> pools = Arrays.asList(p);
when(mockPoolCurator.lockAndLoadByIds(anyCollection())).thenReturn(pools);
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(true);
PreUnbindHelper preHelper = mock(PreUnbindHelper.class);
ValidationResult result = new ValidationResult();
when(preHelper.getResult()).thenReturn(result);
manager.cleanupExpiredPools();
// And the pool should be deleted:
verify(mockPoolCurator).batchDelete(eq(pools), anySetOf(String.class));
verify(mockSubAdapter, never()).getSubscription(any(String.class));
verify(mockSubAdapter, never()).deleteSubscription(any(Subscription.class));
}
use of org.candlepin.policy.js.entitlement.PreUnbindHelper in project candlepin by candlepin.
the class PoolManagerTest method testBatchRevokeCleansUpCorrectPoolsWithSourceEnt.
@Test
public void testBatchRevokeCleansUpCorrectPoolsWithSourceEnt() throws Exception {
Consumer c = TestUtil.createConsumer(owner);
Pool pool2 = TestUtil.createPool(owner, product);
Entitlement e = new Entitlement(pool, c, owner, 1);
Entitlement e2 = new Entitlement(pool2, c, owner, 1);
Entitlement e3 = new Entitlement(pool2, c, owner, 1);
List<Entitlement> entsToDelete = new ArrayList<>();
entsToDelete.add(e);
entsToDelete.add(e2);
List<Pool> poolsWithSource = createPoolsWithSourceEntitlement(e, product);
poolsWithSource.get(0).getEntitlements().add(e3);
Set<Pool> poolsWithSourceAsSet = new HashSet<>(poolsWithSource);
when(mockPoolCurator.listBySourceEntitlements(entsToDelete)).thenReturn(poolsWithSourceAsSet);
PreUnbindHelper preHelper = mock(PreUnbindHelper.class);
ValidationResult result = new ValidationResult();
when(preHelper.getResult()).thenReturn(result);
when(mockConfig.getBoolean(ConfigProperties.STANDALONE)).thenReturn(true);
when(mockPoolCurator.lockAndLoad(eq(pool))).thenReturn(pool);
when(mockPoolCurator.lockAndLoad(eq(pool2))).thenReturn(pool2);
manager.revokeEntitlements(entsToDelete);
entsToDelete.add(e3);
verify(entitlementCurator).batchDelete(eq(entsToDelete));
verify(mockPoolCurator).batchDelete(eq(poolsWithSourceAsSet), anySetOf(String.class));
}
Aggregations