Search in sources :

Example 6 with DefaultOwnerServiceAdapter

use of org.candlepin.service.impl.DefaultOwnerServiceAdapter 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());
}
Also used : ImportSubscriptionServiceAdapter(org.candlepin.service.impl.ImportSubscriptionServiceAdapter) OwnerServiceAdapter(org.candlepin.service.OwnerServiceAdapter) DefaultOwnerServiceAdapter(org.candlepin.service.impl.DefaultOwnerServiceAdapter) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Subscription(org.candlepin.model.dto.Subscription) LinkedList(java.util.LinkedList) DefaultOwnerServiceAdapter(org.candlepin.service.impl.DefaultOwnerServiceAdapter) Test(org.junit.Test)

Example 7 with DefaultOwnerServiceAdapter

use of org.candlepin.service.impl.DefaultOwnerServiceAdapter 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;
}
Also used : Owner(org.candlepin.model.Owner) ImportSubscriptionServiceAdapter(org.candlepin.service.impl.ImportSubscriptionServiceAdapter) UpstreamConsumer(org.candlepin.model.UpstreamConsumer) Consumer(org.candlepin.model.Consumer) OwnerServiceAdapter(org.candlepin.service.OwnerServiceAdapter) DefaultOwnerServiceAdapter(org.candlepin.service.impl.DefaultOwnerServiceAdapter) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Subscription(org.candlepin.model.dto.Subscription) LinkedList(java.util.LinkedList) DefaultOwnerServiceAdapter(org.candlepin.service.impl.DefaultOwnerServiceAdapter)

Example 8 with DefaultOwnerServiceAdapter

use of org.candlepin.service.impl.DefaultOwnerServiceAdapter 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());
}
Also used : Owner(org.candlepin.model.Owner) ImportSubscriptionServiceAdapter(org.candlepin.service.impl.ImportSubscriptionServiceAdapter) OwnerDTO(org.candlepin.dto.api.v1.OwnerDTO) OwnerServiceAdapter(org.candlepin.service.OwnerServiceAdapter) DefaultOwnerServiceAdapter(org.candlepin.service.impl.DefaultOwnerServiceAdapter) Product(org.candlepin.model.Product) Subscription(org.candlepin.model.dto.Subscription) LinkedList(java.util.LinkedList) DefaultOwnerServiceAdapter(org.candlepin.service.impl.DefaultOwnerServiceAdapter) Test(org.junit.Test)

Example 9 with DefaultOwnerServiceAdapter

use of org.candlepin.service.impl.DefaultOwnerServiceAdapter 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);
}
Also used : ImportSubscriptionServiceAdapter(org.candlepin.service.impl.ImportSubscriptionServiceAdapter) Consumer(org.candlepin.model.Consumer) Subscription(org.candlepin.model.dto.Subscription) Branding(org.candlepin.model.Branding) ConsumerType(org.candlepin.model.ConsumerType) LinkedList(java.util.LinkedList) Date(java.util.Date) DefaultOwnerServiceAdapter(org.candlepin.service.impl.DefaultOwnerServiceAdapter) HashSet(java.util.HashSet) Before(org.junit.Before)

Aggregations

LinkedList (java.util.LinkedList)9 Subscription (org.candlepin.model.dto.Subscription)9 DefaultOwnerServiceAdapter (org.candlepin.service.impl.DefaultOwnerServiceAdapter)9 ImportSubscriptionServiceAdapter (org.candlepin.service.impl.ImportSubscriptionServiceAdapter)9 Product (org.candlepin.model.Product)8 OwnerServiceAdapter (org.candlepin.service.OwnerServiceAdapter)8 Pool (org.candlepin.model.Pool)7 Test (org.junit.Test)7 Matchers.anyString (org.mockito.Matchers.anyString)3 Consumer (org.candlepin.model.Consumer)2 Owner (org.candlepin.model.Owner)2 Date (java.util.Date)1 HashSet (java.util.HashSet)1 OwnerDTO (org.candlepin.dto.api.v1.OwnerDTO)1 Branding (org.candlepin.model.Branding)1 ConsumerType (org.candlepin.model.ConsumerType)1 UpstreamConsumer (org.candlepin.model.UpstreamConsumer)1 Before (org.junit.Before)1