Search in sources :

Example 86 with Pool

use of org.candlepin.model.Pool in project candlepin by candlepin.

the class PoolManagerFunctionalTest method testFabricateWithBranding.

@Test
public void testFabricateWithBranding() throws Exception {
    List<Pool> masterPools = poolManager.getPoolsBySubscriptionId(sub4.getId()).list();
    Pool masterPool = null;
    for (Pool pool : masterPools) {
        if (pool.getType() == Pool.PoolType.NORMAL) {
            masterPool = pool;
        }
    }
    Set<Branding> brandingSet = poolManager.fabricateSubscriptionFromPool(masterPool).getBranding();
    Assert.assertNotNull(brandingSet);
    Assert.assertEquals(2, brandingSet.size());
    ArrayList<Branding> list = new ArrayList<>();
    list.addAll(brandingSet);
    list.sort(new Comparator<Branding>() {

        @Override
        public int compare(Branding o1, Branding o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    Assert.assertEquals("branding1", list.get(0).getName());
    Assert.assertEquals("product1", list.get(0).getProductId());
    Assert.assertEquals("type1", list.get(0).getType());
    Assert.assertEquals("branding2", list.get(1).getName());
    Assert.assertEquals("product2", list.get(1).getProductId());
    Assert.assertEquals("type2", list.get(1).getType());
}
Also used : ArrayList(java.util.ArrayList) Pool(org.candlepin.model.Pool) Branding(org.candlepin.model.Branding) Test(org.junit.Test)

Example 87 with Pool

use of org.candlepin.model.Pool in project candlepin by candlepin.

the class PoolManagerFunctionalTest method testDevPoolBatchBind.

@Test
public void testDevPoolBatchBind() throws EntitlementRefusedException {
    Owner owner = createOwner();
    Product p = TestUtil.createProduct("test-product", "Test Product");
    productCurator.create(p);
    Consumer devSystem = new Consumer("dev", "user", owner, systemType);
    devSystem.setFact("dev_sku", p.getId());
    devSystem.addInstalledProduct(new ConsumerInstalledProduct(p));
    consumerCurator.create(devSystem);
    Pool pool1 = createPool(owner, p, 10L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2050, 3, 2));
    pool1.setAttribute(Pool.Attributes.DEVELOPMENT_POOL, "true");
    pool1.setAttribute(Pool.Attributes.REQUIRES_CONSUMER, devSystem.getUuid());
    poolCurator.create(pool1);
    Pool pool2 = createPool(owner, p, 10L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2050, 3, 2));
    poolCurator.create(pool2);
    Map<String, Integer> poolQuantities = new HashMap<>();
    poolQuantities.put(pool1.getId(), 1);
    poolQuantities.put(pool2.getId(), 1);
    List<Entitlement> results = poolManager.entitleByPools(devSystem, poolQuantities);
    assertEquals(2, results.size());
    assertTrue(results.get(0).getPool() == pool1 || results.get(0).getPool() == pool2);
    assertTrue(results.get(1).getPool() == pool1 || results.get(1).getPool() == pool2);
    pool1 = poolCurator.find(pool1.getId());
    pool2 = poolCurator.find(pool2.getId());
    assertEquals(1, pool1.getConsumed().intValue());
    assertEquals(1, pool2.getConsumed().intValue());
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) HashMap(java.util.HashMap) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 88 with Pool

use of org.candlepin.model.Pool in project candlepin by candlepin.

the class PoolManagerFunctionalTest method testListAllForActKeyExcludesErrors.

@Test
public void testListAllForActKeyExcludesErrors() {
    Product p = TestUtil.createProduct("test-product", "Test Product");
    productCurator.create(p);
    ActivationKey ak = new ActivationKey();
    Pool akpool = new Pool();
    akpool.setAttribute(Pool.Attributes.PHYSICAL_ONLY, "true");
    ak.addPool(akpool, 1L);
    Page<List<Pool>> results = poolManager.listAvailableEntitlementPools(null, ak, parentSystem.getOwnerId(), null, null, null, true, new PoolFilterBuilder(), new PageRequest(), false, false, null);
    assertEquals(4, results.getPageData().size());
    // Creating a pool with no entitlements available, which does not trigger
    // a rules error:
    Pool pool = createPool(o, p, 0L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2050, 3, 2));
    poolCurator.create(pool);
    results = poolManager.listAvailableEntitlementPools(null, ak, parentSystem.getOwnerId(), null, null, null, true, new PoolFilterBuilder(), new PageRequest(), false, false, null);
    // Pool in error should not be included. Should have the same number of
    // initial pools.
    assertEquals(5, results.getPageData().size());
}
Also used : PageRequest(org.candlepin.common.paging.PageRequest) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) PoolFilterBuilder(org.candlepin.model.PoolFilterBuilder) Pool(org.candlepin.model.Pool) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Test(org.junit.Test)

Example 89 with Pool

use of org.candlepin.model.Pool in project candlepin by candlepin.

the class PoolManagerFunctionalTest method testCleanupExpiredPoolsWithEntitlementEndDateOverrides.

@Test
public void testCleanupExpiredPoolsWithEntitlementEndDateOverrides() {
    long ct = System.currentTimeMillis();
    Date activeStart = new Date(ct + 3600000);
    Date activeEnd = new Date(ct + 7200000);
    Date expiredStart = new Date(ct - 7200000);
    Date expiredEnd = new Date(ct - 3600000);
    Owner owner = this.createOwner();
    List<Consumer> consumers = new LinkedList<>();
    List<Product> products = new LinkedList<>();
    List<Pool> pools = new LinkedList<>();
    List<Entitlement> entitlements = new LinkedList<>();
    int objCount = 6;
    for (int i = 0; i < objCount; ++i) {
        Consumer consumer = this.createConsumer(owner);
        Product product = this.createProduct("test-product-" + i, "Test Product " + i, owner);
        Pool pool = (i % 2 == 0) ? this.createPool(owner, product, 1L, activeStart, activeEnd) : this.createPool(owner, product, 1L, expiredStart, expiredEnd);
        consumers.add(consumer);
        products.add(product);
        pools.add(pool);
    }
    entitlements.add(this.createEntitlement(owner, consumers.get(0), pools.get(2), null));
    entitlements.add(this.createEntitlement(owner, consumers.get(1), pools.get(3), null));
    entitlements.add(this.createEntitlement(owner, consumers.get(2), pools.get(4), null));
    entitlements.add(this.createEntitlement(owner, consumers.get(3), pools.get(5), null));
    entitlements.get(0).setEndDateOverride(activeEnd);
    entitlements.get(1).setEndDateOverride(activeEnd);
    entitlements.get(2).setEndDateOverride(expiredEnd);
    entitlements.get(3).setEndDateOverride(expiredEnd);
    for (Entitlement entitlement : entitlements) {
        this.entitlementCurator.merge(entitlement);
    }
    this.poolCurator.flush();
    this.poolManager.cleanupExpiredPools();
    // Active pool, no ent
    assertNotNull(this.poolCurator.find(pools.get(0).getId()));
    // Expired pool, no ent
    assertNull(this.poolCurator.find(pools.get(1).getId()));
    // Active pool, active ent
    assertNotNull(this.poolCurator.find(pools.get(2).getId()));
    // Expired pool, active ent
    assertNotNull(this.poolCurator.find(pools.get(3).getId()));
    // Active pool, expired ent
    assertNotNull(this.poolCurator.find(pools.get(4).getId()));
    // Expired pool, expired ent
    assertNull(this.poolCurator.find(pools.get(5).getId()));
}
Also used : Owner(org.candlepin.model.Owner) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Date(java.util.Date) LinkedList(java.util.LinkedList) Consumer(org.candlepin.model.Consumer) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 90 with Pool

use of org.candlepin.model.Pool in project candlepin by candlepin.

the class PoolManagerFunctionalTest method testRefreshPoolsWithChangedProductShouldUpdatePool.

@Test
public void testRefreshPoolsWithChangedProductShouldUpdatePool() {
    Product product1 = TestUtil.createProduct("product 1", "Product 1");
    Product product2 = TestUtil.createProduct("product 2", "Product 2");
    productCurator.create(product1);
    productCurator.create(product2);
    List<Subscription> subscriptions = new LinkedList<>();
    ImportSubscriptionServiceAdapter subAdapter = new ImportSubscriptionServiceAdapter(subscriptions);
    Subscription subscription = TestUtil.createSubscription(o, product1, new HashSet<>());
    subscription.setId(Util.generateDbUUID());
    subscription.setQuantity(5L);
    subscription.setStartDate(new Date());
    subscription.setEndDate(TestUtil.createDate(3020, 12, 12));
    subscription.setModified(new Date());
    subscriptions.add(subscription);
    // set up initial pool
    poolManager.getRefresher(subAdapter, ownerAdapter).add(o).run();
    List<Pool> pools = poolCurator.listByOwnerAndProduct(o, product1.getId());
    assertEquals(1, pools.size());
    // now alter the product behind the sub, and make sure the pool is also updated
    subscription.setProduct(product2.toDTO());
    // set up initial pool
    poolManager.getRefresher(subAdapter, ownerAdapter).add(o).run();
    pools = poolCurator.listByOwnerAndProduct(o, product2.getId());
    assertEquals(1, pools.size());
}
Also used : ImportSubscriptionServiceAdapter(org.candlepin.service.impl.ImportSubscriptionServiceAdapter) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Pool(org.candlepin.model.Pool) Subscription(org.candlepin.model.dto.Subscription) LinkedList(java.util.LinkedList) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Pool (org.candlepin.model.Pool)508 Test (org.junit.Test)358 Product (org.candlepin.model.Product)217 Entitlement (org.candlepin.model.Entitlement)125 Consumer (org.candlepin.model.Consumer)115 ValidationResult (org.candlepin.policy.ValidationResult)111 ArrayList (java.util.ArrayList)100 LinkedList (java.util.LinkedList)100 Owner (org.candlepin.model.Owner)80 HashSet (java.util.HashSet)76 HashMap (java.util.HashMap)67 PoolQuantity (org.candlepin.model.PoolQuantity)66 Date (java.util.Date)65 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)62 Subscription (org.candlepin.model.dto.Subscription)60 List (java.util.List)48 ConsumerType (org.candlepin.model.ConsumerType)48 SourceSubscription (org.candlepin.model.SourceSubscription)47 ActivationKey (org.candlepin.model.activationkeys.ActivationKey)38 Matchers.anyString (org.mockito.Matchers.anyString)30