Search in sources :

Example 56 with Pool

use of org.candlepin.model.Pool 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));
}
Also used : Owner(org.candlepin.model.Owner) SourceSubscription(org.candlepin.model.SourceSubscription) PoolType(org.candlepin.model.Pool.PoolType) ArrayList(java.util.ArrayList) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) CandlepinQuery(org.candlepin.model.CandlepinQuery) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) Test(org.junit.Test)

Example 57 with Pool

use of org.candlepin.model.Pool 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());
}
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) ValidationResult(org.candlepin.policy.ValidationResult) SourceSubscription(org.candlepin.model.SourceSubscription) Pool(org.candlepin.model.Pool) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Matchers.anyList(org.mockito.Matchers.anyList) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 58 with Pool

use of org.candlepin.model.Pool 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());
}
Also used : 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) PoolUpdate(org.candlepin.policy.js.pool.PoolUpdate) LinkedList(java.util.LinkedList) SourceSubscription(org.candlepin.model.SourceSubscription) Pool(org.candlepin.model.Pool) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Matchers.anyList(org.mockito.Matchers.anyList) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 59 with Pool

use of org.candlepin.model.Pool in project candlepin by candlepin.

the class PoolManagerTest method testRefreshPoolsSortsStackDerivedPools.

@SuppressWarnings("rawtypes")
@Test
public void testRefreshPoolsSortsStackDerivedPools() {
    List<Subscription> subscriptions = new ArrayList<>();
    List<Pool> pools = new ArrayList<>();
    // Pool has no subscription ID:
    Product product = TestUtil.createProduct();
    Pool p = TestUtil.createPool(product);
    p.setSourceStack(new SourceStack(new Consumer(), "a"));
    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);
    this.manager.getRefresher(mockSubAdapter, mockOwnerAdapter).add(owner).run();
    ArgumentCaptor<List> poolCaptor = ArgumentCaptor.forClass(List.class);
    verify(this.poolRulesMock).updatePools(poolCaptor.capture(), any(Map.class));
    assertEquals(1, poolCaptor.getValue().size());
    assertEquals(p, poolCaptor.getValue().get(0));
}
Also used : 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) Consumer(org.candlepin.model.Consumer) SourceStack(org.candlepin.model.SourceStack) Pool(org.candlepin.model.Pool) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Matchers.anyList(org.mockito.Matchers.anyList) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 60 with Pool

use of org.candlepin.model.Pool in project candlepin by candlepin.

the class PoolManagerTest method testIsManaged.

@Test
@Parameters(method = "getParametersForIsManagedTests")
public void testIsManaged(PoolType type, SourceSubscription srcSub, String upstreamPoolId, boolean hosted, boolean expected) {
    Pool pool = TestUtil.createPool(owner, product);
    when(mockConfig.getBoolean(eq(ConfigProperties.STANDALONE))).thenReturn(!hosted);
    when(mockConfig.getBoolean(eq(ConfigProperties.STANDALONE), anyBoolean())).thenReturn(!hosted);
    pool.setSourceSubscription(srcSub);
    pool.setUpstreamPoolId(upstreamPoolId);
    switch(type) {
        case UNMAPPED_GUEST:
            pool.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
            pool.setAttribute(Pool.Attributes.UNMAPPED_GUESTS_ONLY, "true");
            break;
        case ENTITLEMENT_DERIVED:
            pool.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
            pool.setSourceEntitlement(new Entitlement());
            break;
        case STACK_DERIVED:
            pool.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
            pool.setSourceStack(new SourceStack());
            break;
        case BONUS:
            pool.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
            break;
        case DEVELOPMENT:
            pool.setAttribute(Pool.Attributes.DEVELOPMENT_POOL, "true");
            break;
        case NORMAL:
        default:
    }
    boolean output = manager.isManaged(pool);
    assertEquals(expected, output);
}
Also used : SourceStack(org.candlepin.model.SourceStack) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) Parameters(junitparams.Parameters) Test(org.junit.Test)

Aggregations

Pool (org.candlepin.model.Pool)508 Test (org.junit.Test)358 Product (org.candlepin.model.Product)217 Entitlement (org.candlepin.model.Entitlement)125 Consumer (org.candlepin.model.Consumer)115 ValidationResult (org.candlepin.policy.ValidationResult)111 ArrayList (java.util.ArrayList)100 LinkedList (java.util.LinkedList)100 Owner (org.candlepin.model.Owner)80 HashSet (java.util.HashSet)76 HashMap (java.util.HashMap)67 PoolQuantity (org.candlepin.model.PoolQuantity)66 Date (java.util.Date)65 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)62 Subscription (org.candlepin.model.dto.Subscription)60 List (java.util.List)48 ConsumerType (org.candlepin.model.ConsumerType)48 SourceSubscription (org.candlepin.model.SourceSubscription)47 ActivationKey (org.candlepin.model.activationkeys.ActivationKey)38 Matchers.anyString (org.mockito.Matchers.anyString)30