[jboss-jira] [JBoss JIRA] (DROOLS-1411) OOPath constraint bugs emerged during dogfooding

Matteo Mortari (JIRA) issues at jboss.org
Thu Jan 19 03:29:00 EST 2017


    [ https://issues.jboss.org/browse/DROOLS-1411?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13350840#comment-13350840 ] 

Matteo Mortari commented on DROOLS-1411:
----------------------------------------

Full recap of the splitted in the subtasks:

{code:java}
    @Test
    public void testWronglyMatchAlsoEquals() {
        String drl =
                "import org.drools.compiler.xpath.*;\n" +
                "global java.util.Set duplicateNames; \n" +
                "\n" +
                "rule DIFF_FILES_BUT_WITH_SAME_FILENAME when\n" +
                "  $dir1 : TMFileSet( $ic1 : /files )\n" + 
                "  TMFileSet( this == $dir1, $ic2 : /files{name == $ic1.name}, $ic1 != $ic2 )\n" +
                "then\n" +
                "  System.out.println( $dir1 + \".: \" + $ic1 + \" \" + $ic2 );\n" +
                "  duplicateNames.add( $ic1.getName() );\n" +
                "end\n";

        KieSession ksession = new KieHelper().addContent( drl, ResourceType.DRL )
                                             .build()
                                             .newKieSession();
        
        Set duplicateNames = new HashSet();
        ksession.setGlobal("duplicateNames", duplicateNames);
        
        TMFileSet x = new TMFileSet("X");
        TMFile file0 = new TMFile("File0", 47);
        TMFile file1 = new TMFile("File1", 47);
        TMFile file2 = new TMFile("File0", 47);
        x.getFiles().addAll(Arrays.asList(new TMFile[]{file0, file1, file2}));
        
        ksession.insert(x);
        ksession.fireAllRules();
        
        assertTrue( duplicateNames.contains("File0") );
        assertFalse( duplicateNames.contains("File1") );
    }
    
    @Test
    public void testWronglyMatchAlsoEqualsBis() {
        String drl =
                "import org.drools.compiler.xpath.*;\n" +
                "global java.util.Set duplicateNames; \n" +
                "\n" +
                "rule DIFF_FILES_BUT_WITH_SAME_FILENAME when\n" +
                "  $dir1 : TMFileSet( $ic1 : /files, $ic2 : /files{name == $ic1.name}, $ic1 != $ic2 )\n" +
                "then\n" +
                "  System.out.println( $dir1 + \".: \" + $ic1 + \" \" + $ic2 );\n" +
                "  duplicateNames.add( $ic1.getName() );\n" +
                "end\n";

        KieSession ksession = new KieHelper().addContent( drl, ResourceType.DRL )
                                             .build()
                                             .newKieSession();
        
        Set duplicateNames = new HashSet();
        ksession.setGlobal("duplicateNames", duplicateNames);
        
        TMFileSet x = new TMFileSet("X");
        TMFile file0 = new TMFile("File0", 47);
        TMFile file1 = new TMFile("File1", 47);
        TMFile file2 = new TMFile("File0", 47);
        x.getFiles().addAll(Arrays.asList(new TMFile[]{file0, file1, file2}));
        
        ksession.insert(x);
        ksession.fireAllRules();
        
        assertTrue( duplicateNames.contains("File0") );
        assertFalse( duplicateNames.contains("File1") );
    }
    
    @Test
    public void testWronglyMatchAlsoEqualsTris() {
        String drl =
                "import org.drools.compiler.xpath.*;\n" +
                "global java.util.Set duplicateNames; \n" +
                "\n" +
                "rule DIFF_FILES_BUT_WITH_SAME_FILENAME when\n" +
                "  $ic1 : TMFileWithParentObj( parent instanceof TMFileSet ,\n" + 
                "                              $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";

        KieSession ksession = new KieHelper().addContent( drl, ResourceType.DRL )
                                             .build()
                                             .newKieSession();
        
        Set duplicateNames = new HashSet();
        ksession.setGlobal("duplicateNames", duplicateNames);
        
        TMFileSet x = new TMFileSet("X");
        TMFileWithParentObj file0 = new TMFileWithParentObj(0, "File0", 47, x);
        TMFileWithParentObj file1 = new TMFileWithParentObj(1, "File1", 47, x);
        TMFileWithParentObj file2 = new TMFileWithParentObj(2, "File0", 47, x);
        x.getFiles().addAll(Arrays.asList(new TMFile[]{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") );
    }
    
    public static class TMFileSetQuater extends AbstractReactiveObject {
        private final String name;
        private final Set<TMFileWithParentObj> members = new ReactiveSet<TMFileWithParentObj>();
        public TMFileSetQuater(String name) {
            this.name = name;
        }
        public String getName() {
            return name;
        }
        public Set<TMFileWithParentObj> getFiles() {
            return members;
        }
    }
    
    @Test
    public void testWronglyMatchAlsoEqualsQuater() {
        String drl =
                "import org.drools.compiler.xpath.*;\n" +
                "import "+TMFileSetQuater.class.getCanonicalName()+";\n" +
                "global java.util.Set duplicateNames; \n" +
                "\n" +
                "rule DIFF_FILES_BUT_WITH_SAME_FILENAME when\n" +
                "  $ic1 : TMFileWithParentObj( parent instanceof TMFileSetQuater ,\n" + 
                "                              $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";

        KieSession ksession = new KieHelper().addContent( drl, ResourceType.DRL )
                                             .build()
                                             .newKieSession();
        
        Set duplicateNames = new HashSet();
        ksession.setGlobal("duplicateNames", duplicateNames);
        
        TMFileSetQuater x = new TMFileSetQuater("X");
        TMFileWithParentObj file0 = new TMFileWithParentObj(0, "File0", 47, x);
        TMFileWithParentObj file1 = new TMFileWithParentObj(1, "File1", 47, x);
        TMFileWithParentObj file2 = new TMFileWithParentObj(2, "File0", 47, x);
        x.getFiles().addAll(Arrays.asList(new TMFileWithParentObj[]{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") );
    }
{code}


> OOPath constraint bugs emerged during dogfooding
> ------------------------------------------------
>
>                 Key: DROOLS-1411
>                 URL: https://issues.jboss.org/browse/DROOLS-1411
>             Project: Drools
>          Issue Type: Bug
>            Reporter: Matteo Mortari
>            Assignee: Matteo Mortari
>
> Misc OOPath constraint bugs emerged during dogfooding using in DMN Validation rules



--
This message was sent by Atlassian JIRA
(v7.2.3#72005)


More information about the jboss-jira mailing list