Search in sources :

Example 11 with GuestId

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

the class ComplianceRulesTest method isEntPartiallyCompliantNonOverriddenVirtLimit.

@Test
public void isEntPartiallyCompliantNonOverriddenVirtLimit() {
    Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2);
    for (int i = 0; i < 5; i++) {
        c.addGuestId(new GuestId("" + i, c, activeGuestAttrs));
    }
    List<Entitlement> ents = new LinkedList<>();
    Entitlement mockServerEntitlement = mockEntitlement(c, TestUtil.createProduct("Awesome OS server"), PRODUCT_1, PRODUCT_2);
    mockServerEntitlement.getPool().getProduct().setAttribute(Product.Attributes.GUEST_LIMIT, "4");
    ents.add(mockServerEntitlement);
    mockEntCurator(c, ents);
    // The guest limit has not been modified, should not be compliant.
    assertFalse(compliance.isEntitlementCompliant(c, mockServerEntitlement, new Date()));
}
Also used : Consumer(org.candlepin.model.Consumer) GuestId(org.candlepin.model.GuestId) Entitlement(org.candlepin.model.Entitlement) LinkedList(java.util.LinkedList) Date(java.util.Date) Test(org.junit.Test)

Example 12 with GuestId

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

the class ComplianceRulesTest method isStackFullyCompliantOverriddenVirtLimit.

@Test
public void isStackFullyCompliantOverriddenVirtLimit() {
    Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2);
    for (int i = 0; i < 5; i++) {
        c.addGuestId(new GuestId("" + i, c, activeGuestAttrs));
    }
    List<Entitlement> ents = new LinkedList<>();
    Entitlement mockServerEntitlement = mockStackedEntitlement(c, "mockServerStack", PRODUCT_1, PRODUCT_2);
    mockServerEntitlement.getPool().getProduct().setAttribute(Product.Attributes.GUEST_LIMIT, "4");
    mockServerEntitlement.getPool().getProduct().setAttribute(Product.Attributes.SOCKETS, "2");
    mockServerEntitlement.setQuantity(4);
    ents.add(mockServerEntitlement);
    Entitlement mockHypervisorEntitlement = mockEntitlement(c, TestUtil.createProduct("Awesome Enterprise Hypervisor"), PRODUCT_1, PRODUCT_2);
    mockHypervisorEntitlement.getPool().getProduct().setAttribute(Product.Attributes.GUEST_LIMIT, "-1");
    ents.add(mockHypervisorEntitlement);
    // Now that we've added the hypervisor,
    // the base guest_limit of 4 should be overridden
    assertTrue(compliance.isStackCompliant(c, "mockServerStack", ents));
}
Also used : Consumer(org.candlepin.model.Consumer) GuestId(org.candlepin.model.GuestId) Entitlement(org.candlepin.model.Entitlement) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 13 with GuestId

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

the class ComplianceRulesTest method fullyCompliantVirtLimitStack.

@Test
public void fullyCompliantVirtLimitStack() {
    Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2);
    for (int i = 0; i < 5; i++) {
        c.addGuestId(new GuestId("" + i, c, activeGuestAttrs));
    }
    List<Entitlement> ents = new LinkedList<>();
    ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2));
    ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2));
    ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2));
    ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2));
    for (Entitlement ent : ents) {
        ent.getPool().getProduct().setAttribute(Product.Attributes.GUEST_LIMIT, "8");
    }
    mockEntCurator(c, ents);
    ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30));
    assertEquals(0, status.getNonCompliantProducts().size());
    assertEquals(2, status.getCompliantProducts().size());
    assertEquals(0, status.getPartiallyCompliantProducts().size());
    assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId()));
    assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_2.getId()));
    assertEquals(4, status.getCompliantProducts().get(PRODUCT_1.getId()).size());
    assertEquals(4, status.getCompliantProducts().get(PRODUCT_2.getId()).size());
}
Also used : Consumer(org.candlepin.model.Consumer) GuestId(org.candlepin.model.GuestId) Entitlement(org.candlepin.model.Entitlement) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 14 with GuestId

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

the class ComplianceRulesTest method fullyCompliantVirtLimitStackVaryingLimits.

@Test
public void fullyCompliantVirtLimitStackVaryingLimits() {
    Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2);
    for (int i = 0; i < 5; i++) {
        c.addGuestId(new GuestId("" + i, c, activeGuestAttrs));
    }
    List<Entitlement> ents = new LinkedList<>();
    ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2));
    ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2));
    ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2));
    ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2));
    for (Entitlement ent : ents) {
        ent.getPool().getProduct().setAttribute(Product.Attributes.GUEST_LIMIT, "1");
    }
    ents.get(0).getPool().getProduct().setAttribute(Product.Attributes.GUEST_LIMIT, "5");
    mockEntCurator(c, ents);
    ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30));
    assertEquals(0, status.getNonCompliantProducts().size());
    assertEquals(2, status.getCompliantProducts().size());
    assertEquals(0, status.getPartiallyCompliantProducts().size());
    assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId()));
    assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_2.getId()));
    assertEquals(4, status.getCompliantProducts().get(PRODUCT_1.getId()).size());
    assertEquals(4, status.getCompliantProducts().get(PRODUCT_2.getId()).size());
}
Also used : Consumer(org.candlepin.model.Consumer) GuestId(org.candlepin.model.GuestId) Entitlement(org.candlepin.model.Entitlement) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 15 with GuestId

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

the class ComplianceRulesTest method isEntFullyCompliantOverriddenVirtLimit.

@Test
public void isEntFullyCompliantOverriddenVirtLimit() {
    Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2);
    for (int i = 0; i < 5; i++) {
        c.addGuestId(new GuestId("" + i, c, activeGuestAttrs));
    }
    List<Entitlement> ents = new LinkedList<>();
    Entitlement mockServerEntitlement = mockEntitlement(c, TestUtil.createProduct("Awesome OS server"), PRODUCT_1, PRODUCT_2);
    mockServerEntitlement.getPool().getProduct().setAttribute(Product.Attributes.GUEST_LIMIT, "4");
    ents.add(mockServerEntitlement);
    Entitlement mockHypervisorEntitlement = mockEntitlement(c, TestUtil.createProduct("Awesome Enterprise Hypervisor"), PRODUCT_1, PRODUCT_2);
    mockHypervisorEntitlement.getPool().getProduct().setAttribute(Product.Attributes.GUEST_LIMIT, "-1");
    ents.add(mockHypervisorEntitlement);
    mockEntCurator(c, ents);
    // Now that we've added the hypervisor,
    // the base guest_limit of 4 should be overridden
    assertTrue(compliance.isEntitlementCompliant(c, mockServerEntitlement, new Date()));
}
Also used : Consumer(org.candlepin.model.Consumer) GuestId(org.candlepin.model.GuestId) Entitlement(org.candlepin.model.Entitlement) LinkedList(java.util.LinkedList) Date(java.util.Date) Test(org.junit.Test)

Aggregations

GuestId (org.candlepin.model.GuestId)49 Consumer (org.candlepin.model.Consumer)37 Test (org.junit.Test)34 LinkedList (java.util.LinkedList)15 Entitlement (org.candlepin.model.Entitlement)14 GuestIdDTO (org.candlepin.dto.api.v1.GuestIdDTO)11 Date (java.util.Date)10 HashMap (java.util.HashMap)8 Product (org.candlepin.model.Product)8 ArrayList (java.util.ArrayList)7 Owner (org.candlepin.model.Owner)7 VirtConsumerMap (org.candlepin.model.VirtConsumerMap)7 HashSet (java.util.HashSet)6 Set (java.util.Set)6 List (java.util.List)5 Pool (org.candlepin.model.Pool)5 ApiOperation (io.swagger.annotations.ApiOperation)4 Produces (javax.ws.rs.Produces)4 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)4 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)4