-
Sub-task
-
Resolution: Done
-
Major
-
7.37.0.Final
-
None
-
2020 Week 19-21 (from May 4), 2020 Week 22-24 (from May 25), 2020 Week 25-27 (from Jun 15), 2020 Week 28-30 (from Jul 6)
-
2
-
NEW
-
NEW
Currently "lambda is not externalized" issue is not widely detected in unit tests. We need to write a specific assertion like this:
@Test public void testExternalizeBindingVariableLambda() throws Exception { String str = "package defaultpkg;\n" + "import " + Person.class.getCanonicalName() + ";" + "global java.util.List list;\n" + "rule R when\n" + " $p : Person($n : name == \"Mario\")\n" + "then\n" + " list.add($n);\n" + "end"; KieModuleModel kieModuleModel = KieServices.get().newKieModuleModel(); kieModuleModel.setConfigurationProperty("drools.externaliseCanonicalModelLambda", Boolean.TRUE.toString()); KieSession ksession = getKieSession(kieModuleModel, str ); final List<String> list = new ArrayList<>(); ksession.setGlobal("list", list); if (testRunType == RUN_TYPE.FLOW_DSL || testRunType == RUN_TYPE.PATTERN_DSL) { RuleImpl rule = (RuleImpl)ksession.getKieBase().getRule("defaultpkg", "R"); Pattern pattern = (Pattern)rule.getLhs().getChildren().get(0); Declaration declaration = pattern.getDeclarations().get("$n"); LambdaReadAccessor lambdaReadAccessor = (LambdaReadAccessor)declaration.getExtractor(); Field field = LambdaReadAccessor.class.getDeclaredField("lambda"); field.setAccessible(true); Function1.Impl function1 = (Function1.Impl)field.get(lambdaReadAccessor); Object lambda = function1.getLambda(); assertThat(lambda.getClass().getName(), containsString("LambdaExtractor")); // materialized Lambda } Person me = new Person( "Mario", 40 ); ksession.insert( me ); ksession.fireAllRules(); Assertions.assertThat(list).containsExactlyInAnyOrder("Mario"); }
This JIRA is to enhance unit tests to assert it widely.