[jboss-jira] [JBoss JIRA] (DROOLS-1219) ClassObjectTypes are not all correctly rewired during a packages merge
Mario Fusco (JIRA)
issues at jboss.org
Fri Jun 24 11:40:00 EDT 2016
Mario Fusco created DROOLS-1219:
-----------------------------------
Summary: ClassObjectTypes are not all correctly rewired during a packages merge
Key: DROOLS-1219
URL: https://issues.jboss.org/browse/DROOLS-1219
Project: Drools
Issue Type: Bug
Components: core engine
Reporter: Mario Fusco
Assignee: Mario Fusco
As demonstrated by the following not all ClassObjectTypes are correctly rewired during a package merge. In that case R2 doesn't fire because the ClassObjectType used by the from pattern is not rewired to the new Class instance created by the second ProjectClassLoader.
{code}
@Test
public void testWiringClassOnPackageMerge() throws Exception {
String drl_init =
"package init;\n" +
"import org.kie.test.TestObject\n" +
"rule RInit when\n" +
"then\n" +
" TestObject obj1 = new TestObject();\n" +
" TestObject obj2 = new TestObject();" +
" obj1.add(obj2);" +
" insert(obj1);\n" +
"end";
String drl1 =
"package p1;\n" +
"import org.kie.test.TestObject\n" +
"global java.util.List list;\n" +
"rule R1 when\n" +
" $obj : TestObject( $objs : objects )\n" +
" $s : Object() from $objs\n" +
"then\n" +
" list.add(\"R1\");\n" +
"end";
String drl2 =
"package p2;\n" +
"import org.kie.test.TestObject\n" +
"global java.util.List list;\n" +
"rule R2 when\n" +
" $obj : TestObject( $objs : objects )\n" +
" $s : TestObject() from $objs\n" +
"then\n" +
" list.add(\"R2\");\n" +
"end";
String javaSrc =
"package org.kie.test;\n" +
"import java.util.*;\n" +
"\n" +
"public class TestObject {\n" +
" private final List<TestObject> objects = new ArrayList<TestObject>();\n" +
"\n" +
" public List<TestObject> getObjects() {\n" +
" return objects;\n" +
" }\n" +
" public void add(TestObject obj) {\n" +
" objects.add(obj);" +
" }" +
"}\n";
String path = "org/kie/test/MyRuleUnit";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
kfs.writeKModuleXML(ks.newKieModuleModel().toXML())
.write("src/main/resources/a.drl", drl_init)
.write("src/main/resources/b.drl", drl1)
.write("src/main/resources/c.drl", drl2)
.write("src/main/java/org/kie/test/TestObject.java", javaSrc);
ks.newKieBuilder( kfs ).buildAll();
KieContainer kcontainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
KieSession kSession = kcontainer.newKieSession();
List<String> list = new ArrayList<String>();
kSession.setGlobal( "list", list );
kSession.fireAllRules();
assertEquals( 2, list.size() );
assertTrue( list.contains( "R1" ) );
assertTrue( list.contains( "R2" ) );
}
{code}
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
More information about the jboss-jira
mailing list