use of org.candlepin.model.Rules 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.model.Rules in project candlepin by candlepin.
the class PoolRulesTest method setUp.
@Before
public void setUp() {
// 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(configMock.getInt(eq(ConfigProperties.PRODUCT_CACHE_MAX))).thenReturn(100);
poolRules = new PoolRules(poolManagerMock, configMock, entCurMock, ownerProdCuratorMock, productCurator);
principal = TestUtil.createOwnerPrincipal();
owner = principal.getOwners().get(0);
}
use of org.candlepin.model.Rules 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.model.Rules in project candlepin by candlepin.
the class RulesResource method delete.
@ApiOperation(notes = "Removes the Rules Deletes any uploaded rules, uses bundled rules instead", value = "delete")
@DELETE
@Produces(MediaType.APPLICATION_JSON)
public void delete() {
Rules deleteRules = rulesCurator.getRules();
rulesCurator.delete(deleteRules);
log.warn("Deleting rules version: " + deleteRules.getVersion());
sink.emitRulesDeleted(deleteRules);
// Trigger a recompile of the JS rules so version/source are set correctly:
jsProvider.compileRules(true);
}
use of org.candlepin.model.Rules in project candlepin by candlepin.
the class JsRunnerProvider method compileRules.
public void compileRules(boolean forceRefresh) {
scriptLock.writeLock().lock();
try {
// Check to see if we need to recompile. we do this inside the write lock
// just to avoid race conditions where we might double compile
Date newUpdated = rulesCurator.getUpdated();
if (!forceRefresh && newUpdated.equals(this.currentRulesUpdated)) {
return;
}
log.info("Recompiling rules with timestamp: {}", newUpdated);
Context context = Context.enter();
context.setOptimizationLevel(9);
scope = context.initStandardObjects(null, true);
try {
Rules rules = rulesCurator.getRules();
rulesVersion = rules.getVersion();
rulesSource = rules.getRulesSource();
script = context.compileString(rules.getRules(), "rules", 1, null);
script.exec(context, scope);
((ScriptableObject) scope).sealObject();
this.currentRulesUpdated = newUpdated;
} finally {
Context.exit();
}
} finally {
scriptLock.writeLock().unlock();
}
}
Aggregations