Work
This commit is contained in:
parent
0d40acdd39
commit
543772616c
7 changed files with 80 additions and 11 deletions
|
|
@ -51,3 +51,11 @@ rule "Exists"
|
||||||
then
|
then
|
||||||
showResult.showText("Account exists");
|
showResult.showText("Account exists");
|
||||||
end
|
end
|
||||||
|
rule "ForAll"
|
||||||
|
when
|
||||||
|
forall ( Account( $no : accountno )
|
||||||
|
CashFlow( accountNo == $no)
|
||||||
|
)
|
||||||
|
then
|
||||||
|
showResult.showText("All cashflows are related to an Account ");
|
||||||
|
end
|
||||||
|
|
@ -81,4 +81,37 @@ public class Testlesson31 {
|
||||||
sessionStatefull.insert(pAccount);
|
sessionStatefull.insert(pAccount);
|
||||||
sessionStatefull.fireAllRules();
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import droolscours.util.OutputDisplay;
|
||||||
global OutputDisplay showResult;
|
global OutputDisplay showResult;
|
||||||
global CustomerService serviceCustomer;
|
global CustomerService serviceCustomer;
|
||||||
|
|
||||||
rule "ForAll"
|
rule "FromCondition"
|
||||||
when
|
when
|
||||||
$c : Customer()
|
$c : Customer()
|
||||||
$cc : Customer(name ==$c.name,surname==$c.surname,country !=$c.country) from serviceCustomer.getListCustomer();
|
$cc : Customer(name ==$c.name,surname==$c.surname,country !=$c.country) from serviceCustomer.getListCustomer();
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package droolscours;
|
package droolscours;
|
||||||
|
|
||||||
|
import droolscours.service.CustomerService;
|
||||||
|
import droolscours.util.OutputDisplay;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.kie.api.runtime.KieContainer;
|
import org.kie.api.runtime.KieContainer;
|
||||||
|
|
@ -19,11 +21,15 @@ public class Testlesson33 {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnFaitSansFait() {
|
public void testFromLHS() throws Exception {
|
||||||
sessionStatefull = KnowledgeSessionHelper
|
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();
|
sessionStatefull.fireAllRules();
|
||||||
System.out.println("Did you see something ?");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
//#created on: 30 oct. 2010
|
|
||||||
package cours
|
package cours
|
||||||
|
|
||||||
//#list any import classes here.
|
//#list any import classes here.
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
package droolscours;
|
package droolscours;
|
||||||
|
|
||||||
|
import droolscours.util.OutputDisplay;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.kie.api.runtime.KieContainer;
|
import org.kie.api.runtime.KieContainer;
|
||||||
import org.kie.api.runtime.KieSession;
|
import org.kie.api.runtime.KieSession;
|
||||||
import org.kie.api.runtime.StatelessKieSession;
|
import org.kie.api.runtime.StatelessKieSession;
|
||||||
|
import util.DateHelper;
|
||||||
import util.KnowledgeSessionHelper;
|
import util.KnowledgeSessionHelper;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -19,11 +21,20 @@ public class Testlesson34 {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnFaitSansFait() {
|
public void testCollecting() throws Exception {
|
||||||
sessionStatefull = KnowledgeSessionHelper
|
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();
|
sessionStatefull.fireAllRules();
|
||||||
System.out.println("Did you see something ?");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,13 @@
|
||||||
package droolscours;
|
package droolscours;
|
||||||
|
|
||||||
|
import droolscours.util.OutputDisplay;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.kie.api.runtime.KieContainer;
|
import org.kie.api.runtime.KieContainer;
|
||||||
import org.kie.api.runtime.KieSession;
|
import org.kie.api.runtime.KieSession;
|
||||||
import org.kie.api.runtime.StatelessKieSession;
|
import org.kie.api.runtime.StatelessKieSession;
|
||||||
|
import org.kie.api.runtime.rule.FactHandle;
|
||||||
|
import util.DateHelper;
|
||||||
import util.KnowledgeSessionHelper;
|
import util.KnowledgeSessionHelper;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -19,11 +22,20 @@ public class Testlesson35 {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnFaitSansFait() {
|
public void testAccumulate() throws Exception {
|
||||||
sessionStatefull = KnowledgeSessionHelper
|
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();
|
sessionStatefull.fireAllRules();
|
||||||
System.out.println("Did you see something ?");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue