Search in sources :

Example 11 with PoolRules

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

the class PoolManagerTest method brandingCopiedWhenCreatingPools.

@Test
public void brandingCopiedWhenCreatingPools() {
    Product product = TestUtil.createProduct();
    Subscription sub = TestUtil.createSubscription(owner, product);
    Branding b1 = new Branding("8000", "OS", "Branded Awesome OS");
    Branding b2 = new Branding("8001", "OS", "Branded Awesome OS 2");
    sub.getBranding().add(b1);
    sub.getBranding().add(b2);
    this.mockProducts(owner, product);
    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(2, resultPool.getBranding().size());
    assertTrue(resultPool.getBranding().contains(b1));
    assertTrue(resultPool.getBranding().contains(b2));
}
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) Branding(org.candlepin.model.Branding) Test(org.junit.Test)

Example 12 with PoolRules

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

the class PoolManagerTest method createPoolsForExistingSubscriptionsBonusExist.

@Test
public void createPoolsForExistingSubscriptionsBonusExist() {
    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(), "derived"));
    existingPools.add(p);
    pRules.createAndEnrichPools(s, existingPools);
    List<Pool> newPools = pRules.createAndEnrichPools(s, existingPools);
    assertEquals(newPools.size(), 1);
    assertEquals(newPools.get(0).getSourceSubscription().getSubscriptionSubKey(), "master");
}
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 13 with PoolRules

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

the class PoolManagerTest method createPoolsForPoolMasterExist.

@Test
public void createPoolsForPoolMasterExist() {
    Owner owner = this.getOwner();
    Product prod = TestUtil.createProduct();
    prod.setAttribute(Product.Attributes.VIRT_LIMIT, "4");
    PoolRules pRules = new PoolRules(manager, mockConfig, entitlementCurator, mockOwnerProductCurator, mockProductCurator);
    List<Pool> existingPools = new LinkedList<>();
    Pool p = TestUtil.createPool(prod);
    p.setSourceSubscription(new SourceSubscription(TestUtil.randomString(), "master"));
    existingPools.add(p);
    List<Pool> newPools = pRules.createAndEnrichPools(p, existingPools);
    assertEquals(1, newPools.size());
    assertEquals("derived", newPools.get(0).getSourceSubscription().getSubscriptionSubKey());
}
Also used : Owner(org.candlepin.model.Owner) SourceSubscription(org.candlepin.model.SourceSubscription) PoolRules(org.candlepin.policy.js.pool.PoolRules) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 14 with PoolRules

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

the class PoolRulesInstanceTest method setUp.

@Before
public void setUp() {
    InputStream is = this.getClass().getResourceAsStream(RulesCurator.DEFAULT_RULES_FILE);
    Rules rules = new Rules(Util.readFile(is));
    when(rulesCuratorMock.getUpdated()).thenReturn(new Date());
    when(rulesCuratorMock.getRules()).thenReturn(rules);
    when(configMock.getInt(eq(ConfigProperties.PRODUCT_CACHE_MAX))).thenReturn(100);
    poolRules = new PoolRules(poolManagerMock, configMock, entCurMock, ownerProdCuratorMock, productCurator);
}
Also used : PoolRules(org.candlepin.policy.js.pool.PoolRules) InputStream(java.io.InputStream) PoolRules(org.candlepin.policy.js.pool.PoolRules) Rules(org.candlepin.model.Rules) Date(java.util.Date) Before(org.junit.Before)

Example 15 with PoolRules

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

the class EntitlementRulesTestFixture method createEnforcer.

@Before
public void createEnforcer() throws Exception {
    MockitoAnnotations.initMocks(this);
    when(config.getInt(eq(ConfigProperties.PRODUCT_CACHE_MAX))).thenReturn(100);
    InputStream is = this.getClass().getResourceAsStream(RulesCurator.DEFAULT_RULES_FILE);
    Rules rules = new Rules(Util.readFile(is));
    when(rulesCurator.getRules()).thenReturn(rules);
    when(rulesCurator.getUpdated()).thenReturn(TestDateUtil.date(2010, 1, 1));
    when(cacheProvider.get()).thenReturn(cache);
    JsRunner jsRules = new JsRunnerProvider(rulesCurator, cacheProvider).get();
    translator = new StandardTranslator(consumerTypeCurator, environmentCurator, ownerCurator);
    enforcer = new EntitlementRules(new DateSourceImpl(), jsRules, I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK), config, consumerCurator, consumerTypeCurator, productCurator, new RulesObjectMapper(new ProductCachedSerializationModule(productCurator)), ownerCurator, ownerProductCuratorMock, productShareCurator, productManager, eventSink, eventFactory, translator);
    owner = new Owner();
    consumerType = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.SYSTEM));
    consumer = new Consumer("test consumer", "test user", owner, consumerType);
    poolRules = new PoolRules(poolManagerMock, config, entCurMock, ownerProductCuratorMock, productCurator);
}
Also used : Owner(org.candlepin.model.Owner) PoolRules(org.candlepin.policy.js.pool.PoolRules) InputStream(java.io.InputStream) RulesObjectMapper(org.candlepin.policy.js.RulesObjectMapper) JsRunner(org.candlepin.policy.js.JsRunner) Rules(org.candlepin.model.Rules) PoolRules(org.candlepin.policy.js.pool.PoolRules) StandardTranslator(org.candlepin.dto.StandardTranslator) ProductCachedSerializationModule(org.candlepin.jackson.ProductCachedSerializationModule) Consumer(org.candlepin.model.Consumer) JsRunnerProvider(org.candlepin.policy.js.JsRunnerProvider) ConsumerType(org.candlepin.model.ConsumerType) DateSourceImpl(org.candlepin.util.DateSourceImpl) Before(org.junit.Before)

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