Search in sources :

Example 51 with Entitlement

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());
}
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 52 with Entitlement

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()));
}
Also used : Owner(org.candlepin.model.Owner) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Date(java.util.Date) LinkedList(java.util.LinkedList) Consumer(org.candlepin.model.Consumer) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 53 with Entitlement

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()));
}
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 54 with Entitlement

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));
}
Also used : JobDetail(org.quartz.JobDetail) ArrayList(java.util.ArrayList) JobExecutionContext(org.quartz.JobExecutionContext) Collection(java.util.Collection) Entitlement(org.candlepin.model.Entitlement) Date(java.util.Date) Test(org.junit.Test)

Example 55 with Entitlement

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

Aggregations

Entitlement (org.candlepin.model.Entitlement)301 Test (org.junit.Test)201 Consumer (org.candlepin.model.Consumer)164 Pool (org.candlepin.model.Pool)125 LinkedList (java.util.LinkedList)84 Product (org.candlepin.model.Product)68 Date (java.util.Date)62 ArrayList (java.util.ArrayList)61 HashSet (java.util.HashSet)59 HashMap (java.util.HashMap)55 Owner (org.candlepin.model.Owner)44 PoolQuantity (org.candlepin.model.PoolQuantity)35 ConsumerType (org.candlepin.model.ConsumerType)34 List (java.util.List)30 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)24 Matchers.anyString (org.mockito.Matchers.anyString)17 Set (java.util.Set)16 Subscription (org.candlepin.model.dto.Subscription)16 ApiOperation (io.swagger.annotations.ApiOperation)15 ApiResponses (io.swagger.annotations.ApiResponses)15