Search in sources :

Example 1 with TMFileWithParentObj

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"));
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) TMFileSet(org.drools.mvel.compiler.oopath.model.TMFileSet) ReactiveSet(org.drools.core.phreak.ReactiveSet) KieBase(org.kie.api.KieBase) TMFileWithParentObj(org.drools.mvel.compiler.oopath.model.TMFileWithParentObj) KieSession(org.kie.api.runtime.KieSession) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with TMFileWithParentObj

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"));
}
Also used : KieBase(org.kie.api.KieBase) TMFileWithParentObj(org.drools.mvel.compiler.oopath.model.TMFileWithParentObj) KieSession(org.kie.api.runtime.KieSession) TMFileSet(org.drools.mvel.compiler.oopath.model.TMFileSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

HashSet (java.util.HashSet)2 TMFileSet (org.drools.mvel.compiler.oopath.model.TMFileSet)2 TMFileWithParentObj (org.drools.mvel.compiler.oopath.model.TMFileWithParentObj)2 Test (org.junit.Test)2 KieBase (org.kie.api.KieBase)2 KieSession (org.kie.api.runtime.KieSession)2 Set (java.util.Set)1 ReactiveSet (org.drools.core.phreak.ReactiveSet)1