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());
}
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());
}
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());
}
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());
}
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());
}
}
Aggregations