Search in sources :

Example 36 with ConsumerInstalledProduct

use of org.candlepin.model.ConsumerInstalledProduct 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 37 with ConsumerInstalledProduct

use of org.candlepin.model.ConsumerInstalledProduct 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)

Example 38 with ConsumerInstalledProduct

use of org.candlepin.model.ConsumerInstalledProduct in project candlepin by candlepin.

the class InstalledProductStatusCalculatorTest method mockConsumer.

private Consumer mockConsumer(Owner owner, Product... installedProducts) {
    ConsumerType ctype = new ConsumerType(ConsumerType.ConsumerTypeEnum.SYSTEM);
    ctype.setId("test-ctype-" + TestUtil.randomInt());
    Consumer consumer = new Consumer();
    consumer.setType(ctype);
    consumer.setOwner(owner);
    for (Product product : installedProducts) {
        consumer.addInstalledProduct(new ConsumerInstalledProduct(consumer, product));
    }
    consumer.setFact("cpu.cpu_socket(s)", "4");
    when(this.consumerTypeCurator.find(eq(ctype.getId()))).thenReturn(ctype);
    when(this.consumerTypeCurator.getConsumerType(eq(consumer))).thenReturn(ctype);
    return consumer;
}
Also used : Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ConsumerType(org.candlepin.model.ConsumerType)

Example 39 with ConsumerInstalledProduct

use of org.candlepin.model.ConsumerInstalledProduct 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());
}
Also used : Owner(org.candlepin.model.Owner) DateRange(org.candlepin.policy.js.compliance.DateRange) Consumer(org.candlepin.model.Consumer) GuestId(org.candlepin.model.GuestId) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Date(java.util.Date) Test(org.junit.Test)

Example 40 with ConsumerInstalledProduct

use of org.candlepin.model.ConsumerInstalledProduct 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());
}
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)

Aggregations

ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)66 Consumer (org.candlepin.model.Consumer)54 Product (org.candlepin.model.Product)51 Test (org.junit.Test)49 Owner (org.candlepin.model.Owner)44 Date (java.util.Date)35 DateRange (org.candlepin.policy.js.compliance.DateRange)26 HashSet (java.util.HashSet)14 ArrayList (java.util.ArrayList)13 Entitlement (org.candlepin.model.Entitlement)11 Pool (org.candlepin.model.Pool)11 ConsumerType (org.candlepin.model.ConsumerType)10 AutobindData (org.candlepin.resource.dto.AutobindData)10 HashMap (java.util.HashMap)8 ConsumerCapability (org.candlepin.model.ConsumerCapability)7 List (java.util.List)6 ProductData (org.candlepin.model.dto.ProductData)6 ConsumerInstalledProductDTO (org.candlepin.dto.api.v1.ConsumerInstalledProductDTO)4 Environment (org.candlepin.model.Environment)4 GuestId (org.candlepin.model.GuestId)4