use of org.candlepin.model.Pool in project candlepin by candlepin.
the class EntitlerTest method bindByPool.
@Test
public void bindByPool() throws EntitlementRefusedException {
String poolid = "pool10";
Pool pool = mock(Pool.class);
Entitlement ent = mock(Entitlement.class);
List<Entitlement> eList = new ArrayList<>();
eList.add(ent);
when(pm.find(eq(poolid))).thenReturn(pool);
Map<String, Integer> pQs = new HashMap<>();
pQs.put(poolid, 1);
when(pm.entitleByPools(eq(consumer), eq(pQs))).thenReturn(eList);
List<Entitlement> ents = entitler.bindByPoolQuantity(consumer, poolid, 1);
assertNotNull(ents);
assertEquals(ent, ents.get(0));
}
use of org.candlepin.model.Pool 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.Pool 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.Pool in project candlepin by candlepin.
the class PoolManagerFunctionalTest method testQuantityCheck.
@Test
public void testQuantityCheck() throws Exception {
Pool monitoringPool = poolCurator.listByOwnerAndProduct(o, monitoring.getId()).get(0);
assertEquals(Long.valueOf(5), monitoringPool.getQuantity());
AutobindData data = AutobindData.create(parentSystem, o).on(new Date()).forProducts(new String[] { monitoring.getId() });
for (int i = 0; i < 5; i++) {
List<Entitlement> entitlements = poolManager.entitleByProducts(data);
assertEquals(1, entitlements.size());
}
// The cert should specify 5 monitoring entitlements, taking a 6th should fail:
assertEquals(0, poolManager.entitleByProducts(data).size());
assertEquals(Long.valueOf(5), monitoringPool.getConsumed());
}
use of org.candlepin.model.Pool in project candlepin by candlepin.
the class PoolManagerFunctionalTest method testListAllForConsumerExcludesErrors.
@Test
public void testListAllForConsumerExcludesErrors() {
Product p = TestUtil.createProduct("test-product", "Test Product");
productCurator.create(p);
Page<List<Pool>> results = poolManager.listAvailableEntitlementPools(parentSystem, null, 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 will 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(parentSystem, null, 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(4, results.getPageData().size());
}
Aggregations