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));
}
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());
}
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");
}
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
}
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));
}
Aggregations