Search in sources :

Example 6 with PreUnbindHelper

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);
}
Also used : PreUnbindHelper(org.candlepin.policy.js.entitlement.PreUnbindHelper) Pool(org.candlepin.model.Pool) Matchers.anyString(org.mockito.Matchers.anyString) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) ValidationResult(org.candlepin.policy.ValidationResult) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 7 with PreUnbindHelper

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));
}
Also used : PreUnbindHelper(org.candlepin.policy.js.entitlement.PreUnbindHelper) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) ValidationResult(org.candlepin.policy.ValidationResult) Test(org.junit.Test)

Example 8 with PreUnbindHelper

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));
}
Also used : PreUnbindHelper(org.candlepin.policy.js.entitlement.PreUnbindHelper) Owner(org.candlepin.model.Owner) PoolType(org.candlepin.model.Pool.PoolType) ArrayList(java.util.ArrayList) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) CandlepinQuery(org.candlepin.model.CandlepinQuery) Matchers.anyString(org.mockito.Matchers.anyString) ValidationResult(org.candlepin.policy.ValidationResult) Date(java.util.Date) SourceSubscription(org.candlepin.model.SourceSubscription) Pool(org.candlepin.model.Pool) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Aggregations

Pool (org.candlepin.model.Pool)8 ValidationResult (org.candlepin.policy.ValidationResult)8 PreUnbindHelper (org.candlepin.policy.js.entitlement.PreUnbindHelper)8 Test (org.junit.Test)8 Entitlement (org.candlepin.model.Entitlement)5 ArrayList (java.util.ArrayList)4 SourceSubscription (org.candlepin.model.SourceSubscription)4 Subscription (org.candlepin.model.dto.Subscription)4 Matchers.anyString (org.mockito.Matchers.anyString)4 LinkedList (java.util.LinkedList)3 List (java.util.List)2 Consumer (org.candlepin.model.Consumer)2 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)2 Owner (org.candlepin.model.Owner)2 PoolType (org.candlepin.model.Pool.PoolType)2 Product (org.candlepin.model.Product)2 Matchers.anyList (org.mockito.Matchers.anyList)2 Date (java.util.Date)1 HashSet (java.util.HashSet)1 CandlepinQuery (org.candlepin.model.CandlepinQuery)1