Work
This commit is contained in:
parent
ce0f351c9d
commit
c9209dc9a5
105 changed files with 2390 additions and 839 deletions
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
|
||||
|
||||
<kbase name="lesson2" packages="lesson2">
|
||||
<ksession name="lesson2-session"/>
|
||||
</kbase>
|
||||
|
||||
</kmodule>
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
//#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 and accounting period both exist"
|
||||
|
||||
when
|
||||
Account( )
|
||||
AccountingPeriod( )
|
||||
then
|
||||
showResult.showText("Un compte est un accountingperiod existe");
|
||||
|
||||
end
|
||||
rule "Credit rule"
|
||||
|
||||
when
|
||||
$cash :CashFlow( $no : accountNo ,type == CashFlow.CREDIT )
|
||||
$acc : Account(accountno ==$no )
|
||||
then
|
||||
$acc.setBalance($acc.getBalance()+$cash.getAmount());
|
||||
showResult.showText("le compte no "+$no+ " a maintenant une valeur de "+$acc.getBalance());
|
||||
end
|
||||
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
package droolscours;
|
||||
|
||||
import droolscours.util.OutputDisplay;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.kie.api.runtime.KieContainer;
|
||||
import org.kie.api.runtime.KieSession;
|
||||
import org.kie.api.runtime.StatelessKieSession;
|
||||
import util.DateHelper;
|
||||
import util.KnowledgeSessionHelper;
|
||||
|
||||
|
||||
public class Testlesson2 {
|
||||
static KieContainer kieContainer;
|
||||
StatelessKieSession sessionStateless = null;
|
||||
KieSession sessionStatefull = null;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass(){
|
||||
kieContainer=KnowledgeSessionHelper.createRuleBase();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testdeuxFait1() {
|
||||
sessionStatefull = KnowledgeSessionHelper
|
||||
.getStatefulKnowledgeSessionWithCallback(kieContainer,"lesson2-session");
|
||||
|
||||
OutputDisplay display = new OutputDisplay();
|
||||
sessionStatefull.setGlobal("showResult", display);
|
||||
Account a = new Account();
|
||||
sessionStatefull.insert(a);
|
||||
AccountingPeriod period = new AccountingPeriod();
|
||||
sessionStatefull.insert(period);
|
||||
sessionStatefull.fireAllRules();
|
||||
}
|
||||
@Test
|
||||
public void testdeuxFait2() throws Exception {
|
||||
sessionStatefull = KnowledgeSessionHelper
|
||||
.getStatefulKnowledgeSessionWithCallback(kieContainer,"lesson2-session");
|
||||
OutputDisplay display = new OutputDisplay();
|
||||
sessionStatefull.setGlobal("showResult", display);
|
||||
Account a = new Account();
|
||||
a.setAccountno(1);
|
||||
a.setBalance(0);
|
||||
sessionStatefull.insert(a);
|
||||
CashFlow cash1 = new CashFlow();
|
||||
cash1.setAccountNo(1);
|
||||
cash1.setAmount(1000);
|
||||
cash1.setMvtDate(DateHelper.getDate("2010-01-15"));
|
||||
cash1.setType(CashFlow.CREDIT);
|
||||
sessionStatefull.insert(cash1);
|
||||
sessionStatefull.fireAllRules();
|
||||
junit.framework.Assert.assertTrue(a.getBalance()==1000);
|
||||
}
|
||||
@Test
|
||||
public void testdeuxFait3() throws Exception {
|
||||
sessionStatefull = KnowledgeSessionHelper
|
||||
.getStatefulKnowledgeSessionWithCallback(kieContainer,"lesson2-session");
|
||||
OutputDisplay display = new OutputDisplay();
|
||||
sessionStatefull.setGlobal("showResult", display);
|
||||
Account a = new Account();
|
||||
a.setAccountno(1);
|
||||
a.setBalance(0);
|
||||
sessionStatefull.insert(a);
|
||||
CashFlow cash1 = new CashFlow();
|
||||
cash1.setAccountNo(1);
|
||||
cash1.setAmount(1000);
|
||||
cash1.setMvtDate(DateHelper.getDate("2010-01-15"));
|
||||
cash1.setType(CashFlow.CREDIT);
|
||||
sessionStatefull.insert(cash1);
|
||||
CashFlow cash2 = new CashFlow();
|
||||
cash2.setAccountNo(2);
|
||||
cash2.setAmount(1000);
|
||||
cash2.setMvtDate(DateHelper.getDate("2010-01-15"));
|
||||
cash2.setType(CashFlow.CREDIT);
|
||||
sessionStatefull.insert(cash2);
|
||||
sessionStatefull.fireAllRules();
|
||||
junit.framework.Assert.assertTrue(a.getBalance()==1000);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue