use of org.candlepin.policy.js.pool.PoolUpdate in project candlepin by candlepin.
the class PoolRulesStackDerivedTest method virtLimitFromFirstVirtLimitEntBatch.
@Test
public void virtLimitFromFirstVirtLimitEntBatch() {
CandlepinQuery cqmock = mock(CandlepinQuery.class);
stackedEnts.clear();
Entitlement e1 = createEntFromPool(pool1);
e1.setQuantity(4);
stackedEnts.add(e1);
Entitlement e2 = createEntFromPool(pool4);
e2.setQuantity(16);
stackedEnts.add(e2);
Class<Set<String>> listClass = (Class<Set<String>>) (Class) HashSet.class;
ArgumentCaptor<Set<String>> arg = ArgumentCaptor.forClass(listClass);
when(cqmock.iterator()).thenReturn(stackedEnts.iterator());
when(entCurMock.findByStackIds(eq(consumer), arg.capture())).thenReturn(cqmock);
List<PoolUpdate> updates = poolRules.updatePoolsFromStack(consumer, Arrays.asList(stackDerivedPool, stackDerivedPool2), false);
Set<String> stackIds = arg.getValue();
assertEquals(2, stackIds.size());
assertThat(stackIds, hasItems(STACK, STACK + "3"));
for (PoolUpdate update : updates) {
assertTrue(update.changed());
assertTrue(update.getQuantityChanged());
}
assertEquals((Long) 2L, stackDerivedPool.getQuantity());
assertEquals((Long) 9L, stackDerivedPool2.getQuantity());
}
use of org.candlepin.policy.js.pool.PoolUpdate in project candlepin by candlepin.
the class PoolRulesStackDerivedTest method mergedProductAttributes.
@Test
public void mergedProductAttributes() {
Entitlement ent1 = createEntFromPool(pool1);
ent1.setCreated(new Date(System.currentTimeMillis() - 86400000));
stackedEnts.add(ent1);
stackedEnts.add(createEntFromPool(pool3));
PoolUpdate update = poolRules.updatePoolFromStack(stackDerivedPool, null);
assertTrue(update.changed());
assertTrue(update.getProductAttributesChanged());
assertEquals(pool1.getProductAttributes(), stackDerivedPool.getProductAttributes());
}
use of org.candlepin.policy.js.pool.PoolUpdate in project candlepin by candlepin.
the class PoolRulesInstanceTest method hostedInstanceBasedRemoved.
@Test
public void hostedInstanceBasedRemoved() {
Subscription s = createInstanceBasedSub("INSTANCEPROD", 100, 2, false);
Pool masterPool = TestUtil.copyFromSub(s);
List<Pool> pools = poolRules.createAndEnrichPools(masterPool, new LinkedList<>());
assertEquals(1, pools.size());
Pool pool = pools.get(0);
// Remove the instance multiplier attribute entirely, pool quantity should
// revert to half of what it was. No existing entitlements need to be adjusted,
// we will let a (future) overconsumption routine handle that.
masterPool = TestUtil.copyFromSub(s);
masterPool.getProduct().removeAttribute(Product.Attributes.INSTANCE_MULTIPLIER);
List<Pool> existingPools = new LinkedList<>();
existingPools.add(pool);
List<PoolUpdate> updates = poolRules.updatePools(masterPool, existingPools, s.getQuantity(), TestUtil.stubChangedProducts(masterPool.getProduct()));
assertEquals(1, updates.size());
PoolUpdate update = updates.get(0);
assertTrue(update.getQuantityChanged());
assertEquals(new Long(100), update.getPool().getQuantity());
assertFalse(update.getPool().getProduct().hasAttribute(Product.Attributes.INSTANCE_MULTIPLIER));
}
use of org.candlepin.policy.js.pool.PoolUpdate in project candlepin by candlepin.
the class PoolRulesTest method contractNumberChanged.
@Test
public void contractNumberChanged() {
Pool p = TestUtil.createPool(owner, TestUtil.createProduct());
p.setContractNumber("123");
// Setup a pool with a single (different) provided product:
Pool p1 = TestUtil.clone(p);
p1.setQuantity(2000L);
p1.setContractNumber("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().getContractNumber());
}
use of org.candlepin.policy.js.pool.PoolUpdate in project candlepin by candlepin.
the class PoolRulesTest method brandingChanged.
@Test
public void brandingChanged() {
Pool p = TestUtil.createPool(owner, TestUtil.createProduct());
Pool p1 = TestUtil.clone(p);
// Add some branding to the pool and do an update:
Branding b1 = new Branding("8000", "OS", "Awesome OS Branded");
Branding b2 = new Branding("8001", "OS", "Awesome OS Branded 2");
p.getBranding().add(b1);
p.getBranding().add(b2);
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());
assertFalse(update.getQuantityChanged());
assertTrue(update.getBrandingChanged());
assertTrue(update.changed());
assertEquals(2, update.getPool().getBranding().size());
assertTrue(update.getPool().getBranding().contains(b1));
assertTrue(update.getPool().getBranding().contains(b2));
}
Aggregations