Search in sources :

Example 71 with Pool

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

the class PoolManagerTest method subProductIdCopiedOntoPoolWhenCreatingNewPool.

@Test
public void subProductIdCopiedOntoPoolWhenCreatingNewPool() {
    Product product = TestUtil.createProduct();
    Product subProduct = TestUtil.createProduct();
    Subscription sub = TestUtil.createSubscription(owner, product);
    sub.setDerivedProduct(subProduct.toDTO());
    this.mockProducts(owner, product, subProduct);
    PoolRules pRules = new PoolRules(manager, mockConfig, entitlementCurator, mockOwnerProductCurator, mockProductCurator);
    List<Pool> pools = pRules.createAndEnrichPools(sub);
    assertEquals(1, pools.size());
    Pool resultPool = pools.get(0);
    assertEquals(subProduct, resultPool.getDerivedProduct());
}
Also used : PoolRules(org.candlepin.policy.js.pool.PoolRules) 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) Test(org.junit.Test)

Example 72 with Pool

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

the class PoolManagerTest method testDeleteExcessEntitlements.

@Test
public void testDeleteExcessEntitlements() throws EntitlementRefusedException {
    ConsumerType ctype = this.mockConsumerType(TestUtil.createConsumerType());
    Consumer consumer = TestUtil.createConsumer(ctype, owner);
    Subscription sub = TestUtil.createSubscription(owner, product);
    sub.setId("testing-subid");
    pool.setSourceSubscription(new SourceSubscription(sub.getId(), "master"));
    Pool derivedPool = TestUtil.createPool(owner, product, 1);
    derivedPool.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
    derivedPool.setSourceSubscription(new SourceSubscription(sub.getId(), "der"));
    derivedPool.setConsumed(3L);
    derivedPool.setId("derivedPool");
    Entitlement masterEnt = new Entitlement(pool, consumer, owner, 5);
    Entitlement derivedEnt = new Entitlement(derivedPool, consumer, owner, 1);
    derivedEnt.setId("1");
    Set<Entitlement> ents = new HashSet<>();
    ents.add(derivedEnt);
    derivedPool.setEntitlements(ents);
    // before
    assertEquals(3, derivedPool.getConsumed().intValue());
    assertEquals(1, derivedPool.getEntitlements().size());
    Collection<Pool> overPools = Collections.singletonList(derivedPool);
    when(mockPoolCurator.lockAndLoad(any(Collection.class))).thenReturn(overPools);
    when(mockPoolCurator.lockAndLoad(pool)).thenReturn(pool);
    when(enforcerMock.update(any(Consumer.class), any(Entitlement.class), any(Integer.class))).thenReturn(new ValidationResult());
    when(mockPoolCurator.lookupOversubscribedBySubscriptionIds(any(String.class), anyMap())).thenReturn(Collections.singletonList(derivedPool));
    when(mockPoolCurator.retrieveOrderedEntitlementsOf(anyListOf(Pool.class))).thenReturn(Collections.singletonList(derivedEnt));
    when(mockPoolCurator.lockAndLoad(eq(derivedPool))).thenReturn(derivedPool);
    pool.setId("masterpool");
    manager.adjustEntitlementQuantity(consumer, masterEnt, 3);
    Class<List<Entitlement>> listClass = (Class<List<Entitlement>>) (Class) ArrayList.class;
    ArgumentCaptor<List<Entitlement>> arg = ArgumentCaptor.forClass(listClass);
    verify(entitlementCurator).batchDelete(arg.capture());
    List<Entitlement> entsDeleted = arg.getValue();
    assertThat(entsDeleted, hasItem(derivedEnt));
    assertEquals(2, derivedPool.getConsumed().intValue());
}
Also used : ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) ValidationResult(org.candlepin.policy.ValidationResult) SourceSubscription(org.candlepin.model.SourceSubscription) Consumer(org.candlepin.model.Consumer) Matchers.anyCollection(org.mockito.Matchers.anyCollection) Collection(java.util.Collection) Pool(org.candlepin.model.Pool) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Matchers.anyList(org.mockito.Matchers.anyList) ConsumerType(org.candlepin.model.ConsumerType) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) Entitlement(org.candlepin.model.Entitlement) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 73 with Pool

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

the class PoolManagerTest method productAttributesCopiedOntoPoolWhenCreatingNewPool.

@Test
public void productAttributesCopiedOntoPoolWhenCreatingNewPool() {
    // Why is this test in pool manager? It looks like a pool rules test.
    PoolRules pRules = new PoolRules(manager, mockConfig, entitlementCurator, mockOwnerProductCurator, mockProductCurator);
    Product product = TestUtil.createProduct();
    product.setLocked(true);
    String testAttributeKey = "multi-entitlement";
    String expectedAttributeValue = "yes";
    product.setAttribute(testAttributeKey, expectedAttributeValue);
    Subscription sub = TestUtil.createSubscription(owner, product);
    this.mockProducts(owner, product);
    List<Pool> pools = pRules.createAndEnrichPools(sub);
    assertEquals(1, pools.size());
    Pool resultPool = pools.get(0);
    assertNotNull(resultPool.getProduct());
    assertTrue(resultPool.getProduct().hasAttribute(testAttributeKey));
    assertEquals(expectedAttributeValue, resultPool.getProduct().getAttributeValue(testAttributeKey));
}
Also used : PoolRules(org.candlepin.policy.js.pool.PoolRules) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Matchers.anyString(org.mockito.Matchers.anyString) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) Test(org.junit.Test)

Example 74 with Pool

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

the class PoolManagerTest method testRefreshPoolsDeletesOrphanedPools.

@Test
public void testRefreshPoolsDeletesOrphanedPools() {
    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"));
    pools.add(p);
    mockSubsList(subscriptions);
    mockPoolsList(pools);
    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.mockProductImport(owner, product);
    this.mockContentImport(owner, new Content[] {});
    Owner owner = getOwner();
    when(mockOwnerCurator.lookupByKey(owner.getKey())).thenReturn(owner);
    this.manager.getRefresher(mockSubAdapter, mockOwnerAdapter).add(owner).run();
    List<Pool> poolsToDelete = Arrays.asList(p);
    verify(this.manager).deletePools(eq(poolsToDelete));
}
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 75 with Pool

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

the class PoolManagerTest method testCreateAndEnrichPoolForPool.

@Test
public void testCreateAndEnrichPoolForPool() {
    List<Pool> newPools = new LinkedList<>();
    Pool p = TestUtil.createPool(TestUtil.createProduct());
    newPools.add(p);
    when(poolRulesMock.createAndEnrichPools(eq(p), any(List.class))).thenReturn(newPools);
    this.manager.createAndEnrichPools(p);
    verify(this.mockPoolCurator, times(1)).create(any(Pool.class));
}
Also used : Pool(org.candlepin.model.Pool) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Matchers.anyList(org.mockito.Matchers.anyList) LinkedList(java.util.LinkedList) 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