Search in sources :

Example 56 with PoolQuantity

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

the class AutobindRulesTest method ensureSelectBestPoolsFiltersPoolsBySLAWhenOrgHasSLASet.

@Test
public void ensureSelectBestPoolsFiltersPoolsBySLAWhenOrgHasSLASet() {
    // Create Premium SLA prod
    String slaPremiumProdId = "premium-sla-product";
    Product slaPremiumProduct = TestUtil.createProduct(slaPremiumProdId, "Product with SLA Permium");
    slaPremiumProduct.setAttribute(Product.Attributes.SUPPORT_LEVEL, "Premium");
    Pool slaPremiumPool = TestUtil.createPool(owner, slaPremiumProduct);
    slaPremiumPool.setId("pool-with-premium-sla");
    slaPremiumPool.getProduct().setAttribute(Product.Attributes.SUPPORT_LEVEL, "Premium");
    // Create Standard SLA Product
    String slaStandardProdId = "standard-sla-product";
    Product slaStandardProduct = TestUtil.createProduct(slaStandardProdId, "Product with SLA Standard");
    slaStandardProduct.setAttribute(Product.Attributes.SUPPORT_LEVEL, "Standard");
    Pool slaStandardPool = TestUtil.createPool(owner, slaStandardProduct);
    slaStandardPool.setId("pool-with-standard-sla");
    slaStandardPool.getProduct().setAttribute(Product.Attributes.SUPPORT_LEVEL, "Standard");
    // Create a product with no SLA.
    Product noSLAProduct = TestUtil.createProduct(productId, "A test product");
    Pool noSLAPool = TestUtil.createPool(owner, noSLAProduct);
    noSLAPool.setId("pool-1");
    List<Pool> pools = new LinkedList<>();
    pools.add(noSLAPool);
    pools.add(slaPremiumPool);
    pools.add(slaStandardPool);
    // SLA filtering only occurs when consumer has SLA set.
    consumer.setServiceLevel("");
    owner.setDefaultServiceLevel("Premium");
    List<PoolQuantity> bestPools = autobindRules.selectBestPools(consumer, new String[] { productId, slaPremiumProdId, slaStandardProdId }, pools, compliance, null, new HashSet<>(), false);
    assertEquals(2, bestPools.size());
    assertTrue(bestPools.contains(new PoolQuantity(slaPremiumPool, 1)));
    assertTrue(bestPools.contains(new PoolQuantity(noSLAPool, 1)));
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 57 with PoolQuantity

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

the class AutobindRulesTest method unlimitedPoolIsPickedUp.

@Test
public void unlimitedPoolIsPickedUp() {
    Product product = TestUtil.createProduct(productId, "my-prod");
    product.setAttribute(Product.Attributes.SOCKETS, "2");
    Pool pool = TestUtil.createPool(owner, product, -1);
    pool.setId("POOL-ID");
    List<Pool> pools = new LinkedList<>();
    pools.add(pool);
    List<PoolQuantity> bestPools = autobindRules.selectBestPools(consumer, new String[] { product.getId() }, pools, compliance, null, new HashSet<>(), false);
    assertEquals(1, bestPools.size());
    assertEquals(new Integer(1), bestPools.get(0).getQuantity());
    assertEquals("POOL-ID", bestPools.get(0).getPool().getId());
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 58 with PoolQuantity

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

the class AutobindRulesTest method unenforcedStackedAutobindForPhysical8Socket.

// Testing an edge case, stacking ID defined, but no attributes specified to enforce:
@Test
public void unenforcedStackedAutobindForPhysical8Socket() {
    List<Pool> pools = createStackedPoolEnforcingNothing();
    setupConsumer("8", false);
    List<PoolQuantity> bestPools = autobindRules.selectBestPools(consumer, new String[] { productId }, pools, compliance, null, new HashSet<>(), false);
    assertEquals(1, bestPools.size());
    PoolQuantity q = bestPools.get(0);
    assertEquals(new Integer(1), q.getQuantity());
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Pool(org.candlepin.model.Pool) Test(org.junit.Test)

Example 59 with PoolQuantity

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

the class AutobindRulesTest method instanceAutobindForVirt8Vcpu.

@Test
public void instanceAutobindForVirt8Vcpu() {
    List<Pool> pools = createInstanceBasedPool();
    setupConsumer("8", true);
    List<PoolQuantity> bestPools = autobindRules.selectBestPools(consumer, new String[] { productId }, pools, compliance, null, new HashSet<>(), false);
    assertEquals(1, bestPools.size());
    PoolQuantity q = bestPools.get(0);
    assertEquals(new Integer(1), q.getQuantity());
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Pool(org.candlepin.model.Pool) Test(org.junit.Test)

Example 60 with PoolQuantity

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

the class AutobindRulesTest method testSelectBestPoolsDoesntFilterTooMuchContentForHypervisor.

public void testSelectBestPoolsDoesntFilterTooMuchContentForHypervisor() {
    Pool pool = createV3OnlyPool();
    List<Pool> pools = new LinkedList<>();
    pools.add(pool);
    // Create a hypervisor consumer which does *not* have a certificate version fact.
    // This replicates the real world scenario for virt-who created hypervisors.
    ConsumerType ctype = new ConsumerType(ConsumerTypeEnum.HYPERVISOR);
    ctype.setId("test-ctype");
    consumer = new Consumer("test consumer", "test user", owner, ctype);
    when(consumerTypeCurator.find(eq(ctype.getId()))).thenReturn(ctype);
    when(consumerTypeCurator.lookupByLabel(eq(ctype.getLabel()))).thenReturn(ctype);
    when(consumerTypeCurator.getConsumerType(eq(consumer))).thenReturn(ctype);
    List<PoolQuantity> results = autobindRules.selectBestPools(consumer, new String[] { productId }, pools, compliance, null, new HashSet<>(), false);
    assertEquals(1, results.size());
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Consumer(org.candlepin.model.Consumer) Pool(org.candlepin.model.Pool) ConsumerType(org.candlepin.model.ConsumerType) LinkedList(java.util.LinkedList)

Aggregations

PoolQuantity (org.candlepin.model.PoolQuantity)75 Pool (org.candlepin.model.Pool)65 Test (org.junit.Test)52 Entitlement (org.candlepin.model.Entitlement)34 LinkedList (java.util.LinkedList)30 Product (org.candlepin.model.Product)28 HashMap (java.util.HashMap)27 ArrayList (java.util.ArrayList)21 Consumer (org.candlepin.model.Consumer)12 List (java.util.List)11 ConsumerType (org.candlepin.model.ConsumerType)11 Matchers.anyString (org.mockito.Matchers.anyString)11 Date (java.util.Date)8 Set (java.util.Set)8 HashSet (java.util.HashSet)7 EntitlementRefusedException (org.candlepin.policy.EntitlementRefusedException)7 ValidationResult (org.candlepin.policy.ValidationResult)7 Subscription (org.candlepin.model.dto.Subscription)6 Matchers.anyLong (org.mockito.Matchers.anyLong)6 PoolFilterBuilder (org.candlepin.model.PoolFilterBuilder)5