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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations