use of org.drools.core.ObjectFilter in project drools by kiegroup.
the class TraitTest method testNodePartitioningByProxiesAfterShed.
@Test
public void testNodePartitioningByProxiesAfterShed() {
String source = "package t.x " + "import java.util.*; " + "import org.drools.core.factmodel.traits.Thing " + "import org.drools.core.factmodel.traits.Traitable " + " " + "global java.util.List list; " + " " + "" + "declare trait A end " + "declare trait B extends A end " + "declare trait C extends B end " + "declare trait D extends A end " + "declare trait E extends C, D end " + "declare trait F extends E end " + "declare trait G extends A end " + "" + "declare Kore " + " @Traitable " + "end " + "" + "rule Init when " + "then " + " Kore k = new Kore(); " + " don( k, C.class ); " + " don( k, D.class ); " + " don( k, B.class ); " + " don( k, A.class ); " + " don( k, F.class ); " + " don( k, E.class ); " + " don( k, G.class ); " + " shed( k, B.class ); " + "end ";
for (char c = 'A'; c <= 'G'; c++) {
String C = "" + c;
source += "rule Rule" + C + " when " + C + "() then list.add( '" + C + "' ); end ";
}
source += "rule RuleAll " + "when " + " A() D() G() " + "then " + " list.add( 'Z' ); " + "end " + "";
KieSession ks = getSessionFromString(source);
TraitFactory.setMode(mode, ks.getKieBase());
List list = new ArrayList();
ks.setGlobal("list", list);
ks.fireAllRules();
System.out.println(list);
assertEquals(Arrays.asList('A', 'D', 'G', 'Z'), list);
for (Object o : ks.getObjects(new ObjectFilter() {
@Override
public boolean accept(Object object) {
return object instanceof TraitableBean;
}
})) {
Set<BitSet> otns = checkOTNPartitioning((TraitableBean) o, ks);
assertEquals(3, otns.size());
}
}
use of org.drools.core.ObjectFilter in project drools by kiegroup.
the class TraitTest method testNodePartitioningByProxies.
@Test
public void testNodePartitioningByProxies() {
String source = "package t.x " + "import java.util.*; " + "import org.drools.core.factmodel.traits.Thing " + "import org.drools.core.factmodel.traits.Traitable " + " " + "global java.util.List list; " + " " + "" + "declare trait A @PropertyReactive end " + "declare trait B extends A @PropertyReactive end " + "declare trait C extends B @PropertyReactive end " + "declare trait D extends A @PropertyReactive end " + "declare trait E extends C, D @PropertyReactive end " + "declare trait F extends E @PropertyReactive end " + "declare trait G extends A @PropertyReactive end " + "" + "declare Kore " + " @Traitable " + "end " + "" + "rule Init when " + "then " + " Kore k = new Kore(); " + " don( k, C.class ); " + " don( k, D.class ); " + " don( k, B.class ); " + " don( k, A.class ); " + " don( k, F.class ); " + " don( k, E.class ); " + " don( k, G.class ); " + "end ";
for (char c = 'A'; c <= 'G'; c++) {
String C = "" + c;
source += "rule Rule" + C + " when " + C + "() then list.add( '" + C + "' ); end ";
}
source += "rule RuleAll " + "when " + " A() B() C() D() E() F() G() " + "then " + " list.add( 'Z' ); " + "end " + "";
KieSession ks = getSessionFromString(source);
TraitFactory.setMode(mode, ks.getKieBase());
List list = new ArrayList();
ks.setGlobal("list", list);
ks.fireAllRules();
System.out.println(list);
assertEquals(Arrays.asList('A', 'B', 'C', 'D', 'E', 'F', 'G', 'Z'), list);
for (Object o : ks.getObjects(new ObjectFilter() {
@Override
public boolean accept(Object object) {
return object instanceof TraitableBean;
}
})) {
Set<BitSet> otns = checkOTNPartitioning((TraitableBean) o, ks);
assertEquals(7, otns.size());
}
}
use of org.drools.core.ObjectFilter in project drools by kiegroup.
the class TraitTest method testTupleIntegrityOnModification.
@Test
public void testTupleIntegrityOnModification() {
String drl = "package test " + "import " + Entity.class.getName() + ";" + "global java.util.List list; " + "declare trait A @propertyReactive value : int end " + "rule Trait when " + " $core: Entity( ) " + "then " + " A o = don( $core, A.class ); " + " System.out.println( 'Found ! ' + o ); " + "end " + "rule Test when " + " $x: A( value == 0 ) " + "then " + " list.add( 0 ); " + "end " + "rule Check when " + " $x: A( value == 42 ) " + "then " + " list.add( 42 ); " + "end " + "rule Mood when " + " $x : A( value != 42 ) " + "then " + " modify ( $x ) { setValue( 42 ); } " + "end ";
KieBase kbase = getKieBaseFromString(drl);
TraitFactory.setMode(mode, kbase);
KieSession ksession = kbase.newKieSession();
List list = new ArrayList();
ksession.setGlobal("list", list);
ksession.insert(new Entity());
ksession.fireAllRules();
for (final Object o : ksession.getObjects(new ObjectFilter() {
@Override
public boolean accept(Object object) {
return object.getClass().getName().contains("test.A");
}
})) {
InternalFactHandle handle = (InternalFactHandle) ksession.getFactHandle(o);
LeftTuple first = handle.getFirstLeftTuple();
assertTrue(first instanceof RuleTerminalNodeLeftTuple);
assertEquals("Check", ((RuleTerminalNodeLeftTuple) first).getRule().getName());
}
assertEquals(Arrays.asList(0, 42), list);
}
Aggregations