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