Search in sources :

Example 11 with PoolUpdate

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

the class PoolRulesTest method productNameChanged.

@Test
public void productNameChanged() {
    Pool p = TestUtil.createPool(owner, TestUtil.createProduct());
    // Setup a pool with a single (different) provided product:
    Pool p1 = TestUtil.clone(p);
    p1.getProduct().setName("somethingelse");
    List<Pool> existingPools = Arrays.asList(p1);
    List<PoolUpdate> updates = this.poolRules.updatePools(p, existingPools, p.getQuantity(), TestUtil.stubChangedProducts(p.getProduct()));
    assertEquals(1, updates.size());
    PoolUpdate update = updates.get(0);
    assertTrue(update.getProductsChanged());
    assertFalse(update.getDatesChanged());
    assertFalse(update.getQuantityChanged());
    assertEquals(p.getProduct().getName(), update.getPool().getProductName());
}
Also used : Pool(org.candlepin.model.Pool) PoolUpdate(org.candlepin.policy.js.pool.PoolUpdate) Test(org.junit.Test)

Example 12 with PoolUpdate

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

the class PoolRulesTest method standaloneVirtLimitSubUpdate.

@Test
public void standaloneVirtLimitSubUpdate() {
    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<>());
    // Should be unmapped virt_only pool:
    assertEquals(2, pools.size());
    Pool physicalPool = pools.get(0);
    assertEquals(0, physicalPool.getAttributes().size());
    p = createVirtLimitPool("virtLimitProduct", 10, 10);
    p.setQuantity(50L);
    List<PoolUpdate> updates = poolRules.updatePools(p, pools, p.getQuantity(), Collections.<String, Product>emptyMap());
    assertEquals(2, updates.size());
    physicalPool = updates.get(0).getPool();
    assertEquals(new Long(50), physicalPool.getQuantity());
    assertEquals(0, physicalPool.getAttributes().size());
}
Also used : Pool(org.candlepin.model.Pool) PoolUpdate(org.candlepin.policy.js.pool.PoolUpdate) Test(org.junit.Test)

Example 13 with PoolUpdate

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

the class PoolRulesTest method virtOnlyQuantityChanged.

@Test
public void virtOnlyQuantityChanged() {
    Pool p = TestUtil.createPool(owner, TestUtil.createProduct());
    p.getProduct().setAttribute(Product.Attributes.VIRT_LIMIT, "5");
    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(40L);
    List<Pool> existingPools = Arrays.asList(p1);
    List<PoolUpdate> updates = this.poolRules.updatePools(p, existingPools, p.getQuantity(), null);
    assertEquals(1, updates.size());
    PoolUpdate update = updates.get(0);
    assertFalse(update.getProductsChanged());
    assertFalse(update.getDatesChanged());
    assertFalse(update.getProductAttributesChanged());
    assertTrue(update.getQuantityChanged());
    assertEquals(Long.valueOf(50), update.getPool().getQuantity());
}
Also used : Pool(org.candlepin.model.Pool) PoolUpdate(org.candlepin.policy.js.pool.PoolUpdate) Test(org.junit.Test)

Example 14 with PoolUpdate

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

the class PoolRulesTest method datesNameChanged.

@Test
public void datesNameChanged() {
    Pool p = TestUtil.createPool(owner, TestUtil.createProduct());
    // Setup a pool with a single (different) provided product:
    Pool p1 = TestUtil.clone(p);
    p1.setEndDate(new Date());
    List<Pool> existingPools = Arrays.asList(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());
    assertTrue(update.getDatesChanged());
    assertFalse(update.getQuantityChanged());
    assertEquals(p.getEndDate(), update.getPool().getEndDate());
}
Also used : Pool(org.candlepin.model.Pool) PoolUpdate(org.candlepin.policy.js.pool.PoolUpdate) Date(java.util.Date) Test(org.junit.Test)

Example 15 with PoolUpdate

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

the class PoolRulesTest method quantityChanged.

@Test
public void quantityChanged() {
    Pool p = TestUtil.createPool(owner, TestUtil.createProduct());
    // Setup a pool with a single (different) provided product:
    Pool p1 = TestUtil.clone(p);
    p1.setQuantity(2000L);
    List<Pool> existingPools = Arrays.asList(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(p.getQuantity(), update.getPool().getQuantity());
}
Also used : 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