use of org.candlepin.model.Pool in project candlepin by candlepin.
the class PoolManagerFunctionalTest method testFabricateWithBranding.
@Test
public void testFabricateWithBranding() throws Exception {
List<Pool> masterPools = poolManager.getPoolsBySubscriptionId(sub4.getId()).list();
Pool masterPool = null;
for (Pool pool : masterPools) {
if (pool.getType() == Pool.PoolType.NORMAL) {
masterPool = pool;
}
}
Set<Branding> brandingSet = poolManager.fabricateSubscriptionFromPool(masterPool).getBranding();
Assert.assertNotNull(brandingSet);
Assert.assertEquals(2, brandingSet.size());
ArrayList<Branding> list = new ArrayList<>();
list.addAll(brandingSet);
list.sort(new Comparator<Branding>() {
@Override
public int compare(Branding o1, Branding o2) {
return o1.getName().compareTo(o2.getName());
}
});
Assert.assertEquals("branding1", list.get(0).getName());
Assert.assertEquals("product1", list.get(0).getProductId());
Assert.assertEquals("type1", list.get(0).getType());
Assert.assertEquals("branding2", list.get(1).getName());
Assert.assertEquals("product2", list.get(1).getProductId());
Assert.assertEquals("type2", list.get(1).getType());
}
use of org.candlepin.model.Pool 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.Pool in project candlepin by candlepin.
the class PoolManagerFunctionalTest method testListAllForActKeyExcludesErrors.
@Test
public void testListAllForActKeyExcludesErrors() {
Product p = TestUtil.createProduct("test-product", "Test Product");
productCurator.create(p);
ActivationKey ak = new ActivationKey();
Pool akpool = new Pool();
akpool.setAttribute(Pool.Attributes.PHYSICAL_ONLY, "true");
ak.addPool(akpool, 1L);
Page<List<Pool>> results = poolManager.listAvailableEntitlementPools(null, ak, parentSystem.getOwnerId(), null, null, null, true, new PoolFilterBuilder(), new PageRequest(), false, false, null);
assertEquals(4, results.getPageData().size());
// Creating a pool with no entitlements available, which does not trigger
// a rules error:
Pool pool = createPool(o, p, 0L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2050, 3, 2));
poolCurator.create(pool);
results = poolManager.listAvailableEntitlementPools(null, ak, parentSystem.getOwnerId(), null, null, null, true, new PoolFilterBuilder(), new PageRequest(), false, false, null);
// Pool in error should not be included. Should have the same number of
// initial pools.
assertEquals(5, results.getPageData().size());
}
use of org.candlepin.model.Pool 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.Pool in project candlepin by candlepin.
the class PoolManagerFunctionalTest method testRefreshPoolsWithChangedProductShouldUpdatePool.
@Test
public void testRefreshPoolsWithChangedProductShouldUpdatePool() {
Product product1 = TestUtil.createProduct("product 1", "Product 1");
Product product2 = TestUtil.createProduct("product 2", "Product 2");
productCurator.create(product1);
productCurator.create(product2);
List<Subscription> subscriptions = new LinkedList<>();
ImportSubscriptionServiceAdapter subAdapter = new ImportSubscriptionServiceAdapter(subscriptions);
Subscription subscription = TestUtil.createSubscription(o, product1, new HashSet<>());
subscription.setId(Util.generateDbUUID());
subscription.setQuantity(5L);
subscription.setStartDate(new Date());
subscription.setEndDate(TestUtil.createDate(3020, 12, 12));
subscription.setModified(new Date());
subscriptions.add(subscription);
// set up initial pool
poolManager.getRefresher(subAdapter, ownerAdapter).add(o).run();
List<Pool> pools = poolCurator.listByOwnerAndProduct(o, product1.getId());
assertEquals(1, pools.size());
// now alter the product behind the sub, and make sure the pool is also updated
subscription.setProduct(product2.toDTO());
// set up initial pool
poolManager.getRefresher(subAdapter, ownerAdapter).add(o).run();
pools = poolCurator.listByOwnerAndProduct(o, product2.getId());
assertEquals(1, pools.size());
}
Aggregations