use of org.candlepin.service.OwnerServiceAdapter in project candlepin by candlepin.
the class OwnerResourceTest method testRefreshPoolsWithNewSubscriptions.
@Test
public void testRefreshPoolsWithNewSubscriptions() {
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));
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);
assertEquals(sub.getId(), newPool.getSubscriptionId());
assertEquals(sub.getQuantity(), newPool.getQuantity());
assertEquals(sub.getStartDate(), newPool.getStartDate());
assertEquals(sub.getEndDate(), newPool.getEndDate());
}
use of org.candlepin.service.OwnerServiceAdapter in project candlepin by candlepin.
the class OwnerResourceTest method testRefreshMultiplePools.
@Test
public void testRefreshMultiplePools() {
Product prod = this.createProduct(owner);
Product prod2 = 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));
subscriptions.add(sub);
Subscription sub2 = TestUtil.createSubscription(owner, prod2, new HashSet<>());
sub2.setId(Util.generateDbUUID());
sub2.setQuantity(800L);
sub2.setStartDate(TestUtil.createDate(2010, 2, 9));
sub2.setEndDate(TestUtil.createDate(3000, 2, 9));
sub2.setModified(TestUtil.createDate(2010, 2, 12));
subscriptions.add(sub2);
// Trigger the refresh:
poolManager.getRefresher(subAdapter, ownerAdapter).add(owner).run();
List<Pool> pools = poolCurator.listByOwner(owner).list();
assertEquals(2, pools.size());
}
use of org.candlepin.service.OwnerServiceAdapter in project candlepin by candlepin.
the class OwnerResourceTest method doTestEntitlementsRevocationCommon.
private Pool doTestEntitlementsRevocationCommon(long subQ, int e1, int e2) throws ParseException {
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(1000L);
sub.setStartDate(TestUtil.createDate(2009, 11, 30));
sub.setEndDate(TestUtil.createDate(Calendar.getInstance().get(Calendar.YEAR) + 10, 10, 30));
sub.setModified(TestUtil.createDate(2015, 11, 30));
subscriptions.add(sub);
List<Pool> pools = poolManager.createAndEnrichPools(sub);
assertTrue(pools.size() > 0);
Pool pool = pools.get(0);
sub.setQuantity(subQ);
Owner retrieved = pool.getOwner();
Consumer consumer = createConsumer(retrieved);
Consumer consumer1 = createConsumer(retrieved);
pool = this.poolCurator.find(pool.getId());
createEntitlementWithQ(pool, retrieved, consumer, e1, "01/02/2010");
createEntitlementWithQ(pool, retrieved, consumer1, e2, "01/01/2010");
assertEquals(pool.getConsumed(), Long.valueOf(e1 + e2));
poolManager.getRefresher(subAdapter, ownerAdapter).add(retrieved).run();
pool = poolCurator.find(pool.getId());
return pool;
}
use of org.candlepin.service.OwnerServiceAdapter in project candlepin by candlepin.
the class OwnerResourceTest method testUpdateOwner.
@Test
public void testUpdateOwner() {
config.setProperty(ConfigProperties.STANDALONE, "false");
Owner owner = new Owner("Test Owner", "test");
ownerCurator.create(owner);
Product prod1 = this.createProduct(owner);
prod1.setAttribute(Product.Attributes.SUPPORT_LEVEL, "premium");
productCurator.merge(prod1);
Product prod2 = this.createProduct(owner);
prod2.setAttribute(Product.Attributes.SUPPORT_LEVEL, "standard");
productCurator.merge(prod2);
List<Subscription> subscriptions = new LinkedList<>();
ImportSubscriptionServiceAdapter subAdapter = new ImportSubscriptionServiceAdapter(subscriptions);
OwnerServiceAdapter ownerAdapter = new DefaultOwnerServiceAdapter(this.ownerCurator, this.i18n);
Subscription sub1 = TestUtil.createSubscription(owner, prod1, new HashSet<>());
sub1.setId(Util.generateDbUUID());
sub1.setQuantity(2000L);
sub1.setStartDate(TestUtil.createDate(2010, 2, 9));
sub1.setEndDate(TestUtil.createDate(3000, 2, 9));
sub1.setModified(TestUtil.createDate(2010, 2, 12));
subscriptions.add(sub1);
Subscription sub2 = TestUtil.createSubscription(owner, prod2, new HashSet<>());
sub2.setId(Util.generateDbUUID());
sub2.setQuantity(2000L);
sub2.setStartDate(TestUtil.createDate(2010, 2, 9));
sub2.setEndDate(TestUtil.createDate(3000, 2, 9));
sub2.setModified(TestUtil.createDate(2010, 2, 12));
subscriptions.add(sub2);
// Trigger the refresh:
poolManager.getRefresher(subAdapter, ownerAdapter).add(owner).run();
owner.setDefaultServiceLevel("premium");
Owner parentOwner1 = ownerCurator.create(new Owner("Paren Owner 1", "parentTest1"));
Owner parentOwner2 = ownerCurator.create(new Owner("Paren Owner 2", "parentTest2"));
owner.setParentOwner(parentOwner1);
ownerCurator.merge(owner);
ownerCurator.flush();
// Update with Display Name Only
OwnerDTO dto = new OwnerDTO();
dto.setDisplayName("New Name");
ownerResource.updateOwner(owner.getKey(), dto);
assertEquals("New Name", owner.getDisplayName());
assertEquals(parentOwner1, owner.getParentOwner());
assertEquals("premium", owner.getDefaultServiceLevel());
assertFalse(owner.isAutobindDisabled());
// Update with Default Service Level only
dto = new OwnerDTO();
dto.setDefaultServiceLevel("standard");
ownerResource.updateOwner(owner.getKey(), dto);
assertEquals("standard", owner.getDefaultServiceLevel());
assertEquals("New Name", owner.getDisplayName());
assertEquals(parentOwner1, owner.getParentOwner());
assertFalse(owner.isAutobindDisabled());
// Update with Parent Owner only
OwnerDTO parentDto = new OwnerDTO();
parentDto.setId(parentOwner2.getId());
dto = new OwnerDTO();
dto.setParentOwner(parentDto);
ownerResource.updateOwner(owner.getKey(), dto);
assertEquals(parentOwner2, owner.getParentOwner());
assertEquals("standard", owner.getDefaultServiceLevel());
assertEquals("New Name", owner.getDisplayName());
assertFalse(owner.isAutobindDisabled());
// Update with empty Service Level only
dto = new OwnerDTO();
dto.setDefaultServiceLevel("");
ownerResource.updateOwner(owner.getKey(), dto);
assertNull(owner.getDefaultServiceLevel());
assertEquals("New Name", owner.getDisplayName());
assertEquals(parentOwner2, owner.getParentOwner());
assertFalse(owner.isAutobindDisabled());
// Update autobind with disabled value.
dto = new OwnerDTO();
dto.setAutobindDisabled(true);
ownerResource.updateOwner(owner.getKey(), dto);
assertNull(owner.getDefaultServiceLevel());
assertEquals("New Name", owner.getDisplayName());
assertEquals(parentOwner2, owner.getParentOwner());
assertTrue(owner.isAutobindDisabled());
// Update autobind with enabled value.
dto = new OwnerDTO();
dto.setAutobindDisabled(false);
ownerResource.updateOwner(owner.getKey(), dto);
assertNull(owner.getDefaultServiceLevel());
assertEquals("New Name", owner.getDisplayName());
assertEquals(parentOwner2, owner.getParentOwner());
assertFalse(owner.isAutobindDisabled());
// Unset autobindDisabled results in no update.
dto = new OwnerDTO();
dto.setAutobindDisabled(null);
ownerResource.updateOwner(owner.getKey(), dto);
assertNull(owner.getDefaultServiceLevel());
assertEquals("New Name", owner.getDisplayName());
assertEquals(parentOwner2, owner.getParentOwner());
assertFalse(owner.isAutobindDisabled());
}
Aggregations