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());
}
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()));
}
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));
}
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());
}
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()));
}
Aggregations