Search in sources :

Example 21 with PoolUpdate

use of org.candlepin.policy.js.pool.PoolUpdate in project candlepin by candlepin.

the class PoolRulesInstanceTest method hostedInstanceBasedUpdatePool.

@Test
public void hostedInstanceBasedUpdatePool() {
    Subscription s = createInstanceBasedSub("INSTANCEPROD", 100, 2, false);
    Pool p = TestUtil.copyFromSub(s);
    List<Pool> pools = poolRules.createAndEnrichPools(p, new LinkedList<>());
    assertEquals(1, pools.size());
    Pool pool = pools.get(0);
    p = TestUtil.copyFromSub(s);
    // Change the value of instance multiplier:
    p.getProduct().setAttribute(Product.Attributes.INSTANCE_MULTIPLIER, "4");
    // Change the quantity:
    p.setQuantity(new Long(200));
    List<Pool> existingPools = new LinkedList<>();
    existingPools.add(pool);
    List<PoolUpdate> updates = poolRules.updatePools(p, existingPools, p.getQuantity(), TestUtil.stubChangedProducts(p.getProduct()));
    assertEquals(1, updates.size());
    PoolUpdate update = updates.get(0);
    assertTrue(update.getQuantityChanged());
    assertEquals(new Long(800), update.getPool().getQuantity());
}
Also used : Pool(org.candlepin.model.Pool) Subscription(org.candlepin.model.dto.Subscription) PoolUpdate(org.candlepin.policy.js.pool.PoolUpdate) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 22 with PoolUpdate

use of org.candlepin.policy.js.pool.PoolUpdate in project candlepin by candlepin.

the class PoolRulesTest method hostedVirtLimitSubUpdatesUnlimitedBonusVirtOnlyPool.

@Test
public void hostedVirtLimitSubUpdatesUnlimitedBonusVirtOnlyPool() {
    when(configMock.getBoolean(ConfigProperties.STANDALONE)).thenReturn(false);
    Pool p = createVirtLimitPool("virtLimitProduct", 10, 10);
    when(poolManagerMock.isManaged(eq(p))).thenReturn(true);
    p.getProduct().setAttribute(Product.Attributes.VIRT_LIMIT, "unlimited");
    List<Pool> pools = poolRules.createAndEnrichPools(p, new LinkedList<>());
    assertEquals(2, pools.size());
    Pool virtBonusPool = pools.get(1);
    // Quantity on bonus pool should be unlimited:
    assertEquals(new Long(-1), virtBonusPool.getQuantity());
    // Now we update the sub and see if that unlimited pool gets adjusted:
    p.getProduct().setAttribute(Product.Attributes.VIRT_LIMIT, "10");
    List<PoolUpdate> updates = poolRules.updatePools(p, pools, p.getQuantity(), TestUtil.stubChangedProducts(p.getProduct()));
    assertEquals(2, updates.size());
    PoolUpdate virtUpdate = updates.get(1);
    assertEquals(new Long(100), virtUpdate.getPool().getQuantity());
}
Also used : Pool(org.candlepin.model.Pool) PoolUpdate(org.candlepin.policy.js.pool.PoolUpdate) Test(org.junit.Test)

Example 23 with PoolUpdate

use of org.candlepin.policy.js.pool.PoolUpdate in project candlepin by candlepin.

the class PoolRulesTest method hostedVirtOnlySubUpdate.

@Test
public void hostedVirtOnlySubUpdate() {
    when(configMock.getBoolean(ConfigProperties.STANDALONE)).thenReturn(true);
    Pool p = createVirtOnlyPool("virtOnlyProduct", 10);
    List<Pool> pools = poolRules.createAndEnrichPools(p, new LinkedList<>());
    assertEquals(1, pools.size());
    p = createVirtOnlyPool("virtOnlyProduct", 20);
    List<PoolUpdate> updates = poolRules.updatePools(p, pools, p.getQuantity(), Collections.<String, Product>emptyMap());
    assertEquals(1, updates.size());
    Pool updated = updates.get(0).getPool();
    assertEquals(new Long(20), updated.getQuantity());
}
Also used : Pool(org.candlepin.model.Pool) PoolUpdate(org.candlepin.policy.js.pool.PoolUpdate) Test(org.junit.Test)

Example 24 with PoolUpdate

use of org.candlepin.policy.js.pool.PoolUpdate in project candlepin by candlepin.

the class PoolRulesTest method providedProductsChanged.

@Test
public void providedProductsChanged() {
    // Pool with two provided products:
    Pool p = TestUtil.createPool(owner, TestUtil.createProduct());
    Product product1 = TestUtil.createProduct();
    Product product2 = TestUtil.createProduct();
    Product product3 = TestUtil.createProduct();
    p.getProvidedProducts().add(product1);
    p.getProvidedProducts().add(product2);
    // Setup a pool with a single (different) provided product:
    Pool p1 = TestUtil.clone(p);
    p1.getProvidedProducts().clear();
    p1.getProvidedProducts().add(product3);
    List<Pool> existingPools = new LinkedList<>();
    existingPools.add(p1);
    List<PoolUpdate> updates = this.poolRules.updatePools(p, existingPools, p.getQuantity(), Collections.<String, Product>emptyMap());
    assertEquals(1, updates.size());
    PoolUpdate update = updates.get(0);
    assertTrue(update.getProductsChanged());
    assertFalse(update.getDatesChanged());
    assertFalse(update.getQuantityChanged());
}
Also used : Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) PoolUpdate(org.candlepin.policy.js.pool.PoolUpdate) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 25 with PoolUpdate

use of org.candlepin.policy.js.pool.PoolUpdate in project candlepin by candlepin.

the class PoolRulesTest method standaloneVirtSubPoolUpdateVirtLimitChanged.

@Test
public void standaloneVirtSubPoolUpdateVirtLimitChanged() {
    when(configMock.getBoolean(ConfigProperties.STANDALONE)).thenReturn(true);
    Pool p = createVirtLimitPool("virtLimitProduct", 10, 10);
    when(poolManagerMock.isManaged(eq(p))).thenReturn(true);
    List<Pool> pools = poolRules.createAndEnrichPools(p, new LinkedList<>());
    assertEquals(2, pools.size());
    p.setQuantity(new Long(20));
    Entitlement ent = mock(Entitlement.class);
    when(ent.getQuantity()).thenReturn(4);
    // Now make a pool that would have been created for guests only after a host
    // bound to the parent pool:
    Pool consumerSpecificPool = TestUtil.clone(p);
    consumerSpecificPool.setAttribute(Pool.Attributes.REQUIRES_HOST, "FAKEUUID");
    consumerSpecificPool.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
    consumerSpecificPool.setAttribute(Product.Attributes.VIRT_ONLY, "true");
    consumerSpecificPool.setQuantity(10L);
    consumerSpecificPool.setSourceEntitlement(ent);
    pools.add(consumerSpecificPool);
    p.getProduct().setAttribute(Product.Attributes.VIRT_LIMIT, "40");
    List<PoolUpdate> updates = poolRules.updatePools(p, pools, p.getQuantity(), TestUtil.stubChangedProducts(p.getProduct()));
    assertEquals(3, updates.size());
    Pool regular = updates.get(0).getPool();
    Pool unmappedSubPool = updates.get(1).getPool();
    Pool subPool = updates.get(2).getPool();
    assertEquals("40", regular.getProduct().getAttributeValue(Product.Attributes.VIRT_LIMIT));
    assertEquals(new Long(40), subPool.getQuantity());
    assertEquals(new Long(800), unmappedSubPool.getQuantity());
}
Also used : Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) PoolUpdate(org.candlepin.policy.js.pool.PoolUpdate) Test(org.junit.Test)

Aggregations

PoolUpdate (org.candlepin.policy.js.pool.PoolUpdate)38 Test (org.junit.Test)35 Pool (org.candlepin.model.Pool)28 LinkedList (java.util.LinkedList)10 Product (org.candlepin.model.Product)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 EventBuilder (org.candlepin.audit.EventBuilder)4 Entitlement (org.candlepin.model.Entitlement)4 Subscription (org.candlepin.model.dto.Subscription)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)2 Branding (org.candlepin.model.Branding)2 Transactional (com.google.inject.persist.Transactional)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Event (org.candlepin.audit.Event)1 CandlepinQuery (org.candlepin.model.CandlepinQuery)1 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)1