This commit is contained in:
Nicolas Héron 2016-05-23 15:52:56 +02:00
commit 543772616c
7 changed files with 80 additions and 11 deletions

View file

@ -51,3 +51,11 @@ rule "Exists"
then
showResult.showText("Account exists");
end
rule "ForAll"
when
forall ( Account( $no : accountno )
CashFlow( accountNo == $no)
)
then
showResult.showText("All cashflows are related to an Account ");
end

View file

@ -81,4 +81,37 @@ public class Testlesson31 {
sessionStatefull.insert(pAccount);
sessionStatefull.fireAllRules();
}
@Test
public void testForALl() throws Exception {
sessionStatefull = KnowledgeSessionHelper
.getStatefulKnowledgeSessionWithCallback(kieContainer, "ksession-lesson3");
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);
sessionStatefull.insert(cash1);
CashFlow cash2 = new CashFlow();
cash2.setAccountNo(1);
sessionStatefull.insert(cash2);
Account a2 = new Account();
a2.setAccountno(2);
a2.setBalance(0);
sessionStatefull.insert(a2);
CashFlow cash3 = new CashFlow();
cash3.setAccountNo(2);
sessionStatefull.insert(cash3);
sessionStatefull.fireAllRules();
}
}

View file

@ -13,7 +13,7 @@ import droolscours.util.OutputDisplay;
global OutputDisplay showResult;
global CustomerService serviceCustomer;
rule "ForAll"
rule "FromCondition"
when
$c : Customer()
$cc : Customer(name ==$c.name,surname==$c.surname,country !=$c.country) from serviceCustomer.getListCustomer();

View file

@ -1,5 +1,7 @@
package droolscours;
import droolscours.service.CustomerService;
import droolscours.util.OutputDisplay;
import org.junit.BeforeClass;
import org.junit.Test;
import org.kie.api.runtime.KieContainer;
@ -19,11 +21,15 @@ public class Testlesson33 {
}
@Test
public void testUnFaitSansFait() {
public void testFromLHS() throws Exception {
sessionStatefull = KnowledgeSessionHelper
.getStatefulKnowledgeSession(kieContainer, "lesson1-session");
.getStatefulKnowledgeSessionWithCallback(kieContainer, "lesson33-session");
OutputDisplay display = new OutputDisplay();
sessionStatefull.setGlobal("showResult", display);
sessionStatefull.setGlobal("serviceCustomer", new CustomerService());
Customer c = new Customer("Héron", "Nicolas", "A");
sessionStatefull.insert(c);
sessionStatefull.fireAllRules();
System.out.println("Did you see something ?");
}
}

View file

@ -1,4 +1,3 @@
//#created on: 30 oct. 2010
package cours
//#list any import classes here.

View file

@ -1,10 +1,12 @@
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;
@ -19,11 +21,20 @@ public class Testlesson34 {
}
@Test
public void testUnFaitSansFait() {
public void testCollecting() throws Exception {
sessionStatefull = KnowledgeSessionHelper
.getStatefulKnowledgeSession(kieContainer, "lesson1-session");
.getStatefulKnowledgeSessionWithCallback(kieContainer, "lesson34-session");
OutputDisplay display = new OutputDisplay();
sessionStatefull.setGlobal("showResult", display);
Account a = new Account();
a.setAccountno(1);
a.setBalance(0);
sessionStatefull.insert(a);
sessionStatefull.insert(new CashFlow(DateHelper.getDate("2010-01-15"), 1000, CashFlow.CREDIT, 1));
sessionStatefull.insert(new CashFlow(DateHelper.getDate("2010-02-15"), 500, CashFlow.DEBIT, 1));
sessionStatefull.insert(new CashFlow(DateHelper.getDate("2010-04-15"), 1000, CashFlow.CREDIT, 1));
sessionStatefull.insert(new AccountingPeriod(DateHelper.getDate("2010-01-01"), DateHelper.getDate("2010-31-31")));
sessionStatefull.fireAllRules();
System.out.println("Did you see something ?");
}
}

View file

@ -1,10 +1,13 @@
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 org.kie.api.runtime.rule.FactHandle;
import util.DateHelper;
import util.KnowledgeSessionHelper;
@ -19,11 +22,20 @@ public class Testlesson35 {
}
@Test
public void testUnFaitSansFait() {
public void testAccumulate() throws Exception {
sessionStatefull = KnowledgeSessionHelper
.getStatefulKnowledgeSession(kieContainer, "lesson1-session");
.getStatefulKnowledgeSessionWithCallback(kieContainer, "lesson35-session");
OutputDisplay display = new OutputDisplay();
sessionStatefull.setGlobal("showResult", display);
sessionStatefull.insert(new Account(1, 0));
FactHandle fa = sessionStatefull.insert(new CashFlow(DateHelper.getDate("2010-01-15"), 1000, CashFlow.CREDIT, 1));
sessionStatefull.insert(new CashFlow(DateHelper.getDate("2010-02-15"), 500, CashFlow.DEBIT, 1));
sessionStatefull.insert(new CashFlow(DateHelper.getDate("2010-04-15"), 1000, CashFlow.CREDIT, 1));
sessionStatefull.insert(new AccountingPeriod(DateHelper.getDate("2010-01-01"), DateHelper.getDate("2010-12-31")));
sessionStatefull.fireAllRules();
sessionStatefull.delete(fa);
sessionStatefull.fireAllRules();
System.out.println("Did you see something ?");
}
}