use of org.candlepin.resource.dto.AutobindData in project candlepin by candlepin.
the class PoolManagerFunctionalTest method testQuantityCheck.
@Test
public void testQuantityCheck() throws Exception {
Pool monitoringPool = poolCurator.listByOwnerAndProduct(o, monitoring.getId()).get(0);
assertEquals(Long.valueOf(5), monitoringPool.getQuantity());
AutobindData data = AutobindData.create(parentSystem, o).on(new Date()).forProducts(new String[] { monitoring.getId() });
for (int i = 0; i < 5; i++) {
List<Entitlement> entitlements = poolManager.entitleByProducts(data);
assertEquals(1, entitlements.size());
}
// The cert should specify 5 monitoring entitlements, taking a 6th should fail:
assertEquals(0, poolManager.entitleByProducts(data).size());
assertEquals(Long.valueOf(5), monitoringPool.getConsumed());
}
use of org.candlepin.resource.dto.AutobindData in project candlepin by candlepin.
the class PoolManagerFunctionalTest method testRegenerateEntitlementCertificatesWithMultipleEntitlements.
@Test
public void testRegenerateEntitlementCertificatesWithMultipleEntitlements() throws EntitlementRefusedException {
AutobindData data = AutobindData.create(childVirtSystem, o).on(new Date()).forProducts(new String[] { provisioning.getId() });
this.entitlementCurator.refresh(poolManager.entitleByProducts(data).get(0));
this.entitlementCurator.refresh(poolManager.entitleByProducts(data).get(0));
regenerateECAndAssertNotSameCertificates();
}
use of org.candlepin.resource.dto.AutobindData 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.resource.dto.AutobindData 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.resource.dto.AutobindData in project candlepin by candlepin.
the class PoolManagerFunctionalTest method testEntitleByProductsWithModifierAndModifiee.
@Test
public void testEntitleByProductsWithModifierAndModifiee() throws EntitlementRefusedException {
Product modifier = TestUtil.createProduct("modifier", "modifier");
Set<String> modified = new HashSet<>();
modified.add(PRODUCT_VIRT_HOST);
Content content = TestUtil.createContent("modifier-content", "modifier-content");
content.setModifiedProductIds(modified);
modifier.addContent(content, true);
contentCurator.create(content);
productCurator.create(modifier);
this.ownerContentCurator.mapContentToOwner(content, this.o);
List<Subscription> subscriptions = new LinkedList<>();
ImportSubscriptionServiceAdapter subAdapter = new ImportSubscriptionServiceAdapter(subscriptions);
Subscription sub = TestUtil.createSubscription(o, modifier, new HashSet<>());
sub.setQuantity(5L);
sub.setStartDate(new Date());
sub.setEndDate(TestUtil.createDate(3020, 12, 12));
sub.setModified(new Date());
sub.setId(Util.generateDbUUID());
subscriptions.add(sub);
poolManager.getRefresher(subAdapter, ownerAdapter).add(o).run();
// This test simulates https://bugzilla.redhat.com/show_bug.cgi?id=676870
// where entitling first to the modifier then to the modifiee causes the modifier's
// entitlement cert to get regenerated, but since it's all in the same http call,
// this ends up causing a hibernate failure (the old cert is asked to be deleted,
// but it hasn't been saved yet). Since getting the pool ordering right is tricky
// inside an entitleByProducts call, we do it in two singular calls here.
AutobindData data = AutobindData.create(parentSystem, o).on(new Date()).forProducts(new String[] { "modifier" });
poolManager.entitleByProducts(data);
try {
data = AutobindData.create(parentSystem, o).on(new Date()).forProducts(new String[] { PRODUCT_VIRT_HOST });
poolManager.entitleByProducts(data);
} catch (EntityNotFoundException e) {
throw e;
// fail("Hibernate failed to properly save entitlement certs!");
}
// If we get here, no exception was raised, so we're happy!
}
Aggregations