Search in sources :

Example 11 with AutobindData

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());
}
Also used : Pool(org.candlepin.model.Pool) AutobindData(org.candlepin.resource.dto.AutobindData) Entitlement(org.candlepin.model.Entitlement) Date(java.util.Date) Test(org.junit.Test)

Example 12 with AutobindData

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();
}
Also used : AutobindData(org.candlepin.resource.dto.AutobindData) Date(java.util.Date) Test(org.junit.Test)

Example 13 with AutobindData

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());
}
Also used : CertificateSerial(org.candlepin.model.CertificateSerial) AutobindData(org.candlepin.resource.dto.AutobindData) Entitlement(org.candlepin.model.Entitlement) Date(java.util.Date) Test(org.junit.Test)

Example 14 with AutobindData

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()));
}
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 15 with AutobindData

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!
}
Also used : Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) EntityNotFoundException(javax.persistence.EntityNotFoundException) LinkedList(java.util.LinkedList) Date(java.util.Date) ImportSubscriptionServiceAdapter(org.candlepin.service.impl.ImportSubscriptionServiceAdapter) Content(org.candlepin.model.Content) AutobindData(org.candlepin.resource.dto.AutobindData) Subscription(org.candlepin.model.dto.Subscription) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

AutobindData (org.candlepin.resource.dto.AutobindData)27 Test (org.junit.Test)22 Date (java.util.Date)18 Consumer (org.candlepin.model.Consumer)17 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)16 Product (org.candlepin.model.Product)15 ArrayList (java.util.ArrayList)13 Pool (org.candlepin.model.Pool)13 Owner (org.candlepin.model.Owner)12 HashSet (java.util.HashSet)11 Entitlement (org.candlepin.model.Entitlement)10 List (java.util.List)8 ProductData (org.candlepin.model.dto.ProductData)5 LinkedList (java.util.LinkedList)4 CandlepinQuery (org.candlepin.model.CandlepinQuery)4 ValidationResult (org.candlepin.policy.ValidationResult)4 Matchers.anyString (org.mockito.Matchers.anyString)4 Set (java.util.Set)3 Page (org.candlepin.common.paging.Page)3 PageRequest (org.candlepin.common.paging.PageRequest)3