Search in sources :

Example 86 with Entitlement

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

the class ComplianceRulesTest method entIsCompliantWhenSocketsAreCovered.

@Test
public void entIsCompliantWhenSocketsAreCovered() {
    Consumer c = mockConsumer(PRODUCT_1);
    c.setFact("cpu.cpu_socket(s)", "4");
    Entitlement ent = mockEntitlement(c, PRODUCT_1);
    ent.getPool().getProduct().setAttribute(Product.Attributes.SOCKETS, "4");
    CandlepinQuery cqmock = mock(CandlepinQuery.class);
    when(cqmock.list()).thenReturn(Arrays.asList(ent));
    when(entCurator.listByConsumerAndDate(eq(c), any(Date.class))).thenReturn(cqmock);
    assertTrue(compliance.isEntitlementCompliant(c, ent, new Date()));
}
Also used : Consumer(org.candlepin.model.Consumer) CandlepinQuery(org.candlepin.model.CandlepinQuery) Entitlement(org.candlepin.model.Entitlement) Date(java.util.Date) Test(org.junit.Test)

Example 87 with Entitlement

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

the class ComplianceRulesTest method mockEntitlement.

private Entitlement mockEntitlement(Consumer consumer, Product product, Date start, Date end, Product... providedProducts) {
    Set<Product> ppset = new HashSet<>();
    for (Product pp : providedProducts) {
        ppset.add(pp);
    }
    Pool pool = new Pool(owner, product, ppset, new Long(1000), start, end, "1000", "1000", "1000");
    pool.setId("pool_" + TestUtil.randomInt());
    pool.setUpdated(new Date());
    pool.setCreated(new Date());
    when(productCurator.getPoolProvidedProductsCached(pool.getId())).thenReturn(pool.getProvidedProducts());
    Entitlement e = new Entitlement(pool, consumer, owner, 1);
    e.setId("ent_" + TestUtil.randomInt());
    e.setUpdated(new Date());
    e.setCreated(new Date());
    return e;
}
Also used : Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) Date(java.util.Date) HashSet(java.util.HashSet)

Example 88 with Entitlement

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

the class ComplianceRulesTest method instanceBasedPhysicalStackedGreen.

@Test
public void instanceBasedPhysicalStackedGreen() {
    Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2);
    List<Entitlement> ents = new LinkedList<>();
    ents.add(mockInstanceEntitlement(c, STACK_ID_1, "2", TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2));
    ents.add(mockInstanceEntitlement(c, STACK_ID_1, "2", TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2));
    ents.get(0).setQuantity(6);
    ents.get(1).setQuantity(2);
    mockEntCurator(c, ents);
    ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30));
    assertEquals(ComplianceStatus.GREEN, status.getStatus());
    assertEquals(0, status.getNonCompliantProducts().size());
    assertEquals(0, status.getPartiallyCompliantProducts().size());
    assertEquals(2, status.getCompliantProducts().size());
    assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId()));
    assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_2.getId()));
}
Also used : Consumer(org.candlepin.model.Consumer) Entitlement(org.candlepin.model.Entitlement) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 89 with Entitlement

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

the class ComplianceRulesTest method testMultiArchitectureMatch.

@Test
public void testMultiArchitectureMatch() {
    Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2);
    c.setFact("uname.machine", "x86_64");
    List<Entitlement> ents = new LinkedList<>();
    ents.add(mockEntitlement(c, TestUtil.createProduct("Awesome Product"), PRODUCT_1));
    ents.get(0).getPool().getProduct().setAttribute(Product.Attributes.ARCHITECTURE, "PPC64,x86_64");
    ents.add(mockEntitlement(c, TestUtil.createProduct("Awesome Product"), PRODUCT_2));
    ents.get(1).getPool().getProduct().setAttribute(Product.Attributes.ARCHITECTURE, "x86_64");
    mockEntCurator(c, ents);
    ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30));
    // Our one entitlement should not cover both of these:
    assertEquals(2, status.getCompliantProducts().size());
    assertEquals(0, status.getNonCompliantProducts().size());
    assertEquals(0, status.getPartiallyCompliantProducts().size());
    assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_2.getId()));
    assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId()));
    assertEquals("valid", status.getStatus());
}
Also used : Consumer(org.candlepin.model.Consumer) Entitlement(org.candlepin.model.Entitlement) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 90 with Entitlement

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

the class ComplianceRulesTest method mockNonStackedHostRestrictedEntitlement.

private Entitlement mockNonStackedHostRestrictedEntitlement(Consumer consumer, String stackId, Product product, Product... providedProducts) {
    Entitlement ent = this.mockEntitlement(consumer, product, providedProducts);
    Pool pool = ent.getPool();
    pool.setAttribute(Pool.Attributes.REQUIRES_HOST, "SOMEUUID");
    pool.getProduct().setAttribute(Product.Attributes.SOCKETS, "2");
    pool.getProduct().setAttribute(Product.Attributes.VCPU, "1");
    return ent;
}
Also used : Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement)

Aggregations

Entitlement (org.candlepin.model.Entitlement)301 Test (org.junit.Test)201 Consumer (org.candlepin.model.Consumer)164 Pool (org.candlepin.model.Pool)125 LinkedList (java.util.LinkedList)84 Product (org.candlepin.model.Product)68 Date (java.util.Date)62 ArrayList (java.util.ArrayList)61 HashSet (java.util.HashSet)59 HashMap (java.util.HashMap)55 Owner (org.candlepin.model.Owner)44 PoolQuantity (org.candlepin.model.PoolQuantity)35 ConsumerType (org.candlepin.model.ConsumerType)34 List (java.util.List)30 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)24 Matchers.anyString (org.mockito.Matchers.anyString)17 Set (java.util.Set)16 Subscription (org.candlepin.model.dto.Subscription)16 ApiOperation (io.swagger.annotations.ApiOperation)15 ApiResponses (io.swagger.annotations.ApiResponses)15