use of org.candlepin.model.Pool in project candlepin by candlepin.
the class PoolManagerTest method testEntitleWithADate.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testEntitleWithADate() throws Exception {
Product product = TestUtil.createProduct();
List<Pool> pools = new ArrayList<>();
Pool pool1 = TestUtil.createPool(product);
pools.add(pool1);
Pool pool2 = TestUtil.createPool(product);
pools.add(pool2);
Date now = new Date();
ValidationResult result = mock(ValidationResult.class);
Page page = mock(Page.class);
when(page.getPageData()).thenReturn(pools);
when(mockPoolCurator.listAvailableEntitlementPools(any(Consumer.class), any(String.class), any(String.class), any(String.class), eq(now), any(PoolFilterBuilder.class), any(PageRequest.class), anyBoolean(), anyBoolean(), anyBoolean(), any(Date.class))).thenReturn(page);
CandlepinQuery mockQuery = mock(CandlepinQuery.class);
when(mockPoolCurator.listAllByIds(any(List.class))).thenReturn(mockQuery);
when(mockQuery.iterator()).thenReturn(Arrays.asList(pool1).listIterator());
when(enforcerMock.preEntitlement(any(Consumer.class), any(Pool.class), anyInt(), any(CallerType.class))).thenReturn(result);
when(result.isSuccessful()).thenReturn(true);
List<PoolQuantity> bestPools = new ArrayList<>();
bestPools.add(new PoolQuantity(pool1, 1));
when(autobindRules.selectBestPools(any(Consumer.class), any(String[].class), any(List.class), any(ComplianceStatus.class), any(String.class), any(Set.class), eq(false))).thenReturn(bestPools);
ConsumerType ctype = this.mockConsumerType(TestUtil.createConsumerType());
Consumer consumer = TestUtil.createConsumer(ctype, owner);
AutobindData data = AutobindData.create(consumer, owner).forProducts(new String[] { product.getUuid() }).on(now);
doNothing().when(mockPoolCurator).flush();
doNothing().when(mockPoolCurator).clear();
List<Entitlement> e = manager.entitleByProducts(data);
assertNotNull(e);
assertEquals(e.size(), 1);
}
use of org.candlepin.model.Pool in project candlepin by candlepin.
the class PoolManagerTest method derivedProvidedProductsCopiedOntoMasterPoolWhenCreatingNewPool.
@Test
public void derivedProvidedProductsCopiedOntoMasterPoolWhenCreatingNewPool() {
Product product = TestUtil.createProduct();
Product subProduct = TestUtil.createProduct();
Product subProvidedProduct = TestUtil.createProduct();
Subscription sub = TestUtil.createSubscription(owner, product);
sub.setDerivedProduct(subProduct.toDTO());
Set<ProductData> subProvided = new HashSet<>();
subProvided.add(subProvidedProduct.toDTO());
sub.setDerivedProvidedProducts(subProvided);
this.mockProducts(owner, product, subProduct, subProvidedProduct);
PoolRules pRules = new PoolRules(manager, mockConfig, entitlementCurator, mockOwnerProductCurator, mockProductCurator);
List<Pool> pools = pRules.createAndEnrichPools(sub);
assertEquals(1, pools.size());
Pool resultPool = pools.get(0);
assertEquals(1, resultPool.getDerivedProvidedProducts().size());
}
use of org.candlepin.model.Pool in project candlepin by candlepin.
the class PoolManagerTest method testCleanupExpiredPoolsReadOnlySubscriptions.
@Test
public void testCleanupExpiredPoolsReadOnlySubscriptions() {
Pool p = createPoolWithEntitlements();
p.setSubscriptionId("subid");
List<Pool> pools = Arrays.asList(p);
when(mockPoolCurator.lockAndLoadByIds(anyCollection())).thenReturn(pools);
when(mockPoolCurator.listExpiredPools(anyInt())).thenReturn(pools);
when(mockPoolCurator.entitlementsIn(p)).thenReturn(new ArrayList<>(p.getEntitlements()));
Subscription sub = new Subscription();
sub.setId(p.getSubscriptionId());
when(mockSubAdapter.getSubscription(any(String.class))).thenReturn(sub);
when(mockSubAdapter.isReadOnly()).thenReturn(true);
PreUnbindHelper preHelper = mock(PreUnbindHelper.class);
ValidationResult result = new ValidationResult();
when(preHelper.getResult()).thenReturn(result);
manager.cleanupExpiredPools();
// And the pool should be deleted:
verify(mockPoolCurator).batchDelete(eq(pools), anySetOf(String.class));
verify(mockSubAdapter, never()).getSubscription(any(String.class));
verify(mockSubAdapter, never()).deleteSubscription(any(Subscription.class));
}
use of org.candlepin.model.Pool in project candlepin by candlepin.
the class PoolManagerTest method mockPoolsList.
private void mockPoolsList(List<Pool> pools) {
List<Pool> floating = new LinkedList<>();
subToPools = new HashMap<>();
for (Pool pool : pools) {
String subid = pool.getSubscriptionId();
if (subid != null) {
if (!subToPools.containsKey(subid)) {
subToPools.put(subid, new LinkedList<>());
}
subToPools.get(subid).add(pool);
} else {
floating.add(pool);
}
}
for (String subid : subToPools.keySet()) {
CandlepinQuery cqmock = mock(CandlepinQuery.class);
when(cqmock.list()).thenReturn(subToPools.get(subid));
when(mockPoolCurator.getPoolsBySubscriptionId(eq(subid))).thenReturn(cqmock);
}
when(mockPoolCurator.getOwnersFloatingPools(any(Owner.class))).thenReturn(floating);
when(mockPoolCurator.getPoolsFromBadSubs(any(Owner.class), any(Collection.class))).thenAnswer(new Answer<List<Pool>>() {
@SuppressWarnings("unchecked")
@Override
public List<Pool> answer(InvocationOnMock iom) throws Throwable {
Collection<String> subIds = (Collection<String>) iom.getArguments()[1];
List<Pool> results = new LinkedList<>();
for (Entry<String, List<Pool>> entry : PoolManagerTest.subToPools.entrySet()) {
for (Pool pool : entry.getValue()) {
if (!subIds.contains(pool.getSubscriptionId())) {
results.add(pool);
}
}
}
return results;
}
});
}
use of org.candlepin.model.Pool in project candlepin by candlepin.
the class PoolManagerTest method subProductAttributesCopiedOntoPoolWhenCreatingNewPool.
@Test
public void subProductAttributesCopiedOntoPoolWhenCreatingNewPool() {
Product product = TestUtil.createProduct();
Product subProduct = TestUtil.createProduct();
Subscription sub = TestUtil.createSubscription(owner, product);
sub.setDerivedProduct(subProduct.toDTO());
String testAttributeKey = "multi-entitlement";
String expectedAttributeValue = "yes";
subProduct.setAttribute(testAttributeKey, expectedAttributeValue);
this.mockProducts(owner, product, subProduct);
PoolRules pRules = new PoolRules(manager, mockConfig, entitlementCurator, mockOwnerProductCurator, mockProductCurator);
List<Pool> pools = pRules.createAndEnrichPools(sub);
assertEquals(1, pools.size());
Pool resultPool = pools.get(0);
assertNotNull(resultPool.getDerivedProduct());
assertTrue(resultPool.getDerivedProduct().hasAttribute(testAttributeKey));
assertEquals(expectedAttributeValue, resultPool.getDerivedProduct().getAttributeValue(testAttributeKey));
}
Aggregations