mariofusco commented on code in PR #6788:
URL:
https://github.com/apache/incubator-kie-drools/pull/6788#discussion_r3511080528
##########
drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/DeclaredTypesTest.java:
##########
@@ -599,6 +607,42 @@ public void testExtendPojo(RUN_TYPE runType) throws
Exception {
assertThat(ksession.fireAllRules()).isEqualTo(1);
}
+ @ParameterizedTest
+ @MethodSource("parametersPatternOnly")
+ public void
testUnparseableConstraintInUnnamedPatternIsLoggedWithContext(RUN_TYPE runType) {
+ // When the pattern auto-naming pre-pass
(ClassPatternDSL.findFirstInnerBinding) hits a
+ // constraint it cannot parse, it must not fail with a bare
"unexpected token:" that hides which
+ // rule is at fault. It now logs a WARN naming the rule and the
offending expression, then skips
+ // it; the real constraint compilation still rejects it (that abort is
unchanged and correct).
+ // 'class == X.class' is rejected by the executable-model DRLX
grammar, so it triggers the path.
+ // Executable-model only: the classic compiler accepts 'class ==' and
never reaches this pre-pass.
+ Logger logger = (Logger)
LoggerFactory.getLogger(ClassPatternDSL.class);
+ ListAppender<ILoggingEvent> appender = new ListAppender<>();
+ appender.start();
+ logger.addAppender(appender);
+ try {
+ String str =
+ "package org.test;\n" +
+ "import " + Person.class.getCanonicalName() + ";\n" +
+ "import " + Child.class.getCanonicalName() + ";\n" +
+ "rule R when\n" +
+ " Person( class == Child.class )\n" +
+ "then end";
+ try {
+ createKieBuilder(runType, str);
+ } catch (RuntimeException expected) {
+ // The real constraint compilation still rejects 'class ==
...'; that abort is unchanged.
+ }
+ assertThat(appender.list)
+ .as("a WARN naming the rule and the offending constraint
expression must be logged")
+ .anyMatch(e -> e.getLevel() == Level.WARN
+ && e.getFormattedMessage().contains("rule 'R'")
+ &&
e.getFormattedMessage().contains("Child.class"));
+ } finally {
+ logger.detachAppender(appender);
+ }
Review Comment:
I agree also with this.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]