Search in sources :

Example 21 with ConsumerInstalledProduct

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

the class PoolManagerFunctionalTest method testDevPoolBatchBind.

@Test
public void testDevPoolBatchBind() throws EntitlementRefusedException {
    Owner owner = createOwner();
    Product p = TestUtil.createProduct("test-product", "Test Product");
    productCurator.create(p);
    Consumer devSystem = new Consumer("dev", "user", owner, systemType);
    devSystem.setFact("dev_sku", p.getId());
    devSystem.addInstalledProduct(new ConsumerInstalledProduct(p));
    consumerCurator.create(devSystem);
    Pool pool1 = createPool(owner, p, 10L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2050, 3, 2));
    pool1.setAttribute(Pool.Attributes.DEVELOPMENT_POOL, "true");
    pool1.setAttribute(Pool.Attributes.REQUIRES_CONSUMER, devSystem.getUuid());
    poolCurator.create(pool1);
    Pool pool2 = createPool(owner, p, 10L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2050, 3, 2));
    poolCurator.create(pool2);
    Map<String, Integer> poolQuantities = new HashMap<>();
    poolQuantities.put(pool1.getId(), 1);
    poolQuantities.put(pool2.getId(), 1);
    List<Entitlement> results = poolManager.entitleByPools(devSystem, poolQuantities);
    assertEquals(2, results.size());
    assertTrue(results.get(0).getPool() == pool1 || results.get(0).getPool() == pool2);
    assertTrue(results.get(1).getPool() == pool1 || results.get(1).getPool() == pool2);
    pool1 = poolCurator.find(pool1.getId());
    pool2 = poolCurator.find(pool2.getId());
    assertEquals(1, pool1.getConsumed().intValue());
    assertEquals(1, pool2.getConsumed().intValue());
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) HashMap(java.util.HashMap) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 22 with ConsumerInstalledProduct

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

the class PoolManagerFunctionalTest method testDevPoolRemovalAtUnbind.

@Test
public void testDevPoolRemovalAtUnbind() throws EntitlementRefusedException {
    Owner owner = createOwner();
    Product p = TestUtil.createProduct("test-product", "Test Product");
    productCurator.create(p);
    Consumer devSystem = new Consumer("dev", "user", owner, systemType);
    devSystem.setFact("dev_sku", p.getId());
    devSystem.addInstalledProduct(new ConsumerInstalledProduct(p));
    consumerCurator.create(devSystem);
    Pool pool1 = createPool(owner, p, 10L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2050, 3, 2));
    pool1.setAttribute(Pool.Attributes.DEVELOPMENT_POOL, "true");
    pool1.setAttribute(Pool.Attributes.REQUIRES_CONSUMER, devSystem.getUuid());
    poolCurator.create(pool1);
    Pool pool2 = createPool(owner, p, 10L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2050, 3, 2));
    poolCurator.create(pool2);
    List<String> possPools = new ArrayList<>();
    possPools.add(pool1.getId());
    AutobindData ad = new AutobindData(devSystem, owner);
    ad.setPossiblePools(possPools);
    List<Entitlement> results = poolManager.entitleByProducts(ad);
    assertEquals(1, results.size());
    assertEquals(results.get(0).getPool(), pool1);
    Entitlement e = entitlementCurator.find(results.get(0).getId());
    poolManager.revokeEntitlement(e);
    assertNull(poolCurator.find(pool1.getId()));
    assertNotNull(poolCurator.find(pool2.getId()));
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Pool(org.candlepin.model.Pool) AutobindData(org.candlepin.resource.dto.AutobindData) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 23 with ConsumerInstalledProduct

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

the class ConsumerResourceUpdateTest method ensureNewGuestIsHealedIfItWasMigratedFromAnotherHost.

// ignored out per mkhusid, see 768872 comment #41
@Ignore
@Test
public void ensureNewGuestIsHealedIfItWasMigratedFromAnotherHost() throws Exception {
    String uuid = "TEST_CONSUMER";
    Owner owner = createOwner();
    Consumer existingHost = createConsumerWithGuests(owner, "Guest 1", "Guest 2");
    existingHost.setUuid(uuid);
    Entitlement entitlement = TestUtil.createEntitlement();
    entitlement.getPool().setAttribute(Product.Attributes.VIRT_ONLY, "1");
    entitlement.getPool().setAttribute(Pool.Attributes.REQUIRES_HOST, uuid);
    Consumer guest1 = new Consumer();
    guest1.setUuid("Guest 1");
    guest1.addEntitlement(entitlement);
    ConsumerInstalledProduct installed = mock(ConsumerInstalledProduct.class);
    guest1.addInstalledProduct(installed);
    when(consumerCurator.findByVirtUuid("Guest 1", owner.getId())).thenReturn(guest1);
    // Ensure that the guests host is the existing.
    when(consumerCurator.getHost("Guest 1", owner.getId())).thenReturn(existingHost);
    when(consumerCurator.findByUuid("Guest 1")).thenReturn(guest1);
    Consumer existingMigratedTo = createConsumerWithGuests(owner);
    existingMigratedTo.setUuid("MIGRATED_TO");
    when(this.consumerCurator.findByUuid(existingMigratedTo.getUuid())).thenReturn(existingMigratedTo);
    this.resource.updateConsumer(existingMigratedTo.getUuid(), createConsumerDTOWithGuests("Guest 1"), principal);
    verify(poolManager).revokeEntitlement(eq(entitlement));
    verify(entitler).bindByProducts(AutobindData.create(guest1, owner));
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Entitlement(org.candlepin.model.Entitlement) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 24 with ConsumerInstalledProduct

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

the class ConsumerResourceUpdateTest method installedPackagesChanged.

@Test
public void installedPackagesChanged() throws Exception {
    Product productA = TestUtil.createProduct("Product A");
    Product productB = TestUtil.createProduct("Product B");
    Product productC = TestUtil.createProduct("Product C");
    Consumer consumer = getFakeConsumer();
    consumer.addInstalledProduct(new ConsumerInstalledProduct(productA));
    consumer.addInstalledProduct(new ConsumerInstalledProduct(productB));
    ConsumerDTO incoming = new ConsumerDTO();
    incoming.addInstalledProduct(new ConsumerInstalledProductDTO(productB.getId(), productB.getName()));
    incoming.addInstalledProduct(new ConsumerInstalledProductDTO(productC.getId(), productC.getName()));
    this.resource.updateConsumer(consumer.getUuid(), incoming, principal);
    verify(sink).queueEvent((Event) any());
}
Also used : Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ConsumerInstalledProductDTO(org.candlepin.dto.api.v1.ConsumerInstalledProductDTO) Test(org.junit.Test)

Example 25 with ConsumerInstalledProduct

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

the class ConsumerResourceUpdateTest method testInstalledPackageSetEquality.

@Test
public void testInstalledPackageSetEquality() throws Exception {
    Consumer consumerA = new Consumer();
    Consumer consumerB = new Consumer();
    Consumer consumerC = new Consumer();
    Consumer consumerD = new Consumer();
    Product productA = TestUtil.createProduct("Product A");
    Product productB = TestUtil.createProduct("Product B");
    Product productC = TestUtil.createProduct("Product C");
    Product productD = TestUtil.createProduct("Product D");
    consumerA.addInstalledProduct(new ConsumerInstalledProduct(consumerA, productA));
    consumerA.addInstalledProduct(new ConsumerInstalledProduct(consumerB, productB));
    consumerA.addInstalledProduct(new ConsumerInstalledProduct(consumerC, productC));
    consumerB.addInstalledProduct(new ConsumerInstalledProduct(consumerA, productA));
    consumerB.addInstalledProduct(new ConsumerInstalledProduct(consumerB, productB));
    consumerB.addInstalledProduct(new ConsumerInstalledProduct(consumerC, productC));
    consumerC.addInstalledProduct(new ConsumerInstalledProduct(consumerA, productA));
    consumerC.addInstalledProduct(new ConsumerInstalledProduct(consumerC, productC));
    consumerD.addInstalledProduct(new ConsumerInstalledProduct(consumerA, productA));
    consumerD.addInstalledProduct(new ConsumerInstalledProduct(consumerB, productB));
    consumerD.addInstalledProduct(new ConsumerInstalledProduct(consumerD, productD));
    assertEquals(consumerA.getInstalledProducts(), consumerB.getInstalledProducts());
    assertFalse(consumerA.getInstalledProducts().equals(consumerC.getInstalledProducts()));
    assertFalse(consumerA.getInstalledProducts().equals(consumerD.getInstalledProducts()));
}
Also used : Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Test(org.junit.Test)

Aggregations

ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)66 Consumer (org.candlepin.model.Consumer)54 Product (org.candlepin.model.Product)51 Test (org.junit.Test)49 Owner (org.candlepin.model.Owner)44 Date (java.util.Date)35 DateRange (org.candlepin.policy.js.compliance.DateRange)26 HashSet (java.util.HashSet)14 ArrayList (java.util.ArrayList)13 Entitlement (org.candlepin.model.Entitlement)11 Pool (org.candlepin.model.Pool)11 ConsumerType (org.candlepin.model.ConsumerType)10 AutobindData (org.candlepin.resource.dto.AutobindData)10 HashMap (java.util.HashMap)8 ConsumerCapability (org.candlepin.model.ConsumerCapability)7 List (java.util.List)6 ProductData (org.candlepin.model.dto.ProductData)6 ConsumerInstalledProductDTO (org.candlepin.dto.api.v1.ConsumerInstalledProductDTO)4 Environment (org.candlepin.model.Environment)4 GuestId (org.candlepin.model.GuestId)4