use of org.drools.core.impl.KnowledgeBaseImpl in project drools by kiegroup.
the class RuleTest method testRuleEnabled.
@Test
public void testRuleEnabled() {
WorkingMemory wm = (WorkingMemory) new KnowledgeBaseImpl("x", null).newKieSession();
final RuleImpl rule = new RuleImpl("myrule");
rule.setEnabled(EnabledBoolean.ENABLED_FALSE);
assertFalse(rule.isEffective(null, new RuleTerminalNode(), wm));
final Calendar past = Calendar.getInstance();
past.setTimeInMillis(10);
rule.setDateEffective(past);
assertFalse(rule.isEffective(null, new RuleTerminalNode(), wm));
rule.setEnabled(EnabledBoolean.ENABLED_TRUE);
assertTrue(rule.isEffective(null, new RuleTerminalNode(), wm));
}
use of org.drools.core.impl.KnowledgeBaseImpl in project drools by kiegroup.
the class RuleTest method testDateEffectiveExpires.
@Test
public void testDateEffectiveExpires() {
WorkingMemory wm = (WorkingMemory) new KnowledgeBaseImpl("x", null).newKieSession();
final RuleImpl rule = new RuleImpl("myrule");
final Calendar past = Calendar.getInstance();
past.setTimeInMillis(10);
final Calendar future = Calendar.getInstance();
future.setTimeInMillis(future.getTimeInMillis() + 100000000);
rule.setDateEffective(past);
rule.setDateExpires(future);
assertTrue(rule.isEffective(null, new RuleTerminalNode(), wm));
rule.setDateExpires(past);
assertFalse(rule.isEffective(null, new RuleTerminalNode(), wm));
rule.setDateExpires(future);
rule.setDateEffective(future);
assertFalse(rule.isEffective(null, new RuleTerminalNode(), wm));
}
use of org.drools.core.impl.KnowledgeBaseImpl in project drools by kiegroup.
the class RuleTest method testDateEffective.
@Test
public void testDateEffective() {
WorkingMemory wm = (WorkingMemory) new KnowledgeBaseImpl("x", null).newKieSession();
final RuleImpl rule = new RuleImpl("myrule");
assertTrue(rule.isEffective(null, new RuleTerminalNode(), wm));
final Calendar earlier = Calendar.getInstance();
earlier.setTimeInMillis(10);
rule.setDateEffective(earlier);
assertTrue(rule.isEffective(null, new RuleTerminalNode(), wm));
final Calendar later = Calendar.getInstance();
later.setTimeInMillis(later.getTimeInMillis() + 100000000);
assertTrue(later.after(Calendar.getInstance()));
rule.setDateEffective(later);
assertFalse(rule.isEffective(null, new RuleTerminalNode(), wm));
}
use of org.drools.core.impl.KnowledgeBaseImpl in project drools by kiegroup.
the class SegmentExecution method applySegmentModel.
public void applySegmentModel(PMMLRequestData requestData, DataSource<PMMLRequestData> data, DataSource<PMML4Result> results, DataSource<SegmentExecution> segmentExecutions, KnowledgeHelper helper) throws IllegalStateException {
if (ruleUnitClassName == null || ruleUnitClassName.trim().isEmpty()) {
throw new IllegalStateException("Unable to apply segment model: No rule unit class name is available");
}
Class<? extends RuleUnit> ruleUnitClass = null;
RuleUnitRegistry rur = ((KnowledgeBaseImpl) helper.getKieRuntime().getKieBase()).getRuleUnitRegistry();
RuleUnit ruOld = ((WrappedStatefulKnowledgeSessionForRHS) helper.getKieRuntime()).getRuleUnitExecutor().getCurrentRuleUnit();
RuleUnitDescr rud = rur.getNamedRuleUnit(ruleUnitClassName).orElse(null);
if (rud != null) {
ruleUnitClass = rud.getRuleUnitClass();
} else {
throw new IllegalStateException("Unable to apply segment model: Unable to find rule unit");
}
// if (ruleUnitClass != null) {
// helper.run(ruleUnitClass);
// PMML4Result result = new PMML4Result(this);
// FactHandle requestFH = data.insert(this.requestData);
// FactHandle resultsFH = results.insert(result);
//
// helper.run(ruleUnitClass);
// RuleUnit ruNew = ((WrappedStatefulKnowledgeSessionForRHS)helper.getKieRuntime()).getRuleUnitExecutor().getCurrentRuleUnit();
// System.out.println("** Result **");
// System.out.println(result);
//
// // Update the state and let the Mining session know
// this.state = SegmentExecutionState.EXECUTING;
// FactHandle handle = ((InternalDataSource)segmentExecutions).getFactHandleForObject(this);
// segmentExecutions.update(handle, this);
//
// helper.run(ruleUnitClass);
// System.out.println("Sub-Model Results");
// results.forEach(r -> {System.out.println(r);});
// }
}
use of org.drools.core.impl.KnowledgeBaseImpl in project drools by kiegroup.
the class ScenarioRunner4JUnitTest method setUp.
@Before
public void setUp() throws Exception {
ksession = mock(StatefulKnowledgeSessionImpl.class);
KnowledgeBaseImpl knowledgeBase = mock(KnowledgeBaseImpl.class);
when(ksession.getKieBase()).thenReturn(knowledgeBase);
ProjectClassLoader classLoader = ProjectClassLoader.createProjectClassLoader();
when(knowledgeBase.getRootClassLoader()).thenReturn(classLoader);
}
Aggregations