Search in sources :

Example 1 with TMFileWithParentObj

use of org.drools.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.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" + "  System.out.println( $ic1 + \" \" + $ic2 );\n" + "  duplicateNames.add( $ic1.getName() );\n" + "end\n";
    final KieSession ksession = new KieHelper().addContent(drl, ResourceType.DRL).build().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) TMFileSet(org.drools.compiler.oopath.model.TMFileSet) Set(java.util.Set) ReactiveSet(org.drools.core.phreak.ReactiveSet) TMFileWithParentObj(org.drools.compiler.oopath.model.TMFileWithParentObj) KieHelper(org.kie.internal.utils.KieHelper) KieSession(org.kie.api.runtime.KieSession) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with TMFileWithParentObj

use of org.drools.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.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" + "  System.out.println( $ic1 + \" \" + $ic2 );\n" + "  duplicateNames.add( $ic1.getName() );\n" + "end\n";
    final KieSession ksession = new KieHelper().addContent(drl, ResourceType.DRL).build().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 : TMFileWithParentObj(org.drools.compiler.oopath.model.TMFileWithParentObj) KieHelper(org.kie.internal.utils.KieHelper) KieSession(org.kie.api.runtime.KieSession) TMFileSet(org.drools.compiler.oopath.model.TMFileSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

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