[jboss-jira] [JBoss JIRA] (DROOLS-5346) Enhance unit test to ditect non-externalized lambda easier
Toshiya Kobayashi (Jira)
issues at jboss.org
Tue May 19 04:35:33 EDT 2020
Toshiya Kobayashi created DROOLS-5346:
-----------------------------------------
Summary: Enhance unit test to ditect non-externalized lambda easier
Key: DROOLS-5346
URL: https://issues.redhat.com/browse/DROOLS-5346
Project: Drools
Issue Type: Sub-task
Components: executable model
Affects Versions: 7.37.0.Final
Reporter: Toshiya Kobayashi
Assignee: Luca Molteni
Currently "lambda is not externalized" issue is not widely detected in unit tests. We need to write a specific assertion like this:
{code:java}
@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");
}
{code}
This JIRA is to enhance unit tests to assert it widely.
--
This message was sent by Atlassian Jira
(v7.13.8#713008)
More information about the jboss-jira
mailing list