Search in sources :

Example 21 with SourceSubscription

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

the class PoolManagerTest method testRefreshPoolsOnlyRegeneratesFloatingWhenNecessary.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testRefreshPoolsOnlyRegeneratesFloatingWhenNecessary() {
    List<Subscription> subscriptions = new ArrayList<>();
    Owner owner = this.getOwner();
    Product product = TestUtil.createProduct();
    Subscription sub = TestUtil.createSubscription(owner, product);
    sub.setId("testing-subid");
    subscriptions.add(sub);
    // Set up pools
    List<Pool> pools = new ArrayList<>();
    // Should be unchanged
    Pool p = TestUtil.createPool(product);
    p.setSourceSubscription(new SourceSubscription(sub.getId(), "master"));
    pools.add(p);
    // Should be regenerated because it has no subscription id
    Pool floating = TestUtil.createPool(TestUtil.createProduct());
    floating.setSourceSubscription(null);
    pools.add(floating);
    mockSubsList(subscriptions);
    mockPoolsList(pools);
    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();
    List<Pool> expectedFloating = new LinkedList();
    // Make sure that only the floating pool was regenerated
    expectedFloating.add(floating);
    verify(this.manager).updateFloatingPools(eq(expectedFloating), eq(true), any(Map.class));
}
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) 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) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 22 with SourceSubscription

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

the class PoolManagerTest method createPoolsForExistingSubscriptionsBonusExist.

@Test
public void createPoolsForExistingSubscriptionsBonusExist() {
    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(), "derived"));
    existingPools.add(p);
    pRules.createAndEnrichPools(s, existingPools);
    List<Pool> newPools = pRules.createAndEnrichPools(s, existingPools);
    assertEquals(newPools.size(), 1);
    assertEquals(newPools.get(0).getSourceSubscription().getSubscriptionSubKey(), "master");
}
Also used : Owner(org.candlepin.model.Owner) SourceSubscription(org.candlepin.model.SourceSubscription) PoolRules(org.candlepin.policy.js.pool.PoolRules) ArrayList(java.util.ArrayList) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 23 with SourceSubscription

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

the class PoolManagerTest method createPoolsForPoolMasterExist.

@Test
public void createPoolsForPoolMasterExist() {
    Owner owner = this.getOwner();
    Product prod = TestUtil.createProduct();
    prod.setAttribute(Product.Attributes.VIRT_LIMIT, "4");
    PoolRules pRules = new PoolRules(manager, mockConfig, entitlementCurator, mockOwnerProductCurator, mockProductCurator);
    List<Pool> existingPools = new LinkedList<>();
    Pool p = TestUtil.createPool(prod);
    p.setSourceSubscription(new SourceSubscription(TestUtil.randomString(), "master"));
    existingPools.add(p);
    List<Pool> newPools = pRules.createAndEnrichPools(p, existingPools);
    assertEquals(1, newPools.size());
    assertEquals("derived", newPools.get(0).getSourceSubscription().getSubscriptionSubKey());
}
Also used : Owner(org.candlepin.model.Owner) SourceSubscription(org.candlepin.model.SourceSubscription) PoolRules(org.candlepin.policy.js.pool.PoolRules) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 24 with SourceSubscription

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

the class PoolManagerTest method testRefreshPoolsSkipsOrphanedStackDerivedPools.

@Test
public void testRefreshPoolsSkipsOrphanedStackDerivedPools() {
    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"));
    // Mock a pool with a source stack ID:
    p.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
    p.setSourceStack(new SourceStack(new Consumer(), "blah"));
    p.setSourceEntitlement(null);
    pools.add(p);
    mockSubsList(subscriptions);
    mockPoolsList(pools);
    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);
    Owner owner = getOwner();
    when(mockOwnerCurator.lookupByKey(owner.getKey())).thenReturn(owner);
    this.manager.getRefresher(mockSubAdapter, mockOwnerAdapter).add(owner).run();
    verify(this.manager, never()).deletePool(same(p));
}
Also used : Owner(org.candlepin.model.Owner) SourceSubscription(org.candlepin.model.SourceSubscription) PoolType(org.candlepin.model.Pool.PoolType) Consumer(org.candlepin.model.Consumer) ArrayList(java.util.ArrayList) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) SourceStack(org.candlepin.model.SourceStack) Pool(org.candlepin.model.Pool) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) Test(org.junit.Test)

Example 25 with SourceSubscription

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

the class PoolManagerTest method testRefreshPoolsOnlyRegeneratesWhenNecessary.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testRefreshPoolsOnlyRegeneratesWhenNecessary() {
    List<Subscription> subscriptions = new ArrayList<>();
    Owner owner = this.getOwner();
    Product product = TestUtil.createProduct();
    product.setLocked(true);
    Subscription sub = TestUtil.createSubscription(owner, product);
    sub.setId("testing-subid");
    subscriptions.add(sub);
    // Set up pools
    List<Pool> pools = new ArrayList<>();
    // Should be unchanged
    Pool p = TestUtil.createPool(product);
    p.setSourceSubscription(new SourceSubscription(sub.getId(), "master"));
    p.setOwner(owner);
    pools.add(p);
    mockSubsList(subscriptions);
    mockPoolsList(pools);
    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();
    List<Pool> expectedModified = new LinkedList();
    // Make sure that only the floating pool was regenerated
    expectedModified.add(p);
    verify(this.manager).updateFloatingPools(eq(new LinkedList()), eq(true), any(Map.class));
    ArgumentCaptor<Pool> argPool = ArgumentCaptor.forClass(Pool.class);
    verify(this.manager).updatePoolsForMasterPool(eq(expectedModified), argPool.capture(), eq(sub.getQuantity()), eq(false), any(Map.class));
    TestUtil.assertPoolsAreEqual(TestUtil.copyFromSub(sub), 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) LinkedList(java.util.LinkedList) SourceSubscription(org.candlepin.model.SourceSubscription) Pool(org.candlepin.model.Pool) 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)

Aggregations

Pool (org.candlepin.model.Pool)31 SourceSubscription (org.candlepin.model.SourceSubscription)31 Product (org.candlepin.model.Product)23 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)19 Owner (org.candlepin.model.Owner)19 Subscription (org.candlepin.model.dto.Subscription)18 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)15 LinkedList (java.util.LinkedList)14 PoolType (org.candlepin.model.Pool.PoolType)10 Entitlement (org.candlepin.model.Entitlement)9 HashSet (java.util.HashSet)8 List (java.util.List)7 Branding (org.candlepin.model.Branding)7 HashMap (java.util.HashMap)6 Consumer (org.candlepin.model.Consumer)6 Matchers.anyList (org.mockito.Matchers.anyList)6 Map (java.util.Map)5 Date (java.util.Date)4 CandlepinQuery (org.candlepin.model.CandlepinQuery)4