use of org.candlepin.policy.js.quantity.SuggestedQuantity in project candlepin by candlepin.
the class CalculatedAttributesUtilTest method testCalculatedAttributesPresent.
@Test
public void testCalculatedAttributesPresent() {
for (PoolComplianceType type : PoolComplianceType.values()) {
when(mockPool.getComplianceType()).thenReturn(type);
Date date = new Date();
Map<String, String> attrs = attrUtil.buildCalculatedAttributes(mockPool, date);
assertTrue(attrs.containsKey("compliance_type"));
}
SuggestedQuantity suggested = new SuggestedQuantity();
suggested.setSuggested(1L);
suggested.setIncrement(1L);
Map<String, SuggestedQuantity> suggestedMap = new HashMap<>();
suggestedMap.put(pool1.getId(), suggested);
when(quantityRules.getSuggestedQuantities(any(List.class), any(Consumer.class), any(Date.class))).thenReturn(suggestedMap);
Date date = new Date();
attrUtil.setQuantityAttributes(pool1, consumer, date);
assertTrue(pool1.getCalculatedAttributes().containsKey("suggested_quantity"));
assertTrue(pool1.getCalculatedAttributes().containsKey("quantity_increment"));
}
use of org.candlepin.policy.js.quantity.SuggestedQuantity in project candlepin by candlepin.
the class CalculatedAttributesUtilTest method testQuantityIncrement.
@Test
public void testQuantityIncrement() {
Product product2 = TestUtil.createProduct("blah", "blah");
product2.setAttribute(Product.Attributes.INSTANCE_MULTIPLIER, "12");
productCurator.create(product2);
Pool pool2 = createPool(owner1, product2, 500L, TestUtil.createDate(2000, 1, 1), TestUtil.createDate(3000, 1, 1));
SuggestedQuantity suggested = new SuggestedQuantity();
suggested.setSuggested(1L);
suggested.setIncrement(12L);
Map<String, SuggestedQuantity> suggestedMap = new HashMap<>();
suggestedMap.put(pool2.getId(), suggested);
when(quantityRules.getSuggestedQuantities(any(List.class), any(Consumer.class), any(Date.class))).thenReturn(suggestedMap);
Date date = new Date();
attrUtil.setQuantityAttributes(pool2, consumer, date);
assertEquals("1", pool2.getCalculatedAttributes().get("suggested_quantity"));
assertEquals("12", pool2.getCalculatedAttributes().get("quantity_increment"));
}
use of org.candlepin.policy.js.quantity.SuggestedQuantity in project candlepin by candlepin.
the class CalculatedAttributesUtil method setQuantityAttributes.
public void setQuantityAttributes(List<Pool> poolList, Consumer c, Date date) {
if (c == null) {
return;
}
Map<String, SuggestedQuantity> results = quantityRules.getSuggestedQuantities(poolList, c, date);
for (Pool p : poolList) {
SuggestedQuantity suggested = results.get(p.getId());
Map<String, String> attrMap = p.getCalculatedAttributes();
if (attrMap == null) {
attrMap = new HashMap<>();
p.setCalculatedAttributes(attrMap);
}
attrMap.put("suggested_quantity", String.valueOf(suggested.getSuggested()));
attrMap.put("quantity_increment", String.valueOf(suggested.getIncrement()));
}
}
use of org.candlepin.policy.js.quantity.SuggestedQuantity in project candlepin by candlepin.
the class ConsumerBindUtil method getQuantityToBind.
public int getQuantityToBind(Pool pool, Consumer consumer) {
Date now = new Date();
// If the pool is being attached in the future, calculate
// suggested quantity on the start date
Date onDate = now.before(pool.getStartDate()) ? pool.getStartDate() : now;
SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, onDate);
int quantity = Math.max(suggested.getIncrement().intValue(), suggested.getSuggested().intValue());
// but whatever we do here, the bind will fail
return quantity;
}
Aggregations