Search in sources :

Example 1 with PoolRules

use of org.candlepin.policy.js.pool.PoolRules 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 2 with PoolRules

use of org.candlepin.policy.js.pool.PoolRules 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());
}
Also used : ProductData(org.candlepin.model.dto.ProductData) PoolRules(org.candlepin.policy.js.pool.PoolRules) 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) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with PoolRules

use of org.candlepin.policy.js.pool.PoolRules 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));
}
Also used : PoolRules(org.candlepin.policy.js.pool.PoolRules) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Matchers.anyString(org.mockito.Matchers.anyString) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) Test(org.junit.Test)

Example 4 with PoolRules

use of org.candlepin.policy.js.pool.PoolRules 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());
}
Also used : PoolRules(org.candlepin.policy.js.pool.PoolRules) 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) Test(org.junit.Test)

Example 5 with PoolRules

use of org.candlepin.policy.js.pool.PoolRules in project candlepin by candlepin.

the class PoolManagerTest method productAttributesCopiedOntoPoolWhenCreatingNewPool.

@Test
public void productAttributesCopiedOntoPoolWhenCreatingNewPool() {
    // Why is this test in pool manager? It looks like a pool rules test.
    PoolRules pRules = new PoolRules(manager, mockConfig, entitlementCurator, mockOwnerProductCurator, mockProductCurator);
    Product product = TestUtil.createProduct();
    product.setLocked(true);
    String testAttributeKey = "multi-entitlement";
    String expectedAttributeValue = "yes";
    product.setAttribute(testAttributeKey, expectedAttributeValue);
    Subscription sub = TestUtil.createSubscription(owner, product);
    this.mockProducts(owner, product);
    List<Pool> pools = pRules.createAndEnrichPools(sub);
    assertEquals(1, pools.size());
    Pool resultPool = pools.get(0);
    assertNotNull(resultPool.getProduct());
    assertTrue(resultPool.getProduct().hasAttribute(testAttributeKey));
    assertEquals(expectedAttributeValue, resultPool.getProduct().getAttributeValue(testAttributeKey));
}
Also used : PoolRules(org.candlepin.policy.js.pool.PoolRules) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Matchers.anyString(org.mockito.Matchers.anyString) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) Test(org.junit.Test)

Aggregations

PoolRules (org.candlepin.policy.js.pool.PoolRules)15 Pool (org.candlepin.model.Pool)12 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)11 Product (org.candlepin.model.Product)11 Test (org.junit.Test)11 SourceSubscription (org.candlepin.model.SourceSubscription)10 Subscription (org.candlepin.model.dto.Subscription)8 Owner (org.candlepin.model.Owner)7 LinkedList (java.util.LinkedList)6 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 Rules (org.candlepin.model.Rules)4 Before (org.junit.Before)4 Date (java.util.Date)3 Consumer (org.candlepin.model.Consumer)2 ConsumerType (org.candlepin.model.ConsumerType)2 Matchers.anyString (org.mockito.Matchers.anyString)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1