Search in sources :

Example 6 with RulesObjectMapper

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

Example 7 with RulesObjectMapper

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

the class EnforcerTest method createEnforcer.

@Before
public void createEnforcer() throws Exception {
    MockitoAnnotations.initMocks(this);
    when(config.getInt(eq(ConfigProperties.PRODUCT_CACHE_MAX))).thenReturn(100);
    owner = createOwner();
    ownerCurator.create(owner);
    consumer = this.createConsumer(owner);
    BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/rules/test-rules.js")));
    StringBuilder builder = new StringBuilder();
    String line = null;
    while ((line = reader.readLine()) != null) {
        builder.append(line + "\n");
    }
    reader.close();
    Rules rules = mock(Rules.class);
    when(rules.getRules()).thenReturn(builder.toString());
    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, mockEnvironmentCurator, mockOwnerCurator);
    enforcer = new EntitlementRules(new DateSourceForTesting(2010, 1, 1), jsRules, i18n, config, consumerCurator, consumerTypeCurator, mockProductCurator, new RulesObjectMapper(new ProductCachedSerializationModule(mockProductCurator)), mockOwnerCurator, mockOwnerProductCurator, mockProductShareCurator, mockProductManager, mockEventSink, mockEventFactory, translator);
}
Also used : ProductCachedSerializationModule(org.candlepin.jackson.ProductCachedSerializationModule) DateSourceForTesting(org.candlepin.test.DateSourceForTesting) InputStreamReader(java.io.InputStreamReader) EntitlementRules(org.candlepin.policy.js.entitlement.EntitlementRules) BufferedReader(java.io.BufferedReader) JsRunnerProvider(org.candlepin.policy.js.JsRunnerProvider) RulesObjectMapper(org.candlepin.policy.js.RulesObjectMapper) JsRunner(org.candlepin.policy.js.JsRunner) Rules(org.candlepin.model.Rules) EntitlementRules(org.candlepin.policy.js.entitlement.EntitlementRules) StandardTranslator(org.candlepin.dto.StandardTranslator) Before(org.junit.Before)

Example 8 with RulesObjectMapper

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

the class ComplianceRulesTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    translator = new StandardTranslator(consumerTypeCurator, environmentCurator, mockOwnerCurator);
    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);
    compliance = new ComplianceRules(provider.get(), entCurator, new StatusReasonMessageGenerator(i18n), eventSink, consumerCurator, consumerTypeCurator, new RulesObjectMapper(new ProductCachedSerializationModule(productCurator)), translator);
    owner = new Owner("test");
    owner.setId(TestUtil.randomString());
    when(mockOwnerCurator.findOwnerById(eq(owner.getId()))).thenReturn(owner);
    activeGuestAttrs = new HashMap<>();
    activeGuestAttrs.put("virtWhoType", "libvirt");
    activeGuestAttrs.put("active", "1");
}
Also used : Locale(java.util.Locale) ProductCachedSerializationModule(org.candlepin.jackson.ProductCachedSerializationModule) Owner(org.candlepin.model.Owner) InputStream(java.io.InputStream) JsRunnerProvider(org.candlepin.policy.js.JsRunnerProvider) RulesObjectMapper(org.candlepin.policy.js.RulesObjectMapper) StandardTranslator(org.candlepin.dto.StandardTranslator) Rules(org.candlepin.model.Rules) Date(java.util.Date) Before(org.junit.Before)

Example 9 with RulesObjectMapper

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

Example 10 with RulesObjectMapper

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

the class OverrideRulesTests method setupTest.

@Before
public void setupTest() {
    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);
    overrideRules = new OverrideRules(provider.get(), config, new RulesObjectMapper(new ProductCachedSerializationModule(productCurator)));
}
Also used : ProductCachedSerializationModule(org.candlepin.jackson.ProductCachedSerializationModule) InputStream(java.io.InputStream) JsRunnerProvider(org.candlepin.policy.js.JsRunnerProvider) RulesObjectMapper(org.candlepin.policy.js.RulesObjectMapper) Rules(org.candlepin.model.Rules) Date(java.util.Date) 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