Search in sources :

Example 6 with OwnerServiceAdapter

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());
}
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 OwnerServiceAdapter

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());
}
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 8 with OwnerServiceAdapter

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;
}
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 9 with OwnerServiceAdapter

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());
}
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)

Aggregations

LinkedList (java.util.LinkedList)9 Subscription (org.candlepin.model.dto.Subscription)9 OwnerServiceAdapter (org.candlepin.service.OwnerServiceAdapter)9 ImportSubscriptionServiceAdapter (org.candlepin.service.impl.ImportSubscriptionServiceAdapter)9 Product (org.candlepin.model.Product)8 DefaultOwnerServiceAdapter (org.candlepin.service.impl.DefaultOwnerServiceAdapter)8 Pool (org.candlepin.model.Pool)7 Test (org.junit.Test)7 Matchers.anyString (org.mockito.Matchers.anyString)3 Owner (org.candlepin.model.Owner)2 Transactional (com.google.inject.persist.Transactional)1 File (java.io.File)1 HashSet (java.util.HashSet)1 Refresher (org.candlepin.controller.Refresher)1 OwnerDTO (org.candlepin.dto.api.v1.OwnerDTO)1 ConsumerDTO (org.candlepin.dto.manifest.v1.ConsumerDTO)1 ProductDTO (org.candlepin.dto.manifest.v1.ProductDTO)1 Consumer (org.candlepin.model.Consumer)1 UpstreamConsumer (org.candlepin.model.UpstreamConsumer)1 SubscriptionServiceAdapter (org.candlepin.service.SubscriptionServiceAdapter)1