CAMEL-22884: Validate method attribute placement in when clause#21969
CAMEL-22884: Validate method attribute placement in when clause#21969
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
core/camel-xml-io/src/test/java/org/apache/camel/xml/in/ModelParserTest.java
Outdated
Show resolved
Hide resolved
| assertNotNull(routes); | ||
| assertEquals(1, routes.getRoutes().size()); |
There was a problem hiding this comment.
using AssertJ assertions will allow to write it in a single assertion and have a more precise error message out of the box
There was a problem hiding this comment.
Done — replaced with assertThat(e).hasStackTraceContaining("already has a predicate") in 577b5cb.
There was a problem hiding this comment.
this comment was for another piece of code
| <choice> | ||
| <when> | ||
| <method ref="someBean" method="isFoo"/> | ||
| <to uri="mock:foo"/> |
There was a problem hiding this comment.
Would it be good to add a here as the exception message tells
There was a problem hiding this comment.
Good idea — adding a <bean id="someBean" type="..."/> would make the test XML more realistic, even though this is purely a parser-level test (no runtime resolution). I'll update both test methods.
There was a problem hiding this comment.
Actually, on second thought — <bean> declarations live at the <camel> root level, not inside <routes>. This test uses parseRoutesDefinition() which expects <routes> as root. Restructuring to use a <camel> wrapper would require a different parse method and adds complexity for a purely parser-level test where bean refs aren't resolved. Happy to change it if you still think it's worth it, but I'd lean toward keeping it simple since the test is only validating XML structure parsing, not runtime behavior.
apupier
left a comment
There was a problem hiding this comment.
- not sure to understand the comments on https://github.com/apache/camel/pull/21969/changes#r2935840734 , so I keep it to you to evaluate if that's fine or not.
- one of my comment was not adressed (despite being marked as resolved with an unrelated comment) but it is not very important, just a nicer to have.
…he#21969) * CAMEL-22884: Validate method attribute placement in when clause Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * CAMEL-22884: Address review comments - use text blocks and AssertJ --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Summary
BasicOutputExpressionNode.setExpression()to detect when an expression element (e.g.<method>) appears after processing steps inside a<when>clause in XML/YAML DSL<method>element placed after<log>or other steps in a<when>clause would silently overwrite the predicate expression instead of being treated as a processor or raising an errorExpressionClauseis legitimately resolved to the actual expression duringpreCreateProcessor()Test plan
testMethodAfterStepsInWhenClauseShouldFailto verify that placing<method>after processing steps in a<when>clause raises an errortestMethodAsPredicateInWhenClauseShouldWorkto verify that<method>as the first (and only expression) child of<when>still works correctly