use of org.drools.mvel.compiler.oopath.model.TMFileWithParentObj in project drools by kiegroup.
the class OOPathTest method testOOPathWithLocalInnerDeclaration.
@Test
public void testOOPathWithLocalInnerDeclaration() {
// DROOLS-1411
final String drl = "import org.drools.mvel.compiler.oopath.model.*;\n" + "import " + TMFileSetQuater.class.getCanonicalName() + ";\n" + "global java.util.Set duplicateNames; \n" + "\n" + "rule DIFF_FILES_BUT_WITH_SAME_FILENAME when\n" + " $ic1 : TMFileWithParentObj( $curName : name, $curId : id, \n" + " $ic2: /parent#TMFileSetQuater/files[name == $curName, id != $curId ] )\n" + "then\n" + " duplicateNames.add( $ic1.getName() );\n" + "end\n";
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, drl);
KieSession ksession = kbase.newKieSession();
final Set duplicateNames = new HashSet();
ksession.setGlobal("duplicateNames", duplicateNames);
final TMFileSetQuater x = new TMFileSetQuater("X");
final TMFileWithParentObj file0 = new TMFileWithParentObj(0, "File0", 47, x);
final TMFileWithParentObj file1 = new TMFileWithParentObj(1, "File1", 47, x);
final TMFileWithParentObj file2 = new TMFileWithParentObj(2, "File0", 47, x);
x.getFiles().addAll(Arrays.asList(file0, file1, file2));
ksession.insert(x);
ksession.insert(file0);
ksession.insert(file1);
ksession.insert(file2);
ksession.fireAllRules();
assertTrue(duplicateNames.contains("File0"));
assertFalse(duplicateNames.contains("File1"));
}
use of org.drools.mvel.compiler.oopath.model.TMFileWithParentObj in project drools by kiegroup.
the class OOPathTest method testOOPathWithLocalDeclaration.
@Test
public void testOOPathWithLocalDeclaration() {
// DROOLS-1411
final String drl = "import org.drools.mvel.compiler.oopath.model.*;\n" + "global java.util.Set duplicateNames; \n" + "\n" + "rule DIFF_FILES_BUT_WITH_SAME_FILENAME when\n" + " $ic1 : TMFileWithParentObj( $curName : name,\n" + " $ic2: /parent#TMFileSet/files[name == $curName, this != $ic1 ] )\n" + "then\n" + " duplicateNames.add( $ic1.getName() );\n" + "end\n";
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, drl);
KieSession ksession = kbase.newKieSession();
final Set<String> duplicateNames = new HashSet<>();
ksession.setGlobal("duplicateNames", duplicateNames);
final TMFileSet x = new TMFileSet("X");
final TMFileWithParentObj file0 = new TMFileWithParentObj(0, "File0", 47, x);
final TMFileWithParentObj file1 = new TMFileWithParentObj(1, "File1", 47, x);
final TMFileWithParentObj file2 = new TMFileWithParentObj(2, "File0", 47, x);
x.getFiles().addAll(Arrays.asList(file0, file1, file2));
ksession.insert(x);
ksession.insert(file0);
ksession.insert(file1);
ksession.insert(file2);
ksession.fireAllRules();
assertTrue(duplicateNames.contains("File0"));
assertFalse(duplicateNames.contains("File1"));
}
Aggregations