Skip to content

Commit

Permalink
[DROOLS-1564] change oopath syntax (kiegroup#963)
Browse files Browse the repository at this point in the history
  • Loading branch information
mariofusco authored May 17, 2017
1 parent 84af44d commit 29294d2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ end

rule "give a dog to an adult person without a dog"
when
person: Person( /age{ this >= 18 } )
not Person( this == person, /pets{ #Dog } )
person: Person( /age[ this >= 18 ] )
not Person( this == person, /pets#Dog )
then
person.addPet(new Dog("Lassie", 1));
end

rule "give a cat to an adult person without a cat"
when
person: Person( /age{ this >= 18 } )
not Person( this == person, /pets{ #Cat } )
person: Person( /age[ this >= 18 ] )
not Person( this == person, /pets#Cat )
then
person.addPet(new Cat("The Cat", 1));
end
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
package org.drools.compiler.xpath.tobeinstrumented;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;

import org.drools.compiler.xpath.tobeinstrumented.model.*;
import javassist.ClassPool;
import javassist.CtClass;
import org.drools.compiler.xpath.tobeinstrumented.model.Child;
import org.drools.compiler.xpath.tobeinstrumented.model.Man;
import org.drools.compiler.xpath.tobeinstrumented.model.PojoWithCollections;
import org.drools.compiler.xpath.tobeinstrumented.model.School;
import org.drools.compiler.xpath.tobeinstrumented.model.TMDirectory;
import org.drools.compiler.xpath.tobeinstrumented.model.TMFile;
import org.drools.compiler.xpath.tobeinstrumented.model.TMFileSet;
import org.drools.compiler.xpath.tobeinstrumented.model.Toy;
import org.drools.compiler.xpath.tobeinstrumented.model.Woman;
import org.drools.core.base.ClassObjectType;
import org.drools.core.common.InternalWorkingMemory;
import org.drools.core.impl.InternalKnowledgeBase;
Expand All @@ -20,24 +35,7 @@
import org.drools.core.reteoo.ReactiveFromNode;
import org.drools.core.reteoo.TupleMemory;
import org.drools.core.util.Iterator;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.kie.api.KieBase;
import org.kie.api.io.ResourceType;
Expand All @@ -47,10 +45,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javassist.CannotCompileException;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.NotFoundException;
import static org.junit.Assert.*;

public class XPathTest {
private static final Logger LOG = LoggerFactory.getLogger(XPathTest.class);
Expand Down Expand Up @@ -136,7 +131,7 @@ public void testReactiveOnLia() {
"global java.util.List list\n" +
"\n" +
"rule R when\n" +
" Man( $toy: /wife/children{age > 10}/toys )\n" +
" Man( $toy: /wife/children[age > 10]/toys )\n" +
"then\n" +
" list.add( $toy.getName() );\n" +
"end\n";
Expand Down Expand Up @@ -186,7 +181,7 @@ public void testReactiveDeleteOnLia() {
"global java.util.List list\n" +
"\n" +
"rule R when\n" +
" Man( $toy: /wife/children{age > 10}/toys )\n" +
" Man( $toy: /wife/children[age > 10]/toys )\n" +
"then\n" +
" list.add( $toy.getName() );\n" +
"end\n";
Expand Down Expand Up @@ -262,7 +257,7 @@ public void testReactiveOnBeta() {
"\n" +
"rule R when\n" +
" $i : Integer()\n" +
" Man( $toy: /wife/children{age > $i}?/toys )\n" +
" Man( $toy: /wife/children[age > $i]?/toys )\n" +
"then\n" +
" list.add( $toy.getName() );\n" +
"end\n";
Expand Down Expand Up @@ -315,12 +310,12 @@ public void testReactive2Rules() {
"\n" +
"rule R1 when\n" +
" $i : Integer()\n" +
" Man( $toy: /wife/children{age >= $i}/toys )\n" +
" Man( $toy: /wife/children[age >= $i]/toys )\n" +
"then\n" +
" toyList.add( $toy.getName() );\n" +
"end\n" +
"rule R2 when\n" +
" School( $child: /children{age >= 13} )\n" +
" School( $child: /children[age >= 13] )\n" +
"then\n" +
" teenagers.add( $child.getName() );\n" +
"end\n";
Expand Down Expand Up @@ -384,7 +379,7 @@ public void testListReactive() {
"import org.drools.compiler.xpath.tobeinstrumented.model.*;\n" +
"\n" +
"rule R2 when\n" +
" School( $child: /children{age >= 13 && age < 20} )\n" +
" School( $child: /children[age >= 13 && age < 20] )\n" +
"then\n" +
" System.out.println( $child );\n" +
" insertLogical( $child );\n" +
Expand Down Expand Up @@ -440,7 +435,7 @@ public void testMiscSetMethods() {
"import org.drools.compiler.xpath.tobeinstrumented.model.*;\n" +
"\n" +
"rule R2 when\n" +
" TMFileSet( $id: name, $p: /files{size >= 100} )\n" +
" TMFileSet( $id: name, $p: /files[size >= 100] )\n" +
"then\n" +
" System.out.println( $id + \".\" + $p.getName() );\n" +
" insertLogical( $id + \".\" + $p.getName() );\n" +
Expand Down Expand Up @@ -514,7 +509,7 @@ public void testMiscListMethods() {
"import org.drools.compiler.xpath.tobeinstrumented.model.*;\n" +
"\n" +
"rule R2 when\n" +
" TMDirectory( $id: name, $p: /files{size >= 100} )\n" +
" TMDirectory( $id: name, $p: /files[size >= 100] )\n" +
"then\n" +
" System.out.println( $id + \".\" + $p.getName() );\n" +
" insertLogical( $id + \".\" + $p.getName() );\n" +
Expand Down

0 comments on commit 29294d2

Please sign in to comment.