use of org.candlepin.policy.js.compliance.DateRange in project candlepin by candlepin.
the class InstalledProductStatusCalculatorTest method validRangeWhenGuestLimitOverridden.
@Test
public void validRangeWhenGuestLimitOverridden() {
Date now = new Date();
Owner owner = TestUtil.createOwner();
Product product = TestUtil.createProduct("p1", "product1");
product.setAttribute(Product.Attributes.GUEST_LIMIT, "2");
Product product2 = TestUtil.createProduct("p2", "product2");
product2.setAttribute(Product.Attributes.GUEST_LIMIT, "-1");
Product product3 = TestUtil.createProduct("p3", "product3");
Consumer consumer = this.mockConsumer(owner, product);
for (int i = 0; i < 5; i++) {
consumer.addGuestId(new GuestId(String.valueOf(i), consumer, this.getActiveGuestAttrs()));
}
DateRange range1 = this.rangeRelativeToDate(now, -4, 4);
DateRange range2 = this.rangeRelativeToDate(now, -2, 2);
consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_1", product, 10, range1, product));
consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_2", product2, 10, range2, product3));
this.mockConsumerEntitlements(consumer, consumer.getEntitlements());
this.mockOwnerProducts(owner, Arrays.asList(product, product2, product3));
this.consumerEnricher.enrich(consumer);
ConsumerInstalledProduct cip = this.getInstalledProduct(consumer, product);
assertEquals(range2.getStartDate(), cip.getStartDate());
assertEquals(range2.getEndDate(), cip.getEndDate());
}
use of org.candlepin.policy.js.compliance.DateRange in project candlepin by candlepin.
the class InstalledProductStatusCalculatorTest method validRangeWhenStackedButOneProvides.
// Test valid range with a full stack where one stacked entitlement provides the product
@Test
public void validRangeWhenStackedButOneProvides() {
Date now = new Date();
Owner owner = TestUtil.createOwner();
Product product = TestUtil.createProduct("p1", "product1");
Product product2 = TestUtil.createProduct("p2", "product2");
Consumer consumer = this.mockConsumer(owner, product);
consumer.setCreated(now);
DateRange range1 = this.rangeRelativeToDate(now, -4, 4);
consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_1", product, 1, range1, product));
consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_1", product2, 1, 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(range1.getEndDate(), cip.getEndDate());
}
use of org.candlepin.policy.js.compliance.DateRange in project candlepin by candlepin.
the class InstalledProductStatusCalculatorTest method validRangeWithMultipleWhereOneConsumesTheOthersSpan.
@Test
public void validRangeWithMultipleWhereOneConsumesTheOthersSpan() {
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, 4);
DateRange range2 = this.rangeRelativeToDate(now, 0, 2);
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(range1.getEndDate(), cip.getEndDate());
}
use of org.candlepin.policy.js.compliance.DateRange in project candlepin by candlepin.
the class InstalledProductStatusCalculatorTest method cannotStackFutureSubs.
@Test
public void cannotStackFutureSubs() {
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, 12);
DateRange range2 = this.rangeRelativeToDate(range1.getEndDate(), 5, 6);
consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_1", product, 1, range1, product));
consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_1", product, 1, range2, product));
this.mockConsumerEntitlements(consumer, consumer.getEntitlements());
this.mockOwnerProducts(owner, Arrays.asList(product));
ComplianceStatus status = complianceRules.getStatus(consumer, now);
assertEquals("partial", status.getStatus());
assertTrue(status.getPartialStacks().containsKey("stack_id_1"));
}
use of org.candlepin.policy.js.compliance.DateRange in project candlepin by candlepin.
the class InstalledProductStatusCalculatorTest method validRangeWithMultipleWhereExpiredEntitlementOverlaps.
@Test
public void validRangeWithMultipleWhereExpiredEntitlementOverlaps() {
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, -7, -3);
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(range2.getStartDate(), cip.getStartDate());
assertEquals(range1.getEndDate(), cip.getEndDate());
}
Aggregations