use of org.drools.core.definitions.rule.impl.RuleImpl in project drools by kiegroup.
the class RuleUnlinkingWithSegmentMemoryTest method setUp.
public void setUp(int type) {
KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(kconf);
buildContext = new BuildContext(kBase);
PropagationContextFactory pctxFactory = kBase.getConfiguration().getComponentFactory().getPropagationContextFactory();
context = pctxFactory.createPropagationContext(0, PropagationContext.Type.INSERTION, null, null, null);
ObjectTypeNode otn = new ObjectTypeNode(4, null, new ClassObjectType(String.class), buildContext);
lian = new LeftInputAdapterNode(5, otn, buildContext);
n1 = (BetaNode) createNetworkNode(10, type, lian, null);
n2 = (BetaNode) createNetworkNode(11, type, n1, null);
n3 = (BetaNode) createNetworkNode(12, type, n2, null);
rule1 = new RuleImpl("rule1");
rule1.setActivationListener("agenda");
rtn1 = (RuleTerminalNode) createNetworkNode(18, RULE_TERMINAL_NODE, n3, rule1);
n4 = (BetaNode) createNetworkNode(13, type, n3, null);
n5 = (BetaNode) createNetworkNode(14, type, n4, null);
rule2 = new RuleImpl("rule2");
rule2.setActivationListener("agenda");
rtn2 = (RuleTerminalNode) createNetworkNode(19, RULE_TERMINAL_NODE, n5, rule2);
n6 = (BetaNode) createNetworkNode(15, type, n5, null);
n7 = (BetaNode) createNetworkNode(16, type, n6, null);
n8 = (BetaNode) createNetworkNode(17, type, n7, null);
rule3 = new RuleImpl("rule3");
rule3.setActivationListener("agenda");
rtn3 = (RuleTerminalNode) createNetworkNode(20, RULE_TERMINAL_NODE, n8, rule3);
lian.addAssociation(rule1);
lian.addAssociation(rule2);
lian.addAssociation(rule3);
n1.addAssociation(rule1);
n1.addAssociation(rule2);
n1.addAssociation(rule3);
n2.addAssociation(rule1);
n2.addAssociation(rule2);
n2.addAssociation(rule3);
n3.addAssociation(rule1);
n3.addAssociation(rule2);
n3.addAssociation(rule3);
n4.addAssociation(rule2);
n4.addAssociation(rule3);
n5.addAssociation(rule2);
n5.addAssociation(rule3);
n6.addAssociation(rule3);
n7.addAssociation(rule3);
n8.addAssociation(rule3);
}
use of org.drools.core.definitions.rule.impl.RuleImpl in project drools by kiegroup.
the class ReteooRuleBuilderTest method testAddRuleWithPatterns.
@Test
public void testAddRuleWithPatterns() {
final RuleImpl rule = new RuleImpl("only patterns");
final Pattern c1 = new Pattern(0, new ClassObjectType(String.class));
final Pattern c2 = new Pattern(1, new ClassObjectType(String.class));
final Pattern c3 = new Pattern(2, new ClassObjectType(String.class));
final GroupElement lhsroot = GroupElementFactory.newAndInstance();
lhsroot.addChild(c1);
lhsroot.addChild(c2);
lhsroot.addChild(c3);
rule.setLhs(lhsroot);
final Consequence consequence = new Consequence() {
public void evaluate(KnowledgeHelper knowledgeHelper, WorkingMemory workingMemory) throws Exception {
System.out.println("Consequence!");
}
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
}
public void writeExternal(ObjectOutput out) throws IOException {
}
public String getName() {
return "default";
}
};
rule.setConsequence(consequence);
final List terminals = this.builder.addRule(rule, this.rulebase);
assertEquals("Rule must have a single terminal node", 1, terminals.size());
final RuleTerminalNode terminal = (RuleTerminalNode) terminals.get(0);
}
use of org.drools.core.definitions.rule.impl.RuleImpl in project drools by kiegroup.
the class PrioritySetWithFormulaTest method test.
@Test
public void test() {
// RULE CheeseWorld_11 has salience "=3+2"
RuleImpl cheeseWorld11 = (RuleImpl) kieBase.getRule("test", "CheeseWorld_11");
assertEquals(5, cheeseWorld11.getSalience().getValue());
// RULE CheeseWorld_12 has salience "=ROW()"
RuleImpl cheeseWorld12 = (RuleImpl) kieBase.getRule("test", "CheeseWorld_12");
assertEquals(12, cheeseWorld12.getSalience().getValue());
}
use of org.drools.core.definitions.rule.impl.RuleImpl in project drools by kiegroup.
the class NamedConsequenceBuilder method buildTerminalNodeForNamedConsequence.
static RuleTerminalNode buildTerminalNodeForNamedConsequence(BuildContext context, NamedConsequence namedConsequence) {
RuleImpl rule = context.getRule();
GroupElement subrule = (GroupElement) context.peek();
ActivationListenerFactory factory = context.getKnowledgeBase().getConfiguration().getActivationListenerFactory(rule.getActivationListener());
context.setConsequenceName(namedConsequence.getConsequenceName());
TerminalNode terminal = factory.createActivationListener(context.getNextId(), context.getTupleSource(), rule, subrule, // subruleIndex,
0, context);
context.setConsequenceName(null);
return (RuleTerminalNode) terminal;
}
use of org.drools.core.definitions.rule.impl.RuleImpl 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));
}
Aggregations