use of org.candlepin.model.Product 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.Product 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.Product in project candlepin by candlepin.
the class PoolManagerTest method mockProducts.
private void mockProducts(Owner owner, Product... products) {
Map<String, Product> productMap = new HashMap<>();
for (Product product : products) {
productMap.put(product.getId(), product);
}
this.mockProducts(owner, productMap);
}
use of org.candlepin.model.Product 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));
}
use of org.candlepin.model.Product in project candlepin by candlepin.
the class PoolManagerTest method subProductIdCopiedOntoPoolWhenCreatingNewPool.
@Test
public void subProductIdCopiedOntoPoolWhenCreatingNewPool() {
Product product = TestUtil.createProduct();
Product subProduct = TestUtil.createProduct();
Subscription sub = TestUtil.createSubscription(owner, product);
sub.setDerivedProduct(subProduct.toDTO());
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);
assertEquals(subProduct, resultPool.getDerivedProduct());
}
Aggregations