use of org.candlepin.model.Product 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());
}
use of org.candlepin.model.Product in project candlepin by candlepin.
the class OwnerResourceTest method ownerAdminCannotAccessAnotherOwnersPools.
@Test(expected = NotFoundException.class)
public void ownerAdminCannotAccessAnotherOwnersPools() {
Owner evilOwner = new Owner("evilowner");
ownerCurator.create(evilOwner);
Principal principal = setupPrincipal(evilOwner, Access.ALL);
Product p = this.createProduct(owner);
Pool pool1 = TestUtil.createPool(owner, p);
Pool pool2 = TestUtil.createPool(owner, p);
poolCurator.create(pool1);
poolCurator.create(pool2);
securityInterceptor.enable();
// Filtering should just cause this to return no results:
ownerResource.listPools(owner.getKey(), null, null, null, null, true, null, null, new ArrayList<>(), false, false, null, null, principal, null);
}
use of org.candlepin.model.Product in project candlepin by candlepin.
the class OwnerResourceTest method testRefreshPoolsWithRemovedMasterPool.
// test covers scenario from bug 1012386
@Test
public void testRefreshPoolsWithRemovedMasterPool() {
Product prod = this.createProduct(owner);
prod.setAttribute(Product.Attributes.VIRT_LIMIT, "4");
productCurator.merge(prod);
config.setProperty(ConfigProperties.STANDALONE, "false");
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);
// Trigger the refresh:
poolManager.getRefresher(subAdapter, ownerAdapter).add(owner).run();
List<Pool> pools = poolCurator.lookupBySubscriptionId(owner, sub.getId());
assertEquals(2, pools.size());
String bonusId = "";
String masterId = "";
for (Pool p : pools) {
if (p.getSourceSubscription().getSubscriptionSubKey().equals("master")) {
poolCurator.delete(p);
masterId = p.getId();
} else {
bonusId = p.getId();
}
}
// Trigger the refresh:
poolManager.getRefresher(subAdapter, ownerAdapter).add(owner).run();
assertNull("Original Master Pool should be gone", poolCurator.find(masterId));
assertNotNull("Bonus Pool should be the same", poolCurator.find(bonusId));
// master pool should have been recreated
pools = poolCurator.lookupBySubscriptionId(owner, sub.getId());
assertEquals(2, pools.size());
boolean newMaster = false;
for (Pool p : pools) {
if (p.getSourceSubscription().getSubscriptionSubKey().equals("master")) {
newMaster = true;
}
}
assertTrue(newMaster);
}
use of org.candlepin.model.Product in project candlepin by candlepin.
the class OwnerResourceTest method testRefreshPoolsWithRemovedBonusPool.
// test covers a corollary scenario from bug 1012386
@Test
public void testRefreshPoolsWithRemovedBonusPool() {
Product prod = this.createProduct(owner);
prod.setAttribute(Product.Attributes.VIRT_LIMIT, "4");
productCurator.merge(prod);
config.setProperty(ConfigProperties.STANDALONE, "false");
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);
// Trigger the refresh:
poolManager.getRefresher(subAdapter, ownerAdapter).add(owner).run();
List<Pool> pools = poolCurator.lookupBySubscriptionId(owner, sub.getId());
assertEquals(2, pools.size());
String bonusId = "";
String masterId = "";
for (Pool p : pools) {
if (p.getSourceSubscription().getSubscriptionSubKey().equals("derived")) {
poolCurator.delete(p);
bonusId = p.getId();
} else {
masterId = p.getId();
}
}
// Trigger the refresh:
poolManager.getRefresher(subAdapter, ownerAdapter).add(owner).run();
assertNull("Original bonus pool should be gone", poolCurator.find(bonusId));
assertNotNull("Master pool should be the same", poolCurator.find(masterId));
// master pool should have been recreated
pools = poolCurator.lookupBySubscriptionId(owner, sub.getId());
assertEquals(2, pools.size());
boolean newBonus = false;
for (Pool p : pools) {
if (p.getSourceSubscription().getSubscriptionSubKey().equals("derived")) {
newBonus = true;
}
}
assertTrue(newBonus);
}
use of org.candlepin.model.Product in project candlepin by candlepin.
the class OwnerResourceTest method createSubscription.
@Test
public void createSubscription() {
Product p = this.createProduct(owner);
Subscription s = TestUtil.createSubscription(owner, p);
s.setId("MADETHISUP");
assertEquals(0, poolCurator.listByOwner(owner).list().size());
ownerResource.createSubscription(owner.getKey(), s);
assertEquals(1, poolCurator.listByOwner(owner).list().size());
}
Aggregations