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