Work
This commit is contained in:
parent
543772616c
commit
48a27afb3d
35 changed files with 98 additions and 869 deletions
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
|
||||
|
||||
<kbase name="lesson4" packages="lesson4">
|
||||
<ksession name="lesson4-session"/>
|
||||
</kbase>
|
||||
<kbase name="lesson4a" packages="lesson4a">
|
||||
<ksession name="lesson4a-session"/>
|
||||
</kbase>
|
||||
</kmodule>
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<process xmlns="http://drools.org/drools-5.0/process"
|
||||
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xs:schemaLocation="http://drools.org/drools-5.0/process drools-processes-5.0.xsd"
|
||||
type="RuleFlow" name="RuleFlow1" id="RF1" package-name="cours" >
|
||||
|
||||
<header>
|
||||
</header>
|
||||
|
||||
<nodes>
|
||||
<start id="1" name="Start" x="62" y="79" width="80" height="40" />
|
||||
<ruleSet id="2" name="Verify" x="162" y="77" width="80" height="40" ruleFlowGroup="Group1" />
|
||||
<ruleSet id="3" name="Calculation" x="267" y="77" width="80" height="40" ruleFlowGroup="Group2" />
|
||||
<end id="4" name="End" x="372" y="77" width="80" height="40" />
|
||||
</nodes>
|
||||
|
||||
<connections>
|
||||
<connection from="1" to="2" />
|
||||
<connection from="2" to="3" />
|
||||
<connection from="3" to="4" />
|
||||
</connections>
|
||||
|
||||
</process>
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
//#created on: 30 oct. 2010
|
||||
package cours
|
||||
|
||||
//#list any import classes here.
|
||||
import droolscours.Account;
|
||||
import droolscours.AccountingPeriod;
|
||||
import droolscours.CashFlow;
|
||||
import droolscours.util.OutputDisplay;
|
||||
|
||||
//#declare any global variables here
|
||||
|
||||
|
||||
global OutputDisplay showResult;
|
||||
|
||||
|
||||
rule "Account group1"
|
||||
ruleflow-group "Group1"
|
||||
when
|
||||
Account( )
|
||||
then
|
||||
showResult.showText("Account in Group1");
|
||||
|
||||
end
|
||||
rule "Account group2"
|
||||
ruleflow-group "Group2"
|
||||
when
|
||||
Account( )
|
||||
then
|
||||
showResult.showText("Account in Group2");
|
||||
|
||||
end
|
||||
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<process xmlns="http://drools.org/drools-5.0/process"
|
||||
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xs:schemaLocation="http://drools.org/drools-5.0/process drools-processes-5.0.xsd"
|
||||
type="RuleFlow" name="RuleFlow3" id="RF3" package-name="cours" >
|
||||
|
||||
<header>
|
||||
<imports>
|
||||
<import name="droolscours.Account" />
|
||||
</imports>
|
||||
</header>
|
||||
|
||||
<nodes>
|
||||
<start id="1" name="Start" x="27" y="78" width="80" height="40" />
|
||||
<ruleSet id="2" name="Calculate2" x="264" y="135" width="80" height="40" ruleFlowGroup="Group2" />
|
||||
<ruleSet id="3" name="Calculate1" x="266" y="28" width="80" height="40" ruleFlowGroup="Group1" />
|
||||
<end id="4" name="End" x="487" y="85" width="80" height="40" />
|
||||
<join id="6" name="Join" x="357" y="91" width="80" height="40" type="2" />
|
||||
<split id="7" name="Split" x="131" y="93" width="80" height="40" type="3" >
|
||||
<constraints>
|
||||
<constraint toNodeId="2" toType="DROOLS_DEFAULT" name="constraint" priority="1" type="rule" dialect="mvel" >Account(balance <= 1000 )</constraint>
|
||||
<constraint toNodeId="3" toType="DROOLS_DEFAULT" name="constraint" priority="1" type="rule" dialect="mvel" >Account(balance > 1000 )</constraint>
|
||||
</constraints>
|
||||
</split>
|
||||
</nodes>
|
||||
|
||||
<connections>
|
||||
<connection from="7" to="2" />
|
||||
<connection from="7" to="3" />
|
||||
<connection from="6" to="4" />
|
||||
<connection from="3" to="6" />
|
||||
<connection from="2" to="6" />
|
||||
<connection from="1" to="7" />
|
||||
</connections>
|
||||
|
||||
</process>
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
//#created on: 30 oct. 2010
|
||||
package cours
|
||||
|
||||
//#list any import classes here.
|
||||
import droolscours.Account;
|
||||
import droolscours.AccountingPeriod;
|
||||
import droolscours.CashFlow;
|
||||
import droolscours.util.OutputDisplay;
|
||||
|
||||
//#declare any global variables here
|
||||
|
||||
|
||||
global OutputDisplay showResult;
|
||||
|
||||
rule "start process"
|
||||
when
|
||||
then
|
||||
kcontext.getKieRuntime().startProcess("RF3");
|
||||
end
|
||||
|
||||
rule "Account group1"
|
||||
ruleflow-group "Group1"
|
||||
when
|
||||
Account(balance > 0 )
|
||||
then
|
||||
showResult.showText("Account in Group1 > 1000 ");
|
||||
|
||||
end
|
||||
rule "Account group2"
|
||||
ruleflow-group "Group2"
|
||||
when
|
||||
Account( )
|
||||
then
|
||||
showResult.showText("Account in Group2 < 1000");
|
||||
|
||||
end
|
||||
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
package droolscours;
|
||||
|
||||
import droolscours.util.OutputDisplay;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.kie.api.runtime.KieContainer;
|
||||
import org.kie.api.runtime.KieSession;
|
||||
import util.KnowledgeSessionHelper;
|
||||
|
||||
|
||||
public class Testlesson4 {
|
||||
static KieContainer kieContainer;
|
||||
KieSession sessionStatefull = null;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
kieContainer = KnowledgeSessionHelper.createRuleBase();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
System.out.println("------------Before------------");
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
System.out.println("------------Après ------------");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRuleFlow1() {
|
||||
sessionStatefull = KnowledgeSessionHelper
|
||||
.getStatefulKnowledgeSessionForJBPM(kieContainer, "ksession-lesson4");
|
||||
OutputDisplay display = new OutputDisplay();
|
||||
sessionStatefull.setGlobal("showResult", display);
|
||||
Account a = new Account();
|
||||
sessionStatefull.insert(a);
|
||||
sessionStatefull.startProcess("RF1");
|
||||
sessionStatefull.fireAllRules();
|
||||
}
|
||||
@Test
|
||||
public void testRuleFlow2() {
|
||||
sessionStatefull = KnowledgeSessionHelper
|
||||
.getStatefulKnowledgeSessionForJBPM(kieContainer, "ksession-lesson4");
|
||||
OutputDisplay display = new OutputDisplay();
|
||||
sessionStatefull.setGlobal("showResult", display);
|
||||
Account a = new Account();
|
||||
sessionStatefull.insert(a);
|
||||
sessionStatefull.fireAllRules();
|
||||
}
|
||||
@Test
|
||||
public void testRuleFlow3() {
|
||||
sessionStatefull = KnowledgeSessionHelper
|
||||
.getStatefulKnowledgeSession(kieContainer, "lesson4a-session");
|
||||
OutputDisplay display = new OutputDisplay();
|
||||
sessionStatefull.setGlobal("showResult", display);
|
||||
Account a = new Account();
|
||||
a.setBalance(500);
|
||||
sessionStatefull.insert(a);
|
||||
AccountingPeriod period = new AccountingPeriod();
|
||||
sessionStatefull.insert(period);
|
||||
|
||||
sessionStatefull.fireAllRules();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue