Search in sources :

Example 1 with RulesObjectMapper

use of org.candlepin.policy.js.RulesObjectMapper 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 RulesObjectMapper

use of org.candlepin.policy.js.RulesObjectMapper 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 RulesObjectMapper

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

the class ComplianceRulesTest method additivePropertiesCanStillDeserialize.

/*
     * Make sure additive properties coming back from the javascript do not break when
     * we deserialize.
     */
@Test
public void additivePropertiesCanStillDeserialize() {
    JsRunner mockRunner = mock(JsRunner.class);
    compliance = new ComplianceRules(mockRunner, entCurator, new StatusReasonMessageGenerator(i18n), eventSink, consumerCurator, consumerTypeCurator, new RulesObjectMapper(new ProductCachedSerializationModule(productCurator)), translator);
    when(mockRunner.runJsFunction(any(Class.class), eq("get_status"), any(JsContext.class))).thenReturn("{\"unknown\": \"thing\"}");
    Consumer c = mockConsumerWithTwoProductsAndNoEntitlements();
    // Nothing to assert here, we just need to see this return without error.
    compliance.getStatus(c, TestUtil.createDate(2011, 8, 30));
}
Also used : ProductCachedSerializationModule(org.candlepin.jackson.ProductCachedSerializationModule) Consumer(org.candlepin.model.Consumer) RulesObjectMapper(org.candlepin.policy.js.RulesObjectMapper) JsContext(org.candlepin.policy.js.JsContext) JsRunner(org.candlepin.policy.js.JsRunner) Test(org.junit.Test)

Example 4 with RulesObjectMapper

use of org.candlepin.policy.js.RulesObjectMapper 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 5 with RulesObjectMapper

use of org.candlepin.policy.js.RulesObjectMapper 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)

Aggregations

ProductCachedSerializationModule (org.candlepin.jackson.ProductCachedSerializationModule)10 RulesObjectMapper (org.candlepin.policy.js.RulesObjectMapper)10 Rules (org.candlepin.model.Rules)9 JsRunnerProvider (org.candlepin.policy.js.JsRunnerProvider)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 JsRunner (org.candlepin.policy.js.JsRunner)4 Locale (java.util.Locale)3 Consumer (org.candlepin.model.Consumer)3 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