Search in sources :

Example 1 with CandlepinPoolManager

use of org.candlepin.controller.CandlepinPoolManager in project candlepin by candlepin.

the class OwnerResourceTest method testCreateUeberCertificateFromScratch.

@Test
public void testCreateUeberCertificateFromScratch() {
    Principal principal = setupPrincipal(owner, Access.ALL);
    Owner owner = TestUtil.createOwner();
    UeberCertificate entCert = mock(UeberCertificate.class);
    OwnerCurator oc = mock(OwnerCurator.class);
    ProductCurator pc = mock(ProductCurator.class);
    ConsumerCurator cc = mock(ConsumerCurator.class);
    EntitlementCurator ec = mock(EntitlementCurator.class);
    CandlepinPoolManager cpm = mock(CandlepinPoolManager.class);
    EntitlementCertificateCurator ecc = mock(EntitlementCertificateCurator.class);
    UeberCertificateCurator uc = mock(UeberCertificateCurator.class);
    UeberCertificateGenerator ucg = mock(UeberCertificateGenerator.class);
    OwnerResource resource = new OwnerResource(oc, pc, null, cc, i18n, null, null, null, null, null, cpm, null, null, null, null, null, ecc, ec, uc, ucg, null, null, null, null, null, null, null, null, null, this.modelTranslator);
    when(oc.lookupByKey(eq("admin"))).thenReturn(owner);
    when(ucg.generate(eq(owner.getKey()), eq(principal))).thenReturn(entCert);
    UeberCertificate result = resource.createUeberCertificate(principal, owner.getKey());
    assertEquals(entCert, result);
}
Also used : EntitlementCurator(org.candlepin.model.EntitlementCurator) OwnerCurator(org.candlepin.model.OwnerCurator) Owner(org.candlepin.model.Owner) UeberCertificate(org.candlepin.model.UeberCertificate) ProductCurator(org.candlepin.model.ProductCurator) UeberCertificateCurator(org.candlepin.model.UeberCertificateCurator) EntitlementCertificateCurator(org.candlepin.model.EntitlementCertificateCurator) UeberCertificateGenerator(org.candlepin.model.UeberCertificateGenerator) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) ConsumerCurator(org.candlepin.model.ConsumerCurator) CandlepinPoolManager(org.candlepin.controller.CandlepinPoolManager) Test(org.junit.Test)

Example 2 with CandlepinPoolManager

use of org.candlepin.controller.CandlepinPoolManager in project candlepin by candlepin.

the class PoolCuratorEntitlementRulesTest method concurrentCreationOfEntitlementsShouldWorkIfUnderMaxMemberLimit.

@Test
public void concurrentCreationOfEntitlementsShouldWorkIfUnderMaxMemberLimit() throws Exception {
    Long numAvailEntitlements = 2L;
    Product newProduct = TestUtil.createProduct();
    newProduct.setAttribute(Pool.Attributes.MULTI_ENTITLEMENT, "yes");
    newProduct = this.createProduct(newProduct, owner);
    Pool consumerPool = createPool(owner, newProduct, numAvailEntitlements, TestUtil.createDate(2009, 11, 30), TestUtil.createDate(2050, 11, 30));
    consumerPool = poolCurator.create(consumerPool);
    CandlepinPoolManager anotherEntitler = injector.getInstance(CandlepinPoolManager.class);
    Map<String, Integer> poolQuantities = new HashMap<>();
    poolQuantities.put(consumerPool.getId(), 1);
    anotherEntitler.entitleByPools(consumer, poolQuantities);
    poolQuantities.put(consumerPool.getId(), 1);
    anotherEntitler.entitleByPools(consumer, poolQuantities);
    assertFalse(poolCurator.find(consumerPool.getId()).entitlementsAvailable(1));
}
Also used : HashMap(java.util.HashMap) CandlepinPoolManager(org.candlepin.controller.CandlepinPoolManager) Test(org.junit.Test)

Example 3 with CandlepinPoolManager

use of org.candlepin.controller.CandlepinPoolManager in project candlepin by candlepin.

the class PoolCuratorEntitlementRulesTest method concurrentCreationOfEntitlementsShouldFailIfOverMaxMemberLimit.

@Test(expected = EntitlementRefusedException.class)
public void concurrentCreationOfEntitlementsShouldFailIfOverMaxMemberLimit() throws Exception {
    Long numAvailEntitlements = 1L;
    Product newProduct = this.createProduct(owner);
    Pool consumerPool = createPool(owner, newProduct, numAvailEntitlements, TestUtil.createDate(2009, 11, 30), TestUtil.createDate(2050, 11, 30));
    poolCurator.create(consumerPool);
    CandlepinPoolManager anotherEntitler = injector.getInstance(CandlepinPoolManager.class);
    Map<String, Integer> poolQuantities = new HashMap<>();
    poolQuantities.put(consumerPool.getId(), 1);
    List<Entitlement> e1 = poolManager.entitleByPools(consumer, poolQuantities);
    assertEquals(1, e1.size());
    poolQuantities.put(consumerPool.getId(), 1);
    anotherEntitler.entitleByPools(consumer, poolQuantities);
}
Also used : HashMap(java.util.HashMap) CandlepinPoolManager(org.candlepin.controller.CandlepinPoolManager) Test(org.junit.Test)

Example 4 with CandlepinPoolManager

use of org.candlepin.controller.CandlepinPoolManager in project candlepin by candlepin.

the class ConsumerResourceTest method testExceptionFromCertGen.

@Test(expected = RuntimeException.class)
public void testExceptionFromCertGen() throws Exception {
    Consumer consumer = createConsumer(createOwner());
    Entitlement e = Mockito.mock(Entitlement.class);
    Pool p = Mockito.mock(Pool.class);
    Subscription s = Mockito.mock(Subscription.class);
    when(e.getPool()).thenReturn(p);
    when(p.getSubscriptionId()).thenReturn("4444");
    when(mockEntitlementCurator.find(eq("9999"))).thenReturn(e);
    when(mockSubscriptionServiceAdapter.getSubscription(eq("4444"))).thenReturn(s);
    when(mockEntitlementCertServiceAdapter.generateEntitlementCert(any(Entitlement.class), any(Product.class))).thenThrow(new IOException());
    CandlepinPoolManager poolManager = new CandlepinPoolManager(null, null, null, this.config, null, null, mockEntitlementCurator, mockConsumerCurator, mockConsumerTypeCurator, null, null, null, null, mockActivationKeyRules, null, null, null, null, null, null, null, null, null, null);
    ConsumerResource consumerResource = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, mockEntitlementCurator, null, mockEntitlementCertServiceAdapter, null, null, null, null, null, null, poolManager, null, null, null, null, null, null, null, null, this.config, null, null, null, consumerBindUtil, null, null, this.factValidator, null, consumerEnricher, migrationProvider, translator);
    consumerResource.regenerateEntitlementCertificates(consumer.getUuid(), "9999", false);
}
Also used : Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) IOException(java.io.IOException) Entitlement(org.candlepin.model.Entitlement) Subscription(org.candlepin.model.dto.Subscription) CandlepinPoolManager(org.candlepin.controller.CandlepinPoolManager) Test(org.junit.Test)

Example 5 with CandlepinPoolManager

use of org.candlepin.controller.CandlepinPoolManager in project candlepin by candlepin.

the class ConsumerResourceTest method testRegenerateEntitlementCertificateWithValidConsumer.

/**
 * Test just verifies that entitler is called only once and it doesn't need
 * any other object to execute.
 */
@Test
public void testRegenerateEntitlementCertificateWithValidConsumer() {
    Consumer consumer = createConsumer(createOwner());
    CandlepinPoolManager mgr = mock(CandlepinPoolManager.class);
    ConsumerResource cr = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, mockSubscriptionServiceAdapter, this.mockOwnerServiceAdapter, null, null, null, null, null, null, null, null, null, mgr, null, null, null, null, null, null, null, null, this.config, null, null, null, consumerBindUtil, null, null, this.factValidator, null, consumerEnricher, migrationProvider, translator);
    cr.regenerateEntitlementCertificates(consumer.getUuid(), null, true);
    Mockito.verify(mgr, Mockito.times(1)).regenerateCertificatesOf(eq(consumer), eq(true));
}
Also used : Consumer(org.candlepin.model.Consumer) CandlepinPoolManager(org.candlepin.controller.CandlepinPoolManager) Test(org.junit.Test)

Aggregations

CandlepinPoolManager (org.candlepin.controller.CandlepinPoolManager)7 Test (org.junit.Test)7 Owner (org.candlepin.model.Owner)3 OwnerCurator (org.candlepin.model.OwnerCurator)3 HashMap (java.util.HashMap)2 ConsumerPrincipal (org.candlepin.auth.ConsumerPrincipal)2 Principal (org.candlepin.auth.Principal)2 UserPrincipal (org.candlepin.auth.UserPrincipal)2 Consumer (org.candlepin.model.Consumer)2 ConsumerCurator (org.candlepin.model.ConsumerCurator)2 EntitlementCertificateCurator (org.candlepin.model.EntitlementCertificateCurator)2 EntitlementCurator (org.candlepin.model.EntitlementCurator)2 ProductCurator (org.candlepin.model.ProductCurator)2 UeberCertificate (org.candlepin.model.UeberCertificate)2 UeberCertificateCurator (org.candlepin.model.UeberCertificateCurator)2 UeberCertificateGenerator (org.candlepin.model.UeberCertificateGenerator)2 IOException (java.io.IOException)1 CandlepinQuery (org.candlepin.model.CandlepinQuery)1 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)1 Entitlement (org.candlepin.model.Entitlement)1