Search in sources :

Example 46 with ConsumerInstalledProduct

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

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

the class InstalledProductStatusCalculatorTest method multiEntGreenNowInnerDatesYellowFutureWithOverlap.

@Test
public void multiEntGreenNowInnerDatesYellowFutureWithOverlap() {
    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(now, -3, 10);
    DateRange range3 = this.rangeRelativeToDate(now, 11, 24);
    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));
    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 48 with ConsumerInstalledProduct

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

the class InstalledProductStatusCalculatorTest method enricherSetsArchVersion.

@Test
public void enricherSetsArchVersion() {
    // test that the enricher sets the arch and version when they are null in the CIP
    Owner owner = TestUtil.createOwner();
    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));
    product.setAttribute(Product.Attributes.ARCHITECTURE, "candlepin arch");
    product.setAttribute(Product.Attributes.VERSION, "candlepin version");
    this.consumerEnricher.enrich(consumer);
    assertEquals("candlepin arch", cip.getArch());
    assertEquals("candlepin 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 49 with ConsumerInstalledProduct

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

the class PoolManagerFunctionalTest method testBatchBindZeroQuantity.

@Test
public void testBatchBindZeroQuantity() throws EntitlementRefusedException {
    Owner owner = createOwner();
    Product p = TestUtil.createProduct("test-product", "Test Product");
    productCurator.create(p);
    Consumer devSystem = new Consumer("dev", "user", owner, systemType);
    devSystem.setFact("dev_sku", p.getId());
    devSystem.addInstalledProduct(new ConsumerInstalledProduct(p));
    consumerCurator.create(devSystem);
    Pool pool1 = createPool(owner, p, 1L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2050, 3, 2));
    pool1.setAttribute(Pool.Attributes.DEVELOPMENT_POOL, "true");
    pool1.setAttribute(Pool.Attributes.REQUIRES_CONSUMER, devSystem.getUuid());
    pool1.setConsumed(1L);
    poolCurator.create(pool1);
    assertEquals(1, poolCurator.find(pool1.getId()).getConsumed().intValue());
    Pool pool2 = createPool(owner, p, 1L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2050, 3, 2));
    pool2.setConsumed(1L);
    poolCurator.create(pool2);
    Map<String, Integer> poolQuantities = new HashMap<>();
    poolQuantities.put(pool1.getId(), 0);
    poolQuantities.put(pool2.getId(), 0);
    List<Entitlement> results = poolManager.entitleByPools(devSystem, poolQuantities);
    assertEquals(2, results.size());
    assertEquals(1, results.get(0).getQuantity().intValue());
    assertEquals(1, results.get(1).getQuantity().intValue());
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) HashMap(java.util.HashMap) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 50 with ConsumerInstalledProduct

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

the class PoolManagerFunctionalTest method testBatchBindError.

@Test
public void testBatchBindError() throws EntitlementRefusedException {
    Owner owner = createOwner();
    Product p = TestUtil.createProduct("test-product", "Test Product");
    p.setAttribute(Pool.Attributes.MULTI_ENTITLEMENT, "yes");
    productCurator.create(p);
    Consumer devSystem = new Consumer("dev", "user", owner, systemType);
    devSystem.setFact("dev_sku", p.getId());
    devSystem.addInstalledProduct(new ConsumerInstalledProduct(p));
    consumerCurator.create(devSystem);
    Pool pool1 = createPool(owner, p, 1L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2050, 3, 2));
    pool1.setAttribute(Pool.Attributes.DEVELOPMENT_POOL, "true");
    pool1.setAttribute(Pool.Attributes.REQUIRES_CONSUMER, devSystem.getUuid());
    poolCurator.create(pool1);
    Entitlement ent = createEntitlement(owner, devSystem, pool1, createEntitlementCertificate("keycert", "cert"));
    ent.setQuantity(1);
    entitlementCurator.create(ent);
    pool1.setConsumed(pool1.getConsumed() + 1);
    poolCurator.merge(pool1);
    poolCurator.flush();
    assertEquals(1, poolCurator.find(pool1.getId()).getConsumed().intValue());
    Pool pool2 = createPool(owner, p, 1L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2050, 3, 2));
    poolCurator.create(pool2);
    Entitlement ent2 = createEntitlement(owner, devSystem, pool2, createEntitlementCertificate("keycert", "cert"));
    ent2.setQuantity(1);
    entitlementCurator.create(ent2);
    pool2.setConsumed(pool2.getConsumed() + 1);
    poolCurator.merge(pool2);
    poolCurator.flush();
    Map<String, Integer> poolQuantities = new HashMap<>();
    poolQuantities.put(pool1.getId(), 1);
    poolQuantities.put(pool2.getId(), 1);
    try {
        List<Entitlement> results = poolManager.entitleByPools(devSystem, poolQuantities);
        fail();
    } catch (EntitlementRefusedException e) {
        assertNotNull(e.getResults());
        assertEquals(2, e.getResults().entrySet().size());
        assertEquals("rulefailed.no.entitlements.available", e.getResults().get(pool1.getId()).getErrors().get(0).getResourceKey());
        assertEquals("rulefailed.no.entitlements.available", e.getResults().get(pool2.getId()).getErrors().get(0).getResourceKey());
    }
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) HashMap(java.util.HashMap) EntitlementRefusedException(org.candlepin.policy.EntitlementRefusedException) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) 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