Search in sources :

Example 6 with GuestId

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

the class CriteriaRulesTest method manifestConsumerVirtOnlyNoRequiresHost.

@Test
public void manifestConsumerVirtOnlyNoRequiresHost() {
    // create a manifest consumer
    ConsumerType type = new ConsumerType(ConsumerType.ConsumerTypeEnum.CANDLEPIN);
    consumerTypeCurator.create(type);
    Consumer c = new Consumer("test-consumer", "test-user", owner, type);
    consumerCurator.create(c);
    Consumer host = createConsumer(owner);
    host.addGuestId(new GuestId("GUESTUUID", host));
    consumerCurator.update(host);
    Product targetProduct = this.createProduct(owner);
    Pool virtPool = this.createPool(owner, targetProduct, 1L, new Date(), new Date());
    virtPool.setAttribute(Product.Attributes.VIRT_ONLY, "true");
    virtPool.setAttribute(Pool.Attributes.REQUIRES_HOST, host.getUuid());
    poolCurator.merge(virtPool);
    poolCurator.flush();
    List<Pool> results = poolCurator.listAvailableEntitlementPools(c, (String) null, (Collection<String>) null, null);
    assertEquals(0, results.size());
}
Also used : Consumer(org.candlepin.model.Consumer) GuestId(org.candlepin.model.GuestId) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) ConsumerType(org.candlepin.model.ConsumerType) Date(java.util.Date) Test(org.junit.Test)

Example 7 with GuestId

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

the class CriteriaRulesTest method requiresHostPoolAttributeFiltering.

@Test
public void requiresHostPoolAttributeFiltering() {
    consumer = this.createConsumer(owner);
    Consumer host = createConsumer(owner);
    host.addGuestId(new GuestId("GUESTUUID", host));
    consumerCurator.update(host);
    Product targetProduct = this.createProduct(owner);
    Pool virtPool = this.createPool(owner, targetProduct, 1L, new Date(), new Date());
    virtPool.setAttribute(Product.Attributes.VIRT_ONLY, "true");
    virtPool.setAttribute(Pool.Attributes.REQUIRES_HOST, host.getUuid());
    poolCurator.merge(virtPool);
    // Another pool requiring a different host:
    Pool anotherVirtPool = this.createPool(owner, targetProduct, 1L, new Date(), new Date());
    anotherVirtPool.setAttribute(Product.Attributes.VIRT_ONLY, "true");
    anotherVirtPool.setAttribute(Pool.Attributes.REQUIRES_HOST, "SOMEOTHERUUID");
    poolCurator.merge(anotherVirtPool);
    poolCurator.flush();
    List<Pool> results = poolCurator.listAvailableEntitlementPools(consumer, (String) null, (Collection<String>) null, null);
    assertEquals(0, results.size());
    // Make the consumer a guest and try again:
    consumer.setFact("virt.is_guest", "true");
    consumer.setFact("virt.uuid", "GUESTUUID");
    consumerCurator.update(consumer);
    assertEquals(host.getUuid(), consumerCurator.getHost("GUESTUUID", owner.getId()).getUuid());
    results = poolCurator.listAvailableEntitlementPools(consumer, (String) null, (Collection<String>) null, null);
    assertEquals(1, results.size());
    assertEquals(virtPool.getId(), results.get(0).getId());
}
Also used : Consumer(org.candlepin.model.Consumer) GuestId(org.candlepin.model.GuestId) Product(org.candlepin.model.Product) Collection(java.util.Collection) Pool(org.candlepin.model.Pool) Date(java.util.Date) Test(org.junit.Test)

Example 8 with GuestId

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

the class CriteriaRulesTest method manifestConsumerVirtOnly.

@Test
public void manifestConsumerVirtOnly() {
    // create a manifest consumer
    ConsumerType type = new ConsumerType(ConsumerType.ConsumerTypeEnum.CANDLEPIN);
    consumerTypeCurator.create(type);
    Consumer c = new Consumer("test-consumer", "test-user", owner, type);
    consumerCurator.create(c);
    Consumer host = createConsumer(owner);
    host.addGuestId(new GuestId("GUESTUUID", host));
    consumerCurator.update(host);
    Product targetProduct = this.createProduct(owner);
    Pool virtPool = this.createPool(owner, targetProduct, 1L, new Date(), new Date());
    virtPool.setAttribute(Product.Attributes.VIRT_ONLY, "true");
    poolCurator.merge(virtPool);
    poolCurator.flush();
    List<Pool> results = poolCurator.listAvailableEntitlementPools(c, (String) null, (Collection<String>) null, null);
    assertEquals(1, results.size());
}
Also used : Consumer(org.candlepin.model.Consumer) GuestId(org.candlepin.model.GuestId) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) ConsumerType(org.candlepin.model.ConsumerType) Date(java.util.Date) Test(org.junit.Test)

Example 9 with GuestId

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

the class ComplianceRulesTest method fullyCompliantVirtLimitStackWithInactiveGuests.

@Test
public void fullyCompliantVirtLimitStackWithInactiveGuests() {
    Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2);
    for (int i = 0; i < 5; i++) {
        c.addGuestId(new GuestId("" + i, c));
    }
    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, "4");
    }
    mockEntCurator(c, ents);
    ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30));
    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()));
    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 10 with GuestId

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

the class ComplianceRulesTest method fullyCompliantVirtLimitStackAllUnlimited.

@Test
public void fullyCompliantVirtLimitStackAllUnlimited() {
    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");
    }
    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)

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