use of org.candlepin.model.Consumer in project candlepin by candlepin.
the class EntitlerTest method testCreatedDevPoolAttributes.
@Test
public void testCreatedDevPoolAttributes() {
Owner owner = TestUtil.createOwner("o");
List<ProductData> devProdDTOs = new ArrayList<>();
Product p1 = TestUtil.createProduct("dev-product", "Dev Product");
p1.setAttribute(Product.Attributes.SUPPORT_LEVEL, "Premium");
p1.setAttribute("expires_after", "47");
Product p2 = TestUtil.createProduct("provided-product1", "Provided Product 1");
Product p3 = TestUtil.createProduct("provided-product2", "Provided Product 2");
devProdDTOs.add(p1.toDTO());
devProdDTOs.add(p2.toDTO());
devProdDTOs.add(p3.toDTO());
Consumer devSystem = TestUtil.createConsumer(owner);
devSystem.setFact("dev_sku", p1.getId());
devSystem.addInstalledProduct(new ConsumerInstalledProduct(p2));
devSystem.addInstalledProduct(new ConsumerInstalledProduct(p3));
when(productAdapter.getProductsByIds(eq(owner), any(List.class))).thenReturn(devProdDTOs);
this.mockProducts(owner, p1, p2, p3);
this.mockProductImport(owner, p1, p2, p3);
this.mockContentImport(owner, Collections.<String, Content>emptyMap());
Pool created = entitler.assembleDevPool(devSystem, owner, devSystem.getFact("dev_sku"));
Calendar cal = Calendar.getInstance();
cal.setTime(created.getStartDate());
cal.add(Calendar.DAY_OF_YEAR, 47);
assertEquals(created.getEndDate(), cal.getTime());
assertEquals("true", created.getAttributeValue(Pool.Attributes.DEVELOPMENT_POOL));
assertEquals(devSystem.getUuid(), created.getAttributeValue(Pool.Attributes.REQUIRES_CONSUMER));
assertEquals(p1.getId(), created.getProductId());
assertEquals(2, created.getProvidedProducts().size());
assertEquals("Premium", created.getProduct().getAttributeValue(Product.Attributes.SUPPORT_LEVEL));
assertEquals(1L, created.getQuantity().longValue());
}
use of org.candlepin.model.Consumer in project candlepin by candlepin.
the class PoolManagerFunctionalTest method testListConditionDevPools.
@Test
public void testListConditionDevPools() {
Owner owner = createOwner();
Product p = TestUtil.createProduct("test-product", "Test Product");
productCurator.create(p);
Pool pool1 = createPool(owner, p, 10L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2050, 3, 2));
pool1.setAttribute(Pool.Attributes.DEVELOPMENT_POOL, "true");
poolCurator.create(pool1);
Pool pool2 = createPool(owner, p, 10L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2050, 3, 2));
poolCurator.create(pool2);
Consumer devSystem = new Consumer("dev", "user", owner, systemType);
devSystem.setFact("dev_sku", p.getId());
devSystem.addInstalledProduct(new ConsumerInstalledProduct(p));
Consumer nonDevSystem = new Consumer("system", "user", owner, systemType);
nonDevSystem.addInstalledProduct(new ConsumerInstalledProduct(p));
Page<List<Pool>> results = poolManager.listAvailableEntitlementPools(devSystem, null, owner.getId(), null, null, null, true, new PoolFilterBuilder(), new PageRequest(), false, false, null);
assertEquals(2, results.getPageData().size());
results = poolManager.listAvailableEntitlementPools(nonDevSystem, null, owner.getId(), null, null, null, true, new PoolFilterBuilder(), new PageRequest(), false, false, null);
assertEquals(1, results.getPageData().size());
Pool found2 = results.getPageData().get(0);
assertEquals(pool2, found2);
}
use of org.candlepin.model.Consumer in project candlepin by candlepin.
the class PoolManagerFunctionalTest method testDevPoolBatchBind.
@Test
public void testDevPoolBatchBind() 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, 10L, 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);
Pool pool2 = createPool(owner, p, 10L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2050, 3, 2));
poolCurator.create(pool2);
Map<String, Integer> poolQuantities = new HashMap<>();
poolQuantities.put(pool1.getId(), 1);
poolQuantities.put(pool2.getId(), 1);
List<Entitlement> results = poolManager.entitleByPools(devSystem, poolQuantities);
assertEquals(2, results.size());
assertTrue(results.get(0).getPool() == pool1 || results.get(0).getPool() == pool2);
assertTrue(results.get(1).getPool() == pool1 || results.get(1).getPool() == pool2);
pool1 = poolCurator.find(pool1.getId());
pool2 = poolCurator.find(pool2.getId());
assertEquals(1, pool1.getConsumed().intValue());
assertEquals(1, pool2.getConsumed().intValue());
}
use of org.candlepin.model.Consumer in project candlepin by candlepin.
the class PoolManagerFunctionalTest method testCleanupExpiredPoolsWithEntitlementEndDateOverrides.
@Test
public void testCleanupExpiredPoolsWithEntitlementEndDateOverrides() {
long ct = System.currentTimeMillis();
Date activeStart = new Date(ct + 3600000);
Date activeEnd = new Date(ct + 7200000);
Date expiredStart = new Date(ct - 7200000);
Date expiredEnd = new Date(ct - 3600000);
Owner owner = this.createOwner();
List<Consumer> consumers = new LinkedList<>();
List<Product> products = new LinkedList<>();
List<Pool> pools = new LinkedList<>();
List<Entitlement> entitlements = new LinkedList<>();
int objCount = 6;
for (int i = 0; i < objCount; ++i) {
Consumer consumer = this.createConsumer(owner);
Product product = this.createProduct("test-product-" + i, "Test Product " + i, owner);
Pool pool = (i % 2 == 0) ? this.createPool(owner, product, 1L, activeStart, activeEnd) : this.createPool(owner, product, 1L, expiredStart, expiredEnd);
consumers.add(consumer);
products.add(product);
pools.add(pool);
}
entitlements.add(this.createEntitlement(owner, consumers.get(0), pools.get(2), null));
entitlements.add(this.createEntitlement(owner, consumers.get(1), pools.get(3), null));
entitlements.add(this.createEntitlement(owner, consumers.get(2), pools.get(4), null));
entitlements.add(this.createEntitlement(owner, consumers.get(3), pools.get(5), null));
entitlements.get(0).setEndDateOverride(activeEnd);
entitlements.get(1).setEndDateOverride(activeEnd);
entitlements.get(2).setEndDateOverride(expiredEnd);
entitlements.get(3).setEndDateOverride(expiredEnd);
for (Entitlement entitlement : entitlements) {
this.entitlementCurator.merge(entitlement);
}
this.poolCurator.flush();
this.poolManager.cleanupExpiredPools();
// Active pool, no ent
assertNotNull(this.poolCurator.find(pools.get(0).getId()));
// Expired pool, no ent
assertNull(this.poolCurator.find(pools.get(1).getId()));
// Active pool, active ent
assertNotNull(this.poolCurator.find(pools.get(2).getId()));
// Expired pool, active ent
assertNotNull(this.poolCurator.find(pools.get(3).getId()));
// Active pool, expired ent
assertNotNull(this.poolCurator.find(pools.get(4).getId()));
// Expired pool, expired ent
assertNull(this.poolCurator.find(pools.get(5).getId()));
}
use of org.candlepin.model.Consumer in project candlepin by candlepin.
the class PoolManagerFunctionalTest method testDevPoolRemovalAtUnbind.
@Test
public void testDevPoolRemovalAtUnbind() 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, 10L, 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);
Pool pool2 = createPool(owner, p, 10L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2050, 3, 2));
poolCurator.create(pool2);
List<String> possPools = new ArrayList<>();
possPools.add(pool1.getId());
AutobindData ad = new AutobindData(devSystem, owner);
ad.setPossiblePools(possPools);
List<Entitlement> results = poolManager.entitleByProducts(ad);
assertEquals(1, results.size());
assertEquals(results.get(0).getPool(), pool1);
Entitlement e = entitlementCurator.find(results.get(0).getId());
poolManager.revokeEntitlement(e);
assertNull(poolCurator.find(pool1.getId()));
assertNotNull(poolCurator.find(pool2.getId()));
}
Aggregations