Search in sources :

Example 81 with Pool

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

the class EntitlerTest method bindByPool.

@Test
public void bindByPool() throws EntitlementRefusedException {
    String poolid = "pool10";
    Pool pool = mock(Pool.class);
    Entitlement ent = mock(Entitlement.class);
    List<Entitlement> eList = new ArrayList<>();
    eList.add(ent);
    when(pm.find(eq(poolid))).thenReturn(pool);
    Map<String, Integer> pQs = new HashMap<>();
    pQs.put(poolid, 1);
    when(pm.entitleByPools(eq(consumer), eq(pQs))).thenReturn(eList);
    List<Entitlement> ents = entitler.bindByPoolQuantity(consumer, poolid, 1);
    assertNotNull(ents);
    assertEquals(ent, ents.get(0));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 82 with Pool

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

the class EntitlerTest method testCreatedDevPoolAttributes.

@Test
public void testCreatedDevPoolAttributes() {
    Owner owner = TestUtil.createOwner("o");
    List<ProductData> devProdDTOs = new ArrayList<>();
    Product p1 = TestUtil.createProduct("dev-product", "Dev Product");
    p1.setAttribute(Product.Attributes.SUPPORT_LEVEL, "Premium");
    p1.setAttribute("expires_after", "47");
    Product p2 = TestUtil.createProduct("provided-product1", "Provided Product 1");
    Product p3 = TestUtil.createProduct("provided-product2", "Provided Product 2");
    devProdDTOs.add(p1.toDTO());
    devProdDTOs.add(p2.toDTO());
    devProdDTOs.add(p3.toDTO());
    Consumer devSystem = TestUtil.createConsumer(owner);
    devSystem.setFact("dev_sku", p1.getId());
    devSystem.addInstalledProduct(new ConsumerInstalledProduct(p2));
    devSystem.addInstalledProduct(new ConsumerInstalledProduct(p3));
    when(productAdapter.getProductsByIds(eq(owner), any(List.class))).thenReturn(devProdDTOs);
    this.mockProducts(owner, p1, p2, p3);
    this.mockProductImport(owner, p1, p2, p3);
    this.mockContentImport(owner, Collections.<String, Content>emptyMap());
    Pool created = entitler.assembleDevPool(devSystem, owner, devSystem.getFact("dev_sku"));
    Calendar cal = Calendar.getInstance();
    cal.setTime(created.getStartDate());
    cal.add(Calendar.DAY_OF_YEAR, 47);
    assertEquals(created.getEndDate(), cal.getTime());
    assertEquals("true", created.getAttributeValue(Pool.Attributes.DEVELOPMENT_POOL));
    assertEquals(devSystem.getUuid(), created.getAttributeValue(Pool.Attributes.REQUIRES_CONSUMER));
    assertEquals(p1.getId(), created.getProductId());
    assertEquals(2, created.getProvidedProducts().size());
    assertEquals("Premium", created.getProduct().getAttributeValue(Product.Attributes.SUPPORT_LEVEL));
    assertEquals(1L, created.getQuantity().longValue());
}
Also used : ProductData(org.candlepin.model.dto.ProductData) Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) List(java.util.List) ArrayList(java.util.ArrayList) Pool(org.candlepin.model.Pool) Test(org.junit.Test)

Example 83 with Pool

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

the class PoolManagerFunctionalTest method testListConditionDevPools.

@Test
public void testListConditionDevPools() {
    Owner owner = createOwner();
    Product p = TestUtil.createProduct("test-product", "Test Product");
    productCurator.create(p);
    Pool pool1 = createPool(owner, p, 10L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2050, 3, 2));
    pool1.setAttribute(Pool.Attributes.DEVELOPMENT_POOL, "true");
    poolCurator.create(pool1);
    Pool pool2 = createPool(owner, p, 10L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2050, 3, 2));
    poolCurator.create(pool2);
    Consumer devSystem = new Consumer("dev", "user", owner, systemType);
    devSystem.setFact("dev_sku", p.getId());
    devSystem.addInstalledProduct(new ConsumerInstalledProduct(p));
    Consumer nonDevSystem = new Consumer("system", "user", owner, systemType);
    nonDevSystem.addInstalledProduct(new ConsumerInstalledProduct(p));
    Page<List<Pool>> results = poolManager.listAvailableEntitlementPools(devSystem, null, owner.getId(), null, null, null, true, new PoolFilterBuilder(), new PageRequest(), false, false, null);
    assertEquals(2, results.getPageData().size());
    results = poolManager.listAvailableEntitlementPools(nonDevSystem, null, owner.getId(), null, null, null, true, new PoolFilterBuilder(), new PageRequest(), false, false, null);
    assertEquals(1, results.getPageData().size());
    Pool found2 = results.getPageData().get(0);
    assertEquals(pool2, found2);
}
Also used : Owner(org.candlepin.model.Owner) PageRequest(org.candlepin.common.paging.PageRequest) Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) 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) Test(org.junit.Test)

Example 84 with Pool

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

the class PoolManagerFunctionalTest method testQuantityCheck.

@Test
public void testQuantityCheck() throws Exception {
    Pool monitoringPool = poolCurator.listByOwnerAndProduct(o, monitoring.getId()).get(0);
    assertEquals(Long.valueOf(5), monitoringPool.getQuantity());
    AutobindData data = AutobindData.create(parentSystem, o).on(new Date()).forProducts(new String[] { monitoring.getId() });
    for (int i = 0; i < 5; i++) {
        List<Entitlement> entitlements = poolManager.entitleByProducts(data);
        assertEquals(1, entitlements.size());
    }
    // The cert should specify 5 monitoring entitlements, taking a 6th should fail:
    assertEquals(0, poolManager.entitleByProducts(data).size());
    assertEquals(Long.valueOf(5), monitoringPool.getConsumed());
}
Also used : Pool(org.candlepin.model.Pool) AutobindData(org.candlepin.resource.dto.AutobindData) Entitlement(org.candlepin.model.Entitlement) Date(java.util.Date) Test(org.junit.Test)

Example 85 with Pool

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

the class PoolManagerFunctionalTest method testListAllForConsumerExcludesErrors.

@Test
public void testListAllForConsumerExcludesErrors() {
    Product p = TestUtil.createProduct("test-product", "Test Product");
    productCurator.create(p);
    Page<List<Pool>> results = poolManager.listAvailableEntitlementPools(parentSystem, null, 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 will 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(parentSystem, null, 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(4, 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) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Pool(org.candlepin.model.Pool) 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