Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Test
- public void testRecursiveNotQuery() {
- String drl =
- "import org.drools.compiler.xpath.Thing;\n" +
- "global java.util.List list\n" +
- "\n" +
- "rule \"Print all things contained in the Office\" when\n" +
- " $office : Thing( name == \"office\" )\n" +
- " isNotContainedIn( $office, thing; )\n" +
- "then\n" +
- " list.add( thing.getName() );\n" +
- "end\n" +
- "\n" +
- "query isContainedIn( Thing $x, Thing $y )\n" +
- " $y := Thing() from $x.getChildren()\n" +
- "or\n" +
- " ( $z := Thing() from $x.getChildren() and isContainedIn( $z, $y; ) )\n" +
- "end\n" +
- "\n" +
- "query isNotContainedIn( Thing $x, Thing $y )\n" +
- " not( isContainedIn( $x, $y; ) )\n" +
- "end\n";
- Thing house = new Thing( "house" );
- Thing office = new Thing( "office" );
- house.addChild( office );
- Thing kitchen = new Thing( "kitchen" );
- house.addChild( kitchen );
- Thing knife = new Thing( "knife" );
- kitchen.addChild( knife );
- Thing cheese = new Thing( "cheese" );
- kitchen.addChild( cheese );
- Thing desk = new Thing( "desk" );
- office.addChild( desk );
- Thing chair = new Thing( "chair" );
- office.addChild( chair );
- Thing computer = new Thing( "computer" );
- desk.addChild( computer );
- Thing draw = new Thing( "draw" );
- desk.addChild( draw );
- Thing key = new Thing( "key" );
- draw.addChild( key );
- KieSession ksession = new KieHelper().addContent( drl, ResourceType.DRL )
- .build()
- .newKieSession();
- List<String> list = new ArrayList<String>();
- ksession.setGlobal( "list", list );
- ksession.insert(house);
- ksession.insert(office);
- ksession.insert(kitchen);
- ksession.insert(knife);
- ksession.insert(cheese);
- ksession.insert(desk);
- ksession.insert(chair);
- ksession.insert(computer);
- ksession.insert(draw);
- ksession.insert(key);
- ksession.fireAllRules();
- System.out.println(list);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement