Search in sources :

Example 51 with Pool

use of org.candlepin.model.Pool in project candlepin by candlepin.

the class EntitlementCertificateGeneratorTest method testNonLazyRegenerate.

@Test
public void testNonLazyRegenerate() throws Exception {
    Owner owner = TestUtil.createOwner("test-owner", "Test Owner");
    Product product = TestUtil.createProduct();
    Pool pool = TestUtil.createPool(owner, product);
    pool.setSourceSubscription(new SourceSubscription("source-sub-id", "master"));
    Map<String, EntitlementCertificate> entCerts = new HashMap<>();
    entCerts.put(pool.getId(), new EntitlementCertificate());
    when(this.mockEntCertAdapter.generateEntitlementCerts(any(Consumer.class), anyMapOf(String.class, PoolQuantity.class), anyMapOf(String.class, Entitlement.class), anyMapOf(String.class, Product.class), eq(true))).thenReturn(entCerts);
    Consumer consumer = TestUtil.createConsumer(owner);
    Entitlement entitlement = new Entitlement(pool, consumer, owner, 1);
    entitlement.setDirty(true);
    this.ecGenerator.regenerateCertificatesOf(entitlement, false);
    assertFalse(entitlement.isDirty());
    verify(this.mockEntCertAdapter).generateEntitlementCerts(eq(consumer), this.poolQuantityMapCaptor.capture(), this.entMapCaptor.capture(), this.productMapCaptor.capture(), eq(true));
    assertEquals(entitlement, this.entMapCaptor.getValue().get(pool.getId()));
    assertEquals(product, this.productMapCaptor.getValue().get(pool.getId()));
    verify(this.mockEventSink, times(1)).queueEvent(any(Event.class));
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Owner(org.candlepin.model.Owner) SourceSubscription(org.candlepin.model.SourceSubscription) EntitlementCertificate(org.candlepin.model.EntitlementCertificate) Consumer(org.candlepin.model.Consumer) HashMap(java.util.HashMap) Product(org.candlepin.model.Product) Event(org.candlepin.audit.Event) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 52 with Pool

use of org.candlepin.model.Pool in project candlepin by candlepin.

the class PoolManagerTest method testCleanup.

@Test
public void testCleanup() throws Exception {
    Pool p = createPoolWithEntitlements();
    when(mockPoolCurator.lockAndLoad(any(Pool.class))).thenReturn(p);
    when(mockPoolCurator.entitlementsIn(p)).thenReturn(new ArrayList<>(p.getEntitlements()));
    PreUnbindHelper preHelper = mock(PreUnbindHelper.class);
    ValidationResult result = new ValidationResult();
    when(preHelper.getResult()).thenReturn(result);
    manager.deletePool(p);
    // And the pool should be deleted:
    verify(mockPoolCurator).delete(p);
    // Check that appropriate events were sent out:
    verify(eventFactory).poolDeleted(p);
    verify(mockEventSink, times(1)).queueEvent((Event) any());
}
Also used : PreUnbindHelper(org.candlepin.policy.js.entitlement.PreUnbindHelper) Pool(org.candlepin.model.Pool) ValidationResult(org.candlepin.policy.ValidationResult) Test(org.junit.Test)

Example 53 with Pool

use of org.candlepin.model.Pool in project candlepin by candlepin.

the class PoolManagerTest method createPoolsForExistingSubscriptionsMasterExist.

@Test
public void createPoolsForExistingSubscriptionsMasterExist() {
    Owner owner = this.getOwner();
    PoolRules pRules = new PoolRules(manager, mockConfig, entitlementCurator, mockOwnerProductCurator, mockProductCurator);
    List<Subscription> subscriptions = new ArrayList<>();
    Product prod = TestUtil.createProduct();
    Set<Product> products = new HashSet<>();
    products.add(prod);
    // productCache.addProducts(products);
    prod.setAttribute(Product.Attributes.VIRT_LIMIT, "4");
    Subscription s = TestUtil.createSubscription(owner, prod);
    subscriptions.add(s);
    this.mockProducts(owner, prod);
    when(mockSubAdapter.getSubscriptions(any(Owner.class))).thenReturn(subscriptions);
    when(mockConfig.getBoolean(ConfigProperties.STANDALONE)).thenReturn(false);
    List<Pool> existingPools = new LinkedList<>();
    Pool p = TestUtil.createPool(prod);
    p.setSourceSubscription(new SourceSubscription(s.getId(), "master"));
    existingPools.add(p);
    List<Pool> newPools = pRules.createAndEnrichPools(s, existingPools);
    assertEquals(newPools.size(), 1);
    assertEquals(newPools.get(0).getSourceSubscription().getSubscriptionSubKey(), "derived");
}
Also used : Owner(org.candlepin.model.Owner) SourceSubscription(org.candlepin.model.SourceSubscription) PoolRules(org.candlepin.policy.js.pool.PoolRules) ArrayList(java.util.ArrayList) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 54 with Pool

use of org.candlepin.model.Pool in project candlepin by candlepin.

the class PoolManagerTest method testRevokeAllEntitlements.

@Test
public void testRevokeAllEntitlements() {
    Consumer c = TestUtil.createConsumer(owner);
    Entitlement e1 = new Entitlement(pool, c, owner, 1);
    Entitlement e2 = new Entitlement(pool, c, owner, 1);
    List<Entitlement> entitlementList = new ArrayList<>();
    entitlementList.add(e1);
    entitlementList.add(e2);
    when(entitlementCurator.listByConsumer(eq(c))).thenReturn(entitlementList);
    when(mockPoolCurator.lockAndLoad(any(Pool.class))).thenReturn(pool);
    PreUnbindHelper preHelper = mock(PreUnbindHelper.class);
    ValidationResult result = new ValidationResult();
    when(preHelper.getResult()).thenReturn(result);
    int total = manager.revokeAllEntitlements(c);
    assertEquals(2, total);
    verify(entitlementCurator, times(1)).markDependentEntitlementsDirty(any(List.class));
// TODO assert batch revokes have been called
}
Also used : PreUnbindHelper(org.candlepin.policy.js.entitlement.PreUnbindHelper) Consumer(org.candlepin.model.Consumer) ArrayList(java.util.ArrayList) Pool(org.candlepin.model.Pool) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Matchers.anyList(org.mockito.Matchers.anyList) Entitlement(org.candlepin.model.Entitlement) ValidationResult(org.candlepin.policy.ValidationResult) Test(org.junit.Test)

Example 55 with Pool

use of org.candlepin.model.Pool in project candlepin by candlepin.

the class PoolManagerTest method refreshPoolsCreatingPoolsForExistingSubscriptions.

@Test
public void refreshPoolsCreatingPoolsForExistingSubscriptions() {
    List<Subscription> subscriptions = new ArrayList<>();
    List<Pool> pools = new ArrayList<>();
    Owner owner = this.getOwner();
    Product product = TestUtil.createProduct();
    product.setLocked(true);
    Subscription s = TestUtil.createSubscription(owner, product);
    subscriptions.add(s);
    mockSubsList(subscriptions);
    mockPoolsList(pools);
    List<Pool> newPools = new LinkedList<>();
    Pool p = TestUtil.createPool(product);
    p.setSourceSubscription(new SourceSubscription(s.getId(), "master"));
    newPools.add(p);
    ArgumentCaptor<Pool> argPool = ArgumentCaptor.forClass(Pool.class);
    when(poolRulesMock.createAndEnrichPools(argPool.capture(), any(List.class))).thenReturn(newPools);
    when(mockOwnerCurator.lookupByKey(owner.getKey())).thenReturn(owner);
    this.mockProducts(owner, product);
    this.mockProductImport(owner, product);
    this.mockContentImport(owner, new Content[] {});
    CandlepinQuery<Pool> cqmock = mock(CandlepinQuery.class);
    when(cqmock.list()).thenReturn(pools);
    when(cqmock.iterator()).thenReturn(pools.iterator());
    when(mockPoolCurator.listByOwnerAndType(eq(owner), any(PoolType.class))).thenReturn(cqmock);
    cqmock = mock(CandlepinQuery.class);
    when(cqmock.list()).thenReturn(Collections.<Pool>emptyList());
    when(mockPoolCurator.getPoolsBySubscriptionIds(anyList())).thenReturn(cqmock);
    cqmock = mock(CandlepinQuery.class);
    when(cqmock.list()).thenReturn(Collections.<Pool>emptyList());
    when(mockPoolCurator.getPoolsBySubscriptionId(anyString())).thenReturn(cqmock);
    this.manager.getRefresher(mockSubAdapter, mockOwnerAdapter).add(owner).run();
    TestUtil.assertPoolsAreEqual(TestUtil.copyFromSub(s), argPool.getValue());
    verify(this.mockPoolCurator, times(1)).create(any(Pool.class));
}
Also used : Owner(org.candlepin.model.Owner) PoolType(org.candlepin.model.Pool.PoolType) ArrayList(java.util.ArrayList) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) CandlepinQuery(org.candlepin.model.CandlepinQuery) LinkedList(java.util.LinkedList) SourceSubscription(org.candlepin.model.SourceSubscription) Pool(org.candlepin.model.Pool) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Matchers.anyList(org.mockito.Matchers.anyList) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) Test(org.junit.Test)

Aggregations

Pool (org.candlepin.model.Pool)508 Test (org.junit.Test)358 Product (org.candlepin.model.Product)217 Entitlement (org.candlepin.model.Entitlement)125 Consumer (org.candlepin.model.Consumer)115 ValidationResult (org.candlepin.policy.ValidationResult)111 ArrayList (java.util.ArrayList)100 LinkedList (java.util.LinkedList)100 Owner (org.candlepin.model.Owner)80 HashSet (java.util.HashSet)76 HashMap (java.util.HashMap)67 PoolQuantity (org.candlepin.model.PoolQuantity)66 Date (java.util.Date)65 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)62 Subscription (org.candlepin.model.dto.Subscription)60 List (java.util.List)48 ConsumerType (org.candlepin.model.ConsumerType)48 SourceSubscription (org.candlepin.model.SourceSubscription)47 ActivationKey (org.candlepin.model.activationkeys.ActivationKey)38 Matchers.anyString (org.mockito.Matchers.anyString)30