use of org.candlepin.model.Pool in project candlepin by candlepin.
the class OwnerResourceTest method removePoolsForExpiredUpdate.
@Test
public void removePoolsForExpiredUpdate() {
Product prod = this.createProduct(owner);
prod.setAttribute(Product.Attributes.VIRT_LIMIT, "3");
prod = productCurator.merge(prod);
Pool pool = TestUtil.createPool(owner, prod);
pool.setUpstreamPoolId("upstream-" + pool.getId());
pool.setSubscriptionSubKey("master");
PoolDTO poolDto = this.modelTranslator.translate(pool, PoolDTO.class);
poolDto = ownerResource.createPool(owner.getKey(), poolDto);
List<Pool> pools = poolCurator.listByOwner(owner).list();
assertEquals(2, pools.size());
poolDto.setStartDate(new Date(System.currentTimeMillis() - 5 * 24 * 60 * 60 * 1000));
poolDto.setEndDate(new Date(System.currentTimeMillis() - 3 * 24 * 60 * 60 * 1000));
ownerResource.updatePool(owner.getKey(), poolDto);
pools = poolCurator.listByOwner(owner).list();
assertEquals(0, pools.size());
}
use of org.candlepin.model.Pool in project candlepin by candlepin.
the class OwnerResourceTest method createBonusPool.
@Test
public void createBonusPool() {
Product prod = this.createProduct(owner);
prod.setAttribute(Product.Attributes.VIRT_LIMIT, "2");
productCurator.merge(prod);
Pool pool = TestUtil.createPool(owner, prod);
pool.setUpstreamPoolId("upstream-" + pool.getId());
assertEquals(0, poolCurator.listByOwner(owner).list().size());
PoolDTO poolDto = this.modelTranslator.translate(pool, PoolDTO.class);
ownerResource.createPool(owner.getKey(), poolDto);
List<Pool> pools = poolCurator.listByOwner(owner).list();
assertEquals(2, pools.size());
assertTrue(pools.get(0).getSubscriptionSubKey().startsWith("master") || pools.get(1).getSubscriptionSubKey().startsWith("master"));
assertTrue(pools.get(0).getSubscriptionSubKey().equals("derived") || pools.get(1).getSubscriptionSubKey().equals("derived"));
}
use of org.candlepin.model.Pool in project candlepin by candlepin.
the class OwnerResourceTest method testEntitlementsRevocationWithLifoOrder.
@Test
public void testEntitlementsRevocationWithLifoOrder() throws Exception {
Pool pool = doTestEntitlementsRevocationCommon(7, 4, 5);
assertEquals(5L, this.poolCurator.find(pool.getId()).getConsumed().longValue());
}
use of org.candlepin.model.Pool in project candlepin by candlepin.
the class OwnerResourceTest method testRefreshPoolsWithRemovedSubscriptions.
@Test
public void testRefreshPoolsWithRemovedSubscriptions() {
Product prod = this.createProduct(owner);
List<Subscription> subscriptions = new LinkedList<>();
ImportSubscriptionServiceAdapter subAdapter = new ImportSubscriptionServiceAdapter(subscriptions);
OwnerServiceAdapter ownerAdapter = new DefaultOwnerServiceAdapter(this.ownerCurator, this.i18n);
Subscription sub = TestUtil.createSubscription(owner, prod, new HashSet<>());
sub.setId(Util.generateDbUUID());
sub.setQuantity(2000L);
sub.setStartDate(TestUtil.createDate(2010, 2, 9));
sub.setEndDate(TestUtil.createDate(3000, 2, 9));
sub.setModified(TestUtil.createDate(2010, 2, 12));
// This line is only present as a result of a (temporary?) fix for BZ 1452694. Once a
// better fix has been implemented, the upstream pool ID can be removed.
sub.setUpstreamPoolId("upstream_pool_id");
subscriptions.add(sub);
// Trigger the refresh:
poolManager.getRefresher(subAdapter, ownerAdapter).add(owner).run();
List<Pool> pools = poolCurator.listByOwnerAndProduct(owner, prod.getId());
assertEquals(1, pools.size());
Pool newPool = pools.get(0);
String poolId = newPool.getId();
// Now delete the subscription:
subscriptions.remove(sub);
// Trigger the refresh:
poolManager.getRefresher(subAdapter, ownerAdapter).add(owner).run();
assertNull("Pool not having subscription should have been deleted", poolCurator.find(poolId));
}
use of org.candlepin.model.Pool in project candlepin by candlepin.
the class OwnerResourceTest method testRefreshPoolsWithChangedSubscriptions.
@Test
public void testRefreshPoolsWithChangedSubscriptions() {
Product prod = this.createProduct(owner);
Pool pool = createPool(owner, prod, 1000L, TestUtil.createDate(2009, 11, 30), TestUtil.createDate(2015, 11, 30));
List<Subscription> subscriptions = new LinkedList<>();
ImportSubscriptionServiceAdapter subAdapter = new ImportSubscriptionServiceAdapter(subscriptions);
OwnerServiceAdapter ownerAdapter = new DefaultOwnerServiceAdapter(this.ownerCurator, this.i18n);
Subscription sub = TestUtil.createSubscription(owner, prod, new HashSet<>());
sub.setId(Util.generateDbUUID());
sub.setQuantity(2000L);
sub.setStartDate(TestUtil.createDate(2010, 2, 9));
sub.setEndDate(TestUtil.createDate(3000, 2, 9));
sub.setModified(TestUtil.createDate(2010, 2, 12));
subscriptions.add(sub);
assertTrue(pool.getQuantity() < sub.getQuantity());
assertTrue(pool.getStartDate() != sub.getStartDate());
assertTrue(pool.getEndDate() != sub.getEndDate());
pool.getSourceSubscription().setSubscriptionId(sub.getId());
poolCurator.merge(pool);
poolManager.getRefresher(subAdapter, ownerAdapter).add(owner).run();
pool = poolCurator.find(pool.getId());
assertEquals(sub.getId(), pool.getSubscriptionId());
assertEquals(sub.getQuantity(), pool.getQuantity());
assertEquals(sub.getStartDate(), pool.getStartDate());
assertEquals(sub.getEndDate(), pool.getEndDate());
}
Aggregations