use of org.candlepin.model.ConsumerInstalledProduct in project candlepin by candlepin.
the class PoolManagerTest method expiredEntitlementEvent.
@Test
public void expiredEntitlementEvent() {
Date now = new Date();
Product p = TestUtil.createProduct();
p.setAttribute(Product.Attributes.HOST_LIMITED, "true");
p.setAttribute(Product.Attributes.VIRT_LIMIT, "unlimited");
Consumer guest = TestUtil.createConsumer(owner);
guest.setFact("virt.is_guest", "true");
guest.addInstalledProduct(new ConsumerInstalledProduct(p));
Pool pool = TestUtil.createPool(owner, p);
pool.setAttribute(Pool.Attributes.UNMAPPED_GUESTS_ONLY, "true");
pool.setAttribute(Pool.Attributes.VIRT_ONLY, "true");
pool.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
pool.setAttribute(Pool.Attributes.PHYSICAL_ONLY, "false");
pool.setAttribute(Product.Attributes.VIRT_LIMIT, "0");
pool.setStartDate(new Date(now.getTime() - (1000 * 60 * 60 * 24 * 2)));
Entitlement ent = TestUtil.createEntitlement(owner, guest, pool, null);
ent.setEndDateOverride(new Date(now.getTime() - (1000 * 60 * 60 * 24 * 1)));
ent.setId("test-ent-id");
ent.setQuantity(1);
Set<Entitlement> entitlements = new HashSet<>();
entitlements.add(ent);
pool.setEntitlements(entitlements);
Event event = new Event();
event.setConsumerUuid(guest.getUuid());
event.setOwnerId(owner.getId());
event.setTarget(Target.ENTITLEMENT);
event.setType(Type.EXPIRED);
when(eventFactory.entitlementExpired(eq(ent))).thenReturn(event);
when(mockPoolCurator.lockAndLoad(eq(pool))).thenReturn(pool);
manager.revokeEntitlement(ent);
String message = event.getMessageText();
assertNotNull(message);
message = message.split(": ")[1];
assertEquals(message, i18n.tr("Unmapped guest entitlement expired without establishing a host/guest mapping."));
}
use of org.candlepin.model.ConsumerInstalledProduct in project candlepin by candlepin.
the class EntitlerTest method testDevPoolCreationAtBindFailStandalone.
@Test(expected = ForbiddenException.class)
public void testDevPoolCreationAtBindFailStandalone() throws Exception {
Owner owner = TestUtil.createOwner("o");
List<ProductData> devProdDTOs = new ArrayList<>();
Product p = TestUtil.createProduct("test-product", "Test Product");
devProdDTOs.add(p.toDTO());
Pool activePool = TestUtil.createPool(owner, p);
List<Pool> activeList = new ArrayList<>();
activeList.add(activePool);
Consumer devSystem = TestUtil.createConsumer(owner);
devSystem.setFact("dev_sku", p.getId());
devSystem.addInstalledProduct(new ConsumerInstalledProduct(p));
when(config.getBoolean(eq(ConfigProperties.STANDALONE))).thenReturn(true);
when(poolCurator.hasActiveEntitlementPools(eq(owner.getId()), any(Date.class))).thenReturn(true);
when(productAdapter.getProductsByIds(any(Owner.class), any(List.class))).thenReturn(devProdDTOs);
when(ownerProductCurator.getProductById(eq(owner), eq(p.getId()))).thenReturn(p);
AutobindData ad = new AutobindData(devSystem, owner);
entitler.bindByProducts(ad);
}
use of org.candlepin.model.ConsumerInstalledProduct in project candlepin by candlepin.
the class EntitlerTest method testDevPoolCreationAtBindFailNotActive.
@Test(expected = ForbiddenException.class)
public void testDevPoolCreationAtBindFailNotActive() throws Exception {
Owner owner = TestUtil.createOwner("o");
List<ProductData> devProdDTOs = new ArrayList<>();
Product p = TestUtil.createProduct("test-product", "Test Product");
devProdDTOs.add(p.toDTO());
Consumer devSystem = TestUtil.createConsumer(owner);
devSystem.setFact("dev_sku", p.getId());
devSystem.addInstalledProduct(new ConsumerInstalledProduct(p));
when(config.getBoolean(eq(ConfigProperties.STANDALONE))).thenReturn(false);
when(poolCurator.hasActiveEntitlementPools(eq(owner.getId()), any(Date.class))).thenReturn(false);
when(productAdapter.getProductsByIds(any(Owner.class), any(List.class))).thenReturn(devProdDTOs);
when(ownerProductCurator.getProductById(eq(owner), eq(p.getId()))).thenReturn(p);
AutobindData ad = new AutobindData(devSystem, owner);
entitler.bindByProducts(ad);
}
use of org.candlepin.model.ConsumerInstalledProduct in project candlepin by candlepin.
the class EntitlerTest method testCreatedDevPoolAttributes.
@Test
public void testCreatedDevPoolAttributes() {
Owner owner = TestUtil.createOwner("o");
List<ProductData> devProdDTOs = new ArrayList<>();
Product p1 = TestUtil.createProduct("dev-product", "Dev Product");
p1.setAttribute(Product.Attributes.SUPPORT_LEVEL, "Premium");
p1.setAttribute("expires_after", "47");
Product p2 = TestUtil.createProduct("provided-product1", "Provided Product 1");
Product p3 = TestUtil.createProduct("provided-product2", "Provided Product 2");
devProdDTOs.add(p1.toDTO());
devProdDTOs.add(p2.toDTO());
devProdDTOs.add(p3.toDTO());
Consumer devSystem = TestUtil.createConsumer(owner);
devSystem.setFact("dev_sku", p1.getId());
devSystem.addInstalledProduct(new ConsumerInstalledProduct(p2));
devSystem.addInstalledProduct(new ConsumerInstalledProduct(p3));
when(productAdapter.getProductsByIds(eq(owner), any(List.class))).thenReturn(devProdDTOs);
this.mockProducts(owner, p1, p2, p3);
this.mockProductImport(owner, p1, p2, p3);
this.mockContentImport(owner, Collections.<String, Content>emptyMap());
Pool created = entitler.assembleDevPool(devSystem, owner, devSystem.getFact("dev_sku"));
Calendar cal = Calendar.getInstance();
cal.setTime(created.getStartDate());
cal.add(Calendar.DAY_OF_YEAR, 47);
assertEquals(created.getEndDate(), cal.getTime());
assertEquals("true", created.getAttributeValue(Pool.Attributes.DEVELOPMENT_POOL));
assertEquals(devSystem.getUuid(), created.getAttributeValue(Pool.Attributes.REQUIRES_CONSUMER));
assertEquals(p1.getId(), created.getProductId());
assertEquals(2, created.getProvidedProducts().size());
assertEquals("Premium", created.getProduct().getAttributeValue(Product.Attributes.SUPPORT_LEVEL));
assertEquals(1L, created.getQuantity().longValue());
}
use of org.candlepin.model.ConsumerInstalledProduct in project candlepin by candlepin.
the class PoolManagerFunctionalTest method testListConditionDevPools.
@Test
public void testListConditionDevPools() {
Owner owner = createOwner();
Product p = TestUtil.createProduct("test-product", "Test Product");
productCurator.create(p);
Pool pool1 = createPool(owner, p, 10L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2050, 3, 2));
pool1.setAttribute(Pool.Attributes.DEVELOPMENT_POOL, "true");
poolCurator.create(pool1);
Pool pool2 = createPool(owner, p, 10L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2050, 3, 2));
poolCurator.create(pool2);
Consumer devSystem = new Consumer("dev", "user", owner, systemType);
devSystem.setFact("dev_sku", p.getId());
devSystem.addInstalledProduct(new ConsumerInstalledProduct(p));
Consumer nonDevSystem = new Consumer("system", "user", owner, systemType);
nonDevSystem.addInstalledProduct(new ConsumerInstalledProduct(p));
Page<List<Pool>> results = poolManager.listAvailableEntitlementPools(devSystem, null, owner.getId(), null, null, null, true, new PoolFilterBuilder(), new PageRequest(), false, false, null);
assertEquals(2, results.getPageData().size());
results = poolManager.listAvailableEntitlementPools(nonDevSystem, null, owner.getId(), null, null, null, true, new PoolFilterBuilder(), new PageRequest(), false, false, null);
assertEquals(1, results.getPageData().size());
Pool found2 = results.getPageData().get(0);
assertEquals(pool2, found2);
}
Aggregations