Search in sources :

Example 26 with PoolUpdate

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

the class PoolRulesTest method standaloneVirtSubPoolUpdateNoChanges.

@Test
public void standaloneVirtSubPoolUpdateNoChanges() {
    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());
    Entitlement ent = mock(Entitlement.class);
    when(ent.getQuantity()).thenReturn(1);
    // 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);
    List<PoolUpdate> updates = poolRules.updatePools(p, pools, p.getQuantity(), Collections.<String, Product>emptyMap());
    assertEquals(0, updates.size());
}
Also used : Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) PoolUpdate(org.candlepin.policy.js.pool.PoolUpdate) Test(org.junit.Test)

Example 27 with PoolUpdate

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

the class PoolRulesTest method hostedVirtLimitRemoved.

@Test
public void hostedVirtLimitRemoved() {
    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, "4");
    List<Pool> pools = poolRules.createAndEnrichPools(p, new LinkedList<>());
    assertEquals(2, pools.size());
    // Now we remove virt_limit on the incoming subscription product and see if
    // the unlimited pool gets adjusted and flagged for cleanup:
    p.setProduct(TestUtil.createProduct(p.getProduct().getId(), p.getProduct().getName()));
    List<PoolUpdate> updates = poolRules.updatePools(p, pools, p.getQuantity(), TestUtil.stubChangedProducts(p.getProduct()));
    assertEquals(2, updates.size());
    // Regular pool should be in a sane state:
    PoolUpdate baseUpdate = updates.get(0);
    assertEquals(new Long(10), baseUpdate.getPool().getQuantity());
    assertFalse(baseUpdate.getPool().isMarkedForDelete());
    // Virt bonus pool should have quantity 0 and be flagged for cleanup:
    PoolUpdate virtUpdate = updates.get(1);
    assertEquals(new Long(0), virtUpdate.getPool().getQuantity());
    assertTrue(virtUpdate.getPool().isMarkedForDelete());
}
Also used : Pool(org.candlepin.model.Pool) PoolUpdate(org.candlepin.policy.js.pool.PoolUpdate) Test(org.junit.Test)

Example 28 with PoolUpdate

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

the class PoolRulesTest method orderNumberChanged.

@Test
public void orderNumberChanged() {
    Pool p = TestUtil.createPool(owner, TestUtil.createProduct());
    p.setOrderNumber("123");
    // Setup a pool with a single (different) order number:
    Pool p1 = TestUtil.clone(p);
    p1.setQuantity(2000L);
    p1.setOrderNumber("ABC");
    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.getOrderChanged());
    assertEquals("123", update.getPool().getOrderNumber());
}
Also used : Pool(org.candlepin.model.Pool) PoolUpdate(org.candlepin.policy.js.pool.PoolUpdate) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 29 with PoolUpdate

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

the class PoolRulesTest method updateVirtOnlyNoVirtLimit.

@Test
public void updateVirtOnlyNoVirtLimit() {
    when(configMock.getBoolean(ConfigProperties.STANDALONE)).thenReturn(false);
    Pool p = TestUtil.createPool(owner, TestUtil.createProduct());
    p.setQuantity(10L);
    // Setup a pool with a single (different) provided product:
    Pool p1 = TestUtil.clone(p);
    p1.setAttribute(Product.Attributes.VIRT_ONLY, "true");
    p1.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
    p1.setQuantity(20L);
    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);
    assertFalse(update.getProductsChanged());
    assertFalse(update.getDatesChanged());
    assertTrue(update.getQuantityChanged());
    assertEquals(Long.valueOf(10), update.getPool().getQuantity());
}
Also used : Pool(org.candlepin.model.Pool) PoolUpdate(org.candlepin.policy.js.pool.PoolUpdate) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 30 with PoolUpdate

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

the class PoolRulesTest method updatePoolSubProvidedProductsChanged.

@Test
public void updatePoolSubProvidedProductsChanged() {
    // Pool with two provided products:
    Pool p = TestUtil.createPool(owner, TestUtil.createProduct());
    Product subProd = TestUtil.createProduct();
    p.setDerivedProduct(subProd);
    Product product1 = TestUtil.createProduct();
    Product product2 = TestUtil.createProduct();
    Product product3 = TestUtil.createProduct();
    p.getDerivedProvidedProducts().add(product1);
    p.getDerivedProvidedProducts().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 = Arrays.asList(p1);
    List<PoolUpdate> updates = this.poolRules.updatePools(p, existingPools, p.getQuantity(), Collections.<String, Product>emptyMap());
    assertEquals(1, updates.size());
    assertEquals(2, updates.get(0).getPool().getDerivedProvidedProducts().size());
}
Also used : Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) 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