Search in sources :

Example 81 with Entitlement

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

the class QuantityRulesTest method testPhysicalIgnoresPastConsumed.

@Test
public void testPhysicalIgnoresPastConsumed() {
    pool.getProduct().setAttribute(Pool.Attributes.MULTI_ENTITLEMENT, "yes");
    pool.getProduct().setAttribute(Product.Attributes.STACKING_ID, "1");
    pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "1");
    consumer.setFact(SOCKET_FACT, "4");
    // Green now, but we will ask for suggested quantity on a date in the future:
    Entitlement e = createValidEntitlement(pool);
    e.setQuantity(4);
    Set<Entitlement> ents = new HashSet<>();
    ents.add(e);
    consumer.setEntitlements(ents);
    // Ask for quantity in the future, past the end of the current pool:
    Calendar c = Calendar.getInstance();
    c.setTime(pool.getEndDate());
    Date futureDate = TestUtil.createDate(c.get(Calendar.YEAR) + 1, 1, 1);
    SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, futureDate);
    assertEquals(new Long(4), suggested.getSuggested());
}
Also used : Calendar(java.util.Calendar) Entitlement(org.candlepin.model.Entitlement) Date(java.util.Date) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 82 with Entitlement

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

the class RulesObjectMapperTest method filterEntitlementConsumer.

@Test
public void filterEntitlementConsumer() {
    Entitlement e = new Entitlement();
    Consumer c = new Consumer();
    IdentityCertificate cert = new IdentityCertificate();
    cert.setCert("FILTERMEPLEASE");
    cert.setKey("KEY");
    c.setIdCert(cert);
    e.setConsumer(c);
    context.put("entitlement", e);
    String output = objMapper.toJsonString(context);
    assertFalse(output.contains("consumer"));
}
Also used : Consumer(org.candlepin.model.Consumer) Entitlement(org.candlepin.model.Entitlement) IdentityCertificate(org.candlepin.model.IdentityCertificate) Test(org.junit.Test)

Example 83 with Entitlement

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

the class RulesObjectMapperTest method filterEntitlementCert.

@Test
public void filterEntitlementCert() {
    List<Entitlement> allEnts = new LinkedList<>();
    Entitlement e = new Entitlement();
    Set<EntitlementCertificate> entCerts = new HashSet<>();
    EntitlementCertificate cert = new EntitlementCertificate();
    cert.setCert("FILTERME");
    cert.setKey("FILTERME");
    entCerts.add(cert);
    e.setCertificates(entCerts);
    allEnts.add(e);
    context.put("entitlements", allEnts);
    String output = objMapper.toJsonString(context);
    assertFalse(output.contains("FILTERME"));
}
Also used : EntitlementCertificate(org.candlepin.model.EntitlementCertificate) Entitlement(org.candlepin.model.Entitlement) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 84 with Entitlement

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

the class ComplianceRulesTest method mockHostRestrictedEntitlement.

private Entitlement mockHostRestrictedEntitlement(Consumer consumer, String stackId, Product product, Product... providedProducts) {
    Entitlement ent = this.mockBaseStackedEntitlement(consumer, stackId, 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)

Example 85 with Entitlement

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

the class ComplianceRulesTest method virtualStackedOnlyUsesVcpuAndRam.

@Test
public void virtualStackedOnlyUsesVcpuAndRam() {
    Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2);
    c.setFact("virt.is_guest", "true");
    c.setFact("cpu.core(s)_per_socket", "8");
    c.setFact("cpu.cpu_socket(s)", "10");
    // 8GB RAM
    c.setFact("memory.memtotal", "8000000");
    List<Entitlement> ents = new LinkedList<>();
    Entitlement ent = mockBaseStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2);
    ent.getPool().getProduct().setAttribute(Product.Attributes.CORES, "1");
    ent.getPool().getProduct().setAttribute(Product.Attributes.RAM, "1");
    ent.getPool().getProduct().setAttribute(Product.Attributes.SOCKETS, "1");
    ent.getPool().getProduct().setAttribute(Product.Attributes.VCPU, "1");
    ents.add(ent);
    ents.get(0).setQuantity(1);
    mockEntCurator(c, ents);
    ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30));
    assertEquals(ComplianceStatus.YELLOW, status.getStatus());
    assertEquals(0, status.getNonCompliantProducts().size());
    assertEquals(2, status.getPartiallyCompliantProducts().size());
    assertEquals(0, status.getCompliantProducts().size());
    assertTrue(status.getPartiallyCompliantProducts().keySet().contains(PRODUCT_1.getId()));
    assertTrue(status.getPartiallyCompliantProducts().keySet().contains(PRODUCT_2.getId()));
    // We should be partial because of ram and vcpus, nothing else
    assertEquals(2, status.getReasons().size());
    List<String> reasonKeys = new LinkedList<>();
    for (ComplianceReason r : status.getReasons()) {
        reasonKeys.add(r.getKey());
    }
    assertTrue(reasonKeys.contains("RAM"));
    assertTrue(reasonKeys.contains("VCPU"));
}
Also used : Consumer(org.candlepin.model.Consumer) Entitlement(org.candlepin.model.Entitlement) LinkedList(java.util.LinkedList) Test(org.junit.Test)

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