use of org.candlepin.model.Entitlement in project candlepin by candlepin.
the class PoolManagerFunctionalTest method testRevocationRevokesEntitlementCertSerial.
@Test
public void testRevocationRevokesEntitlementCertSerial() throws Exception {
AutobindData data = AutobindData.create(parentSystem, o).on(new Date()).forProducts(new String[] { monitoring.getId() });
Entitlement e = poolManager.entitleByProducts(data).get(0);
CertificateSerial serial = e.getCertificates().iterator().next().getSerial();
poolManager.revokeEntitlement(e);
List<Entitlement> entitlements = entitlementCurator.listByConsumer(parentSystem);
assertTrue(entitlements.isEmpty());
CertificateSerial revoked = certSerialCurator.find(serial.getId());
assertTrue("Entitlement cert serial should have been marked as revoked once deleted!", revoked.isRevoked());
}
use of org.candlepin.model.Entitlement in project candlepin by candlepin.
the class PoolManagerFunctionalTest method testCleanupExpiredPoolsWithEntitlementEndDateOverrides.
@Test
public void testCleanupExpiredPoolsWithEntitlementEndDateOverrides() {
long ct = System.currentTimeMillis();
Date activeStart = new Date(ct + 3600000);
Date activeEnd = new Date(ct + 7200000);
Date expiredStart = new Date(ct - 7200000);
Date expiredEnd = new Date(ct - 3600000);
Owner owner = this.createOwner();
List<Consumer> consumers = new LinkedList<>();
List<Product> products = new LinkedList<>();
List<Pool> pools = new LinkedList<>();
List<Entitlement> entitlements = new LinkedList<>();
int objCount = 6;
for (int i = 0; i < objCount; ++i) {
Consumer consumer = this.createConsumer(owner);
Product product = this.createProduct("test-product-" + i, "Test Product " + i, owner);
Pool pool = (i % 2 == 0) ? this.createPool(owner, product, 1L, activeStart, activeEnd) : this.createPool(owner, product, 1L, expiredStart, expiredEnd);
consumers.add(consumer);
products.add(product);
pools.add(pool);
}
entitlements.add(this.createEntitlement(owner, consumers.get(0), pools.get(2), null));
entitlements.add(this.createEntitlement(owner, consumers.get(1), pools.get(3), null));
entitlements.add(this.createEntitlement(owner, consumers.get(2), pools.get(4), null));
entitlements.add(this.createEntitlement(owner, consumers.get(3), pools.get(5), null));
entitlements.get(0).setEndDateOverride(activeEnd);
entitlements.get(1).setEndDateOverride(activeEnd);
entitlements.get(2).setEndDateOverride(expiredEnd);
entitlements.get(3).setEndDateOverride(expiredEnd);
for (Entitlement entitlement : entitlements) {
this.entitlementCurator.merge(entitlement);
}
this.poolCurator.flush();
this.poolManager.cleanupExpiredPools();
// Active pool, no ent
assertNotNull(this.poolCurator.find(pools.get(0).getId()));
// Expired pool, no ent
assertNull(this.poolCurator.find(pools.get(1).getId()));
// Active pool, active ent
assertNotNull(this.poolCurator.find(pools.get(2).getId()));
// Expired pool, active ent
assertNotNull(this.poolCurator.find(pools.get(3).getId()));
// Active pool, expired ent
assertNotNull(this.poolCurator.find(pools.get(4).getId()));
// Expired pool, expired ent
assertNull(this.poolCurator.find(pools.get(5).getId()));
}
use of org.candlepin.model.Entitlement 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.Entitlement in project candlepin by candlepin.
the class EntitleByProductsJobTest method bindByProductsExec.
@Test
public void bindByProductsExec() throws Exception {
String[] pids = { "pid1", "pid2", "pid3" };
JobDetail detail = EntitleByProductsJob.bindByProducts(pids, consumer, null, null, owner.getKey());
JobExecutionContext ctx = mock(JobExecutionContext.class);
when(ctx.getMergedJobDataMap()).thenReturn(detail.getJobDataMap());
List<Entitlement> ents = new ArrayList<>();
when(e.bindByProducts(eq(pids), eq(consumerUuid), eq((Date) null), eq((Collection<String>) null))).thenReturn(ents);
EntitleByProductsJob job = new EntitleByProductsJob(e, null);
injector.injectMembers(job);
job.execute(ctx);
verify(e).bindByProducts(eq(pids), eq(consumerUuid), eq((Date) null), eq((Collection<String>) null));
verify(e).sendEvents(eq(ents));
}
use of org.candlepin.model.Entitlement in project candlepin by candlepin.
the class QuantityRulesTest method testStackOnlyStacksWithSameStackingId.
@Test
public void testStackOnlyStacksWithSameStackingId() {
consumer.setFact(IS_VIRT, "false");
consumer.setFact(SOCKET_FACT, "8");
pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");
pool.setQuantity(10L);
Product product1 = TestUtil.createProduct();
Pool pool1 = TestUtil.createPool(owner, product1);
Entitlement e = TestUtil.createEntitlement(owner, consumer, pool1, new EntitlementCertificate());
Set<Entitlement> entSet = new HashSet<>();
entSet.add(e);
pool1.setEntitlements(entSet);
pool1.getProduct().setAttribute(Pool.Attributes.MULTI_ENTITLEMENT, "yes");
pool1.getProduct().setAttribute(Product.Attributes.STACKING_ID, "2");
pool1.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");
pool1.setQuantity(10L);
// Consume 2 subscriptions with another stacking ID
Entitlement toAdd = pool1.getEntitlements().iterator().next();
toAdd.setQuantity(2);
consumer.addEntitlement(toAdd);
// Ensure the 2 attached entitlements do not cause the suggested quantity to change
SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
assertEquals(new Long(4), suggested.getSuggested());
}
Aggregations