use of org.candlepin.service.impl.ImportSubscriptionServiceAdapter 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.impl.ImportSubscriptionServiceAdapter 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());
}
use of org.candlepin.service.impl.ImportSubscriptionServiceAdapter in project candlepin by candlepin.
the class PoolManagerFunctionalTest method init.
@Before
@Override
public void init() throws Exception {
super.init();
o = createOwner();
ownerCurator.create(o);
this.ownerAdapter = new DefaultOwnerServiceAdapter(this.ownerCurator, this.i18n);
virtHost = TestUtil.createProduct(PRODUCT_VIRT_HOST, PRODUCT_VIRT_HOST);
virtHostPlatform = TestUtil.createProduct(PRODUCT_VIRT_HOST_PLATFORM, PRODUCT_VIRT_HOST_PLATFORM);
virtGuest = TestUtil.createProduct(PRODUCT_VIRT_GUEST, PRODUCT_VIRT_GUEST);
monitoring = TestUtil.createProduct(PRODUCT_MONITORING, PRODUCT_MONITORING);
monitoring.setAttribute(Pool.Attributes.MULTI_ENTITLEMENT, "yes");
provisioning = TestUtil.createProduct(PRODUCT_PROVISIONING, PRODUCT_PROVISIONING);
provisioning.setAttribute(Pool.Attributes.MULTI_ENTITLEMENT, "yes");
provisioning.setMultiplier(2L);
provisioning.setAttribute(Product.Attributes.INSTANCE_MULTIPLIER, "4");
virtHost.setAttribute(PRODUCT_VIRT_HOST, "");
virtHostPlatform.setAttribute(PRODUCT_VIRT_HOST_PLATFORM, "");
virtGuest.setAttribute(PRODUCT_VIRT_GUEST, "");
monitoring.setAttribute(PRODUCT_MONITORING, "");
provisioning.setAttribute(PRODUCT_PROVISIONING, "");
socketLimitedProduct = TestUtil.createProduct("socket-limited-prod", "Socket Limited Product");
socketLimitedProduct.setAttribute(Product.Attributes.SOCKETS, "2");
productCurator.create(socketLimitedProduct);
productCurator.create(virtHost);
productCurator.create(virtHostPlatform);
productCurator.create(virtGuest);
productCurator.create(monitoring);
productCurator.create(provisioning);
List<Subscription> subscriptions = new LinkedList<>();
ImportSubscriptionServiceAdapter subAdapter = new ImportSubscriptionServiceAdapter(subscriptions);
Subscription sub1 = TestUtil.createSubscription(o, virtHost, new HashSet<>());
sub1.setId(Util.generateDbUUID());
sub1.setQuantity(5L);
sub1.setStartDate(new Date());
sub1.setEndDate(TestUtil.createDate(3020, 12, 12));
sub1.setModified(new Date());
Subscription sub2 = TestUtil.createSubscription(o, virtHostPlatform, new HashSet<>());
sub2.setId(Util.generateDbUUID());
sub2.setQuantity(5L);
sub2.setStartDate(new Date());
sub2.setEndDate(TestUtil.createDate(3020, 12, 12));
sub2.setModified(new Date());
Subscription sub3 = TestUtil.createSubscription(o, monitoring, new HashSet<>());
sub3.setId(Util.generateDbUUID());
sub3.setQuantity(5L);
sub3.setStartDate(new Date());
sub3.setEndDate(TestUtil.createDate(3020, 12, 12));
sub3.setModified(new Date());
sub4 = TestUtil.createSubscription(o, provisioning, new HashSet<>());
sub4.setId(Util.generateDbUUID());
sub4.setQuantity(5L);
sub4.setStartDate(new Date());
sub4.setEndDate(TestUtil.createDate(3020, 12, 12));
sub4.setModified(new Date());
sub4.getBranding().add(new Branding("product1", "type1", "branding1"));
sub4.getBranding().add(new Branding("product2", "type2", "branding2"));
subscriptions.add(sub1);
subscriptions.add(sub2);
subscriptions.add(sub3);
subscriptions.add(sub4);
poolManager.getRefresher(subAdapter, ownerAdapter).add(o).run();
this.systemType = new ConsumerType(ConsumerTypeEnum.SYSTEM);
consumerTypeCurator.create(systemType);
parentSystem = new Consumer("system", "user", o, systemType);
parentSystem.getFacts().put("total_guests", "0");
consumerCurator.create(parentSystem);
childVirtSystem = new Consumer("virt system", "user", o, systemType);
consumerCurator.create(childVirtSystem);
}
Aggregations