Search in sources :

Example 1 with JsRunnerProvider

use of org.candlepin.policy.js.JsRunnerProvider in project candlepin by candlepin.

the class InstalledProductStatusCalculatorTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    translator = new StandardTranslator(this.consumerTypeCurator, this.environmentCurator, this.ownerCurator);
    // Load the default production rules:
    InputStream is = this.getClass().getResourceAsStream(RulesCurator.DEFAULT_RULES_FILE);
    Rules rules = new Rules(Util.readFile(is));
    Locale locale = new Locale("en_US");
    when(rulesCuratorMock.getUpdated()).thenReturn(new Date());
    when(rulesCuratorMock.getRules()).thenReturn(rules);
    when(cacheProvider.get()).thenReturn(cache);
    this.provider = new JsRunnerProvider(rulesCuratorMock, cacheProvider);
    i18n = I18nFactory.getI18n(getClass(), "org.candlepin.i18n.Messages", locale, I18nFactory.FALLBACK);
    RulesObjectMapper objectMapper = new RulesObjectMapper(new ProductCachedSerializationModule(productCurator));
    this.complianceRules = new ComplianceRules(provider.get(), this.entCurator, new StatusReasonMessageGenerator(i18n), eventSink, this.consumerCurator, this.consumerTypeCurator, objectMapper, translator);
    this.consumerEnricher = new ConsumerEnricher(this.complianceRules, this.ownerProductCurator);
}
Also used : Locale(java.util.Locale) ProductCachedSerializationModule(org.candlepin.jackson.ProductCachedSerializationModule) InputStream(java.io.InputStream) JsRunnerProvider(org.candlepin.policy.js.JsRunnerProvider) RulesObjectMapper(org.candlepin.policy.js.RulesObjectMapper) StatusReasonMessageGenerator(org.candlepin.policy.js.compliance.StatusReasonMessageGenerator) ComplianceRules(org.candlepin.policy.js.compliance.ComplianceRules) StandardTranslator(org.candlepin.dto.StandardTranslator) Rules(org.candlepin.model.Rules) ComplianceRules(org.candlepin.policy.js.compliance.ComplianceRules) Date(java.util.Date) Before(org.junit.Before)

Example 2 with JsRunnerProvider

use of org.candlepin.policy.js.JsRunnerProvider in project candlepin by candlepin.

the class ActivationKeyRulesTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    Locale locale = new Locale("en_US");
    i18n = I18nFactory.getI18n(getClass(), "org.candlepin.i18n.Messages", locale, I18nFactory.FALLBACK);
    // Load the default production rules:
    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(cacheProvider.get()).thenReturn(cache);
    provider = new JsRunnerProvider(rulesCuratorMock, cacheProvider);
    ProductCurator productCurator = mock(ProductCurator.class);
    translator = new StandardTranslator(mockConsumerTypeCurator, environmentCurator, mockOwnerCurator);
    actKeyRules = new ActivationKeyRules(provider.get(), i18n, new RulesObjectMapper(new ProductCachedSerializationModule(productCurator)), translator);
}
Also used : Locale(java.util.Locale) ProductCachedSerializationModule(org.candlepin.jackson.ProductCachedSerializationModule) InputStream(java.io.InputStream) ProductCurator(org.candlepin.model.ProductCurator) JsRunnerProvider(org.candlepin.policy.js.JsRunnerProvider) RulesObjectMapper(org.candlepin.policy.js.RulesObjectMapper) Rules(org.candlepin.model.Rules) StandardTranslator(org.candlepin.dto.StandardTranslator) Date(java.util.Date) Before(org.junit.Before)

Example 3 with JsRunnerProvider

use of org.candlepin.policy.js.JsRunnerProvider in project candlepin by candlepin.

the class AutobindRulesTest 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, mockOwnerCurator);
    autobindRules = new AutobindRules(jsRules, mockProductCurator, consumerTypeCurator, mockOwnerCurator, new RulesObjectMapper(new ProductCachedSerializationModule(mockProductCurator)), translator);
    owner = new Owner();
    owner.setId(TestUtil.randomString());
    when(mockOwnerCurator.findOwnerById(eq(owner.getId()))).thenReturn(owner);
    ConsumerType ctype = new ConsumerType(ConsumerTypeEnum.SYSTEM);
    ctype.setId("test-ctype");
    consumer = new Consumer("test consumer", "test user", owner, ctype);
    when(consumerTypeCurator.find(eq(ctype.getId()))).thenReturn(ctype);
    when(consumerTypeCurator.lookupByLabel(eq(ctype.getLabel()))).thenReturn(ctype);
    when(consumerTypeCurator.getConsumerType(eq(consumer))).thenReturn(ctype);
    compliance = new ComplianceStatus();
    activeGuestAttrs = new HashMap<>();
    activeGuestAttrs.put("virtWhoType", "libvirt");
    activeGuestAttrs.put("active", "1");
}
Also used : Owner(org.candlepin.model.Owner) AutobindRules(org.candlepin.policy.js.autobind.AutobindRules) ComplianceStatus(org.candlepin.policy.js.compliance.ComplianceStatus) InputStream(java.io.InputStream) RulesObjectMapper(org.candlepin.policy.js.RulesObjectMapper) JsRunner(org.candlepin.policy.js.JsRunner) Rules(org.candlepin.model.Rules) AutobindRules(org.candlepin.policy.js.autobind.AutobindRules) 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) Before(org.junit.Before)

Example 4 with JsRunnerProvider

use of org.candlepin.policy.js.JsRunnerProvider in project candlepin by candlepin.

the class ContentOverrideValidatorTest method setupTest.

@Before
public void setupTest() {
    InputStream is = this.getClass().getResourceAsStream(RulesCurator.DEFAULT_RULES_FILE);
    rulesCuratorMock = mock(RulesCurator.class);
    config = mock(Configuration.class);
    cacheProvider = mock(Provider.class);
    cache = mock(JsRunnerRequestCache.class);
    Rules rules = new Rules(Util.readFile(is));
    when(rulesCuratorMock.getUpdated()).thenReturn(new Date());
    when(rulesCuratorMock.getRules()).thenReturn(rules);
    when(cacheProvider.get()).thenReturn(cache);
    provider = new JsRunnerProvider(rulesCuratorMock, cacheProvider);
    overrideRules = new OverrideRules(provider.get(), config, new RulesObjectMapper(new ProductCachedSerializationModule(mockProductCurator)));
    validator = new ContentOverrideValidator(i18n, overrideRules);
}
Also used : ProductCachedSerializationModule(org.candlepin.jackson.ProductCachedSerializationModule) RulesCurator(org.candlepin.model.RulesCurator) Configuration(org.candlepin.common.config.Configuration) InputStream(java.io.InputStream) JsRunnerProvider(org.candlepin.policy.js.JsRunnerProvider) RulesObjectMapper(org.candlepin.policy.js.RulesObjectMapper) OverrideRules(org.candlepin.policy.js.override.OverrideRules) Rules(org.candlepin.model.Rules) OverrideRules(org.candlepin.policy.js.override.OverrideRules) Date(java.util.Date) Provider(com.google.inject.Provider) JsRunnerProvider(org.candlepin.policy.js.JsRunnerProvider) JsRunnerRequestCache(org.candlepin.policy.js.JsRunnerRequestCache) Before(org.junit.Before)

Example 5 with JsRunnerProvider

use of org.candlepin.policy.js.JsRunnerProvider in project candlepin by candlepin.

the class QuantityRulesTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    // Load the default production rules:
    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(cacheProvider.get()).thenReturn(cache);
    provider = new JsRunnerProvider(rulesCuratorMock, cacheProvider);
    translator = new StandardTranslator(consumerTypeCurator, environmentCurator, ownerCuratorMock);
    quantityRules = new QuantityRules(provider.get(), new RulesObjectMapper(new ProductCachedSerializationModule(productCurator)), translator);
    owner = new Owner("Test Owner " + TestUtil.randomInt());
    product = TestUtil.createProduct();
    pool = TestUtil.createPool(owner, product);
    pool.setId("fakepoolid");
    ctype = TestUtil.createConsumerType();
    consumer = TestUtil.createConsumer(owner);
    when(consumerTypeCurator.find(eq(ctype.getId()))).thenReturn(ctype);
    when(consumerTypeCurator.getConsumerType(eq(consumer))).thenReturn(ctype);
    Entitlement e = TestUtil.createEntitlement(owner, consumer, pool, new EntitlementCertificate());
    Set<Entitlement> entSet = new HashSet<>();
    entSet.add(e);
    pool.setEntitlements(entSet);
    pool.getProduct().setAttribute(Pool.Attributes.MULTI_ENTITLEMENT, "yes");
    pool.getProduct().setAttribute(Product.Attributes.STACKING_ID, "1");
}
Also used : Owner(org.candlepin.model.Owner) EntitlementCertificate(org.candlepin.model.EntitlementCertificate) InputStream(java.io.InputStream) RulesObjectMapper(org.candlepin.policy.js.RulesObjectMapper) Rules(org.candlepin.model.Rules) StandardTranslator(org.candlepin.dto.StandardTranslator) Date(java.util.Date) ProductCachedSerializationModule(org.candlepin.jackson.ProductCachedSerializationModule) JsRunnerProvider(org.candlepin.policy.js.JsRunnerProvider) Entitlement(org.candlepin.model.Entitlement) HashSet(java.util.HashSet) Before(org.junit.Before)

Aggregations

ProductCachedSerializationModule (org.candlepin.jackson.ProductCachedSerializationModule)9 Rules (org.candlepin.model.Rules)9 JsRunnerProvider (org.candlepin.policy.js.JsRunnerProvider)9 RulesObjectMapper (org.candlepin.policy.js.RulesObjectMapper)9 Before (org.junit.Before)9 InputStream (java.io.InputStream)8 StandardTranslator (org.candlepin.dto.StandardTranslator)7 Date (java.util.Date)6 Owner (org.candlepin.model.Owner)4 Locale (java.util.Locale)3 JsRunner (org.candlepin.policy.js.JsRunner)3 Consumer (org.candlepin.model.Consumer)2 ConsumerType (org.candlepin.model.ConsumerType)2 Provider (com.google.inject.Provider)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 HashSet (java.util.HashSet)1 Configuration (org.candlepin.common.config.Configuration)1 Entitlement (org.candlepin.model.Entitlement)1 EntitlementCertificate (org.candlepin.model.EntitlementCertificate)1