This commit is contained in:
Nicolas Héron 2016-05-20 14:16:10 +02:00
commit 474d3bf5b1
86 changed files with 675 additions and 529 deletions

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
<kbase name="lesson31" packages="lesson31">
<ksession name="lesson31-session"/>
</kbase>
</kmodule>

View file

@ -0,0 +1,51 @@
//#created on: 30 oct. 2010
package cours
//#list any import classes here.
import droolscours.Account;
import droolscours.AccountingPeriod;
import droolscours.CashFlow;
import droolscours.PrivateAccount;
import droolscours.Customer;
import droolscours.util.OutputDisplay;
//#declare any global variables here
global OutputDisplay showResult;
rule "Le cashFlow est du crédit ou du débit"
when
$cash :CashFlow(type in ( CashFlow.DEBIT,CashFlow.CREDIT) )
then
showResult.showText("Cash Flow est un crédit ou un débit");
end
rule "Accessor"
when
$cash :PrivateAccount( owner.name =="Héron" )
then
showResult.showText("Account is owned by Héron");
end
rule "infixAnd"
when
( $c1 : Customer ( country=="GB") and PrivateAccount( owner==$c1))
or
( $c1 : Customer (country=="US") and PrivateAccount( owner==$c1))
then
showResult.showText("Person lives in GB or US");
end
rule "no customer"
when
not Customer( )
then
showResult.showText("No customer");
end
rule "Exists"
when
exists Account( )
then
showResult.showText("Account exists");
end

View file

@ -0,0 +1,29 @@
package droolscours;
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.KnowledgeSessionHelper;
public class Testlesson31 {
static KieContainer kieContainer;
StatelessKieSession sessionStateless = null;
KieSession sessionStatefull = null;
@BeforeClass
public static void beforeClass() {
kieContainer = KnowledgeSessionHelper.createRuleBase();
}
@Test
public void testUnFaitSansFait() {
sessionStatefull = KnowledgeSessionHelper
.getStatefulKnowledgeSession(kieContainer, "lesson3-session");
sessionStatefull.fireAllRules();
System.out.println("Did you see something ?");
}
}