Search in sources :

Example 11 with DateRange

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

the class InstalledProductStatusCalculatorTest method validRangeCorrectPartialEntitlementNoGap.

@Test
public void validRangeCorrectPartialEntitlementNoGap() {
    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, 4, 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(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 12 with DateRange

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

the class InstalledProductStatusCalculatorTest method validRangeEndDateSetToFirstDateOfLosingValidStatus.

@Test
public void validRangeEndDateSetToFirstDateOfLosingValidStatus() {
    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, -2, 10);
    DateRange range3 = this.rangeRelativeToDate(now, -3, -1);
    DateRange range4 = this.rangeRelativeToDate(range1.getEndDate(), 0, 10);
    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));
    consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_1", product, 1, range3, product));
    consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_1", product, 1, range4, 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(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 13 with DateRange

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

the class InstalledProductStatusCalculatorTest method validRangeForSingleValidEnitlement.

@Test
public void validRangeForSingleValidEnitlement() {
    Owner owner = TestUtil.createOwner();
    Product product = TestUtil.createProduct("p1", "product1");
    Consumer consumer = this.mockConsumer(owner, product);
    DateRange range = this.rangeRelativeToDate(new Date(), -6, 6);
    Entitlement entitlement = this.mockEntitlement(owner, consumer, product, range, product);
    consumer.addEntitlement(entitlement);
    this.mockConsumerEntitlements(consumer, consumer.getEntitlements());
    this.mockOwnerProducts(owner, Arrays.asList(product));
    this.consumerEnricher.enrich(consumer);
    ConsumerInstalledProduct cip = this.getInstalledProduct(consumer, product);
    assertEquals(range.getStartDate(), cip.getStartDate());
    assertEquals(range.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) Entitlement(org.candlepin.model.Entitlement) Date(java.util.Date) Test(org.junit.Test)

Example 14 with DateRange

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

the class InstalledProductStatusCalculatorTest method validRangeIgnoresExpiredWithNoOverlap.

@Test
public void validRangeIgnoresExpiredWithNoOverlap() {
    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, -3);
    DateRange range2 = this.rangeRelativeToDate(now, -1, 6);
    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 15 with DateRange

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

the class InstalledProductStatusCalculatorTest method enricherDoesntSetArchVersion.

@Test
public void enricherDoesntSetArchVersion() {
    // test that the enricher does not set the arch and version when they are populated
    // in the CIP
    Owner owner = TestUtil.createOwner();
    owner.setId(TestUtil.randomString());
    Product product = TestUtil.createProduct("p1", "product1");
    Consumer consumer = this.mockConsumer(owner, product);
    DateRange range = this.rangeRelativeToDate(new Date(), -1, 4);
    Entitlement entitlement = this.mockEntitlement(owner, consumer, product, range, product);
    consumer.addEntitlement(entitlement);
    this.mockConsumerEntitlements(consumer, consumer.getEntitlements());
    ConsumerInstalledProduct cip = new ConsumerInstalledProduct();
    cip.setProductId(product.getId());
    consumer.addInstalledProduct(cip);
    this.mockOwnerProducts(owner, Arrays.asList(product));
    // Set these to non-null values to show they aren't overwritten
    cip.setArch("original arch");
    cip.setVersion("original version");
    product.setAttribute(Product.Attributes.ARCHITECTURE, "candlepin arch");
    product.setAttribute(Product.Attributes.VERSION, "candlepin version");
    this.consumerEnricher.enrich(consumer);
    assertEquals("original arch", cip.getArch());
    assertEquals("original version", cip.getVersion());
}
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) Entitlement(org.candlepin.model.Entitlement) Date(java.util.Date) Test(org.junit.Test)

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