use of org.candlepin.model.Consumer 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.model.Consumer 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.model.Consumer in project candlepin by candlepin.
the class InstalledProductStatusCalculatorTest method validRangeIsNullWhenOnlyExpiredEntitlementExists.
@Test
public void validRangeIsNullWhenOnlyExpiredEntitlementExists() {
Date now = new Date();
Owner owner = TestUtil.createOwner();
Product product = TestUtil.createProduct("p1", "product1");
Consumer consumer = this.mockConsumer(owner, product);
consumer.setCreated(now);
DateRange range1 = this.rangeRelativeToDate(now, -4, -2);
consumer.addEntitlement(this.mockEntitlement(owner, consumer, product, range1, product));
this.mockConsumerEntitlements(consumer, consumer.getEntitlements());
this.mockOwnerProducts(owner, Arrays.asList(product));
this.consumerEnricher.enrich(consumer);
ConsumerInstalledProduct cip = this.getInstalledProduct(consumer, product);
assertEquals(null, cip.getStartDate());
assertEquals(null, cip.getEndDate());
}
use of org.candlepin.model.Consumer in project candlepin by candlepin.
the class InstalledProductStatusCalculatorTest method validRangeWithMultipleWhereFutureEntitlementOverlaps.
@Test
public void validRangeWithMultipleWhereFutureEntitlementOverlaps() {
Date now = new Date();
Owner owner = TestUtil.createOwner();
Product product = TestUtil.createProduct("p1", "product1");
Consumer consumer = this.mockConsumer(owner, product);
consumer.setCreated(now);
DateRange range1 = this.rangeRelativeToDate(now, -4, 2);
DateRange range2 = this.rangeRelativeToDate(now, 2, 4);
consumer.addEntitlement(this.mockEntitlement(owner, consumer, product, range2, product));
consumer.addEntitlement(this.mockEntitlement(owner, consumer, product, range1, product));
this.mockConsumerEntitlements(consumer, consumer.getEntitlements());
this.mockOwnerProducts(owner, Arrays.asList(product));
this.consumerEnricher.enrich(consumer);
ConsumerInstalledProduct cip = this.getInstalledProduct(consumer, product);
assertEquals(range1.getStartDate(), cip.getStartDate());
assertEquals(range2.getEndDate(), cip.getEndDate());
}
use of org.candlepin.model.Consumer in project candlepin by candlepin.
the class InstalledProductStatusCalculatorTest method validRangeConsidersInvalidGapBetweenNonStackedEntitlement.
@Test
public void validRangeConsidersInvalidGapBetweenNonStackedEntitlement() {
Date now = new Date();
Owner owner = TestUtil.createOwner();
Product product = TestUtil.createProduct("p1", "product1");
Product stacked = TestUtil.createProduct("p1_stack", "product1-stacked");
Consumer consumer = this.mockConsumer(owner, product);
consumer.setCreated(now);
DateRange range1 = this.rangeRelativeToDate(now, -4, -2);
DateRange range2 = this.rangeRelativeToDate(now, -3, 2);
DateRange range3 = this.rangeRelativeToDate(now, -1, 4);
consumer.addEntitlement(this.mockEntitlement(owner, consumer, product, range1, product));
consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_1", stacked, 1, range2, product));
consumer.addEntitlement(this.mockEntitlement(owner, consumer, product, range3, product));
this.mockConsumerEntitlements(consumer, consumer.getEntitlements());
this.mockOwnerProducts(owner, Arrays.asList(product));
this.consumerEnricher.enrich(consumer);
ConsumerInstalledProduct cip = this.getInstalledProduct(consumer, product);
assertEquals(range3.getStartDate(), cip.getStartDate());
assertEquals(range3.getEndDate(), cip.getEndDate());
}
Aggregations