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