Search in sources :

Example 21 with DateRange

use of org.candlepin.policy.js.compliance.DateRange in project candlepin by candlepin.

the class InstalledProductStatusCalculatorTest method validRangeIgnoresFutureWithOverlap.

@Test
public void validRangeIgnoresFutureWithOverlap() {
    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, 12, 24);
    DateRange range2 = this.rangeRelativeToDate(now, 0, 13);
    consumer.addEntitlement(this.mockEntitlement(owner, consumer, product, range2, product));
    consumer.addEntitlement(this.mockEntitlement(owner, consumer, product, range1, 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());
}
Also used : Owner(org.candlepin.model.Owner) DateRange(org.candlepin.policy.js.compliance.DateRange) Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Date(java.util.Date) Test(org.junit.Test)

Example 22 with DateRange

use of org.candlepin.policy.js.compliance.DateRange in project candlepin by candlepin.

the class InstalledProductStatusCalculatorTest method validRangeCorrectPartialEntitlementGap.

@Test
public void validRangeCorrectPartialEntitlementGap() {
    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, 5, 9);
    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));
    this.consumerEnricher.enrich(consumer);
    ConsumerInstalledProduct cip = this.getInstalledProduct(consumer, product);
    assertEquals(range1.getStartDate(), cip.getStartDate());
    assertEquals(range1.getEndDate(), cip.getEndDate());
}
Also used : Owner(org.candlepin.model.Owner) DateRange(org.candlepin.policy.js.compliance.DateRange) Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Date(java.util.Date) Test(org.junit.Test)

Example 23 with DateRange

use of org.candlepin.policy.js.compliance.DateRange in project candlepin by candlepin.

the class InstalledProductStatusCalculatorTest method validRangeWithMultipleEntsWithOverlap.

@Test
public void validRangeWithMultipleEntsWithOverlap() {
    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, 1, 8);
    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());
}
Also used : Owner(org.candlepin.model.Owner) DateRange(org.candlepin.policy.js.compliance.DateRange) Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Date(java.util.Date) Test(org.junit.Test)

Example 24 with DateRange

use of org.candlepin.policy.js.compliance.DateRange in project candlepin by candlepin.

the class InstalledProductStatusCalculatorTest method validRangeIgnoresFutureWithNoOverlap.

@Test
public void validRangeIgnoresFutureWithNoOverlap() {
    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, 6, 12);
    DateRange range2 = this.rangeRelativeToDate(now, -1, 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(range2.getStartDate(), cip.getStartDate());
    assertEquals(range2.getEndDate(), cip.getEndDate());
}
Also used : Owner(org.candlepin.model.Owner) DateRange(org.candlepin.policy.js.compliance.DateRange) Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Date(java.util.Date) Test(org.junit.Test)

Example 25 with DateRange

use of org.candlepin.policy.js.compliance.DateRange in project candlepin by candlepin.

the class InstalledProductStatusCalculatorTest method rangeRelativeToDate.

private DateRange rangeRelativeToDate(Date relativeTo, int startMonths, int endMonths) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(relativeTo);
    cal.add(Calendar.MONTH, startMonths);
    Date start = cal.getTime();
    cal.setTime(relativeTo);
    cal.add(Calendar.MONTH, endMonths);
    Date end = cal.getTime();
    return new DateRange(start, end);
}
Also used : DateRange(org.candlepin.policy.js.compliance.DateRange) Calendar(java.util.Calendar) Date(java.util.Date)

Aggregations

DateRange (org.candlepin.policy.js.compliance.DateRange)28 Date (java.util.Date)27 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)27 Product (org.candlepin.model.Product)27 Consumer (org.candlepin.model.Consumer)26 Owner (org.candlepin.model.Owner)26 Test (org.junit.Test)26 Entitlement (org.candlepin.model.Entitlement)4 ComplianceStatus (org.candlepin.policy.js.compliance.ComplianceStatus)2 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 GuestId (org.candlepin.model.GuestId)1