-
Notifications
You must be signed in to change notification settings - Fork 5.1k
CAMEL-22884: Validate method attribute placement in when clause #21969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -449,6 +449,52 @@ public void testParseError() throws Exception { | |
| assertTrue(e.getMessage().startsWith("Unexpected attribute '{}ref'")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testMethodAfterStepsInWhenClauseShouldFail() throws Exception { | ||
| String routesXml = "<routes xmlns=\"http://camel.apache.org/schema/xml-io\">" | ||
| + " <route>" | ||
| + " <from uri=\"direct:start\"/>" | ||
| + " <choice>" | ||
| + " <when>" | ||
| + " <simple>${header.foo} == 'bar'</simple>" | ||
| + " <log message=\"Condition met\"/>" | ||
| + " <method ref=\"someBean\" method=\"processFooBar\"/>" | ||
| + " </when>" | ||
| + " <otherwise>" | ||
| + " <to uri=\"mock:other\"/>" | ||
| + " </otherwise>" | ||
| + " </choice>" | ||
| + " </route>" | ||
| + "</routes>"; | ||
| Exception e = assertThrows(Exception.class, () -> { | ||
| new ModelParser(new StringReader(routesXml)).parseRoutesDefinition(); | ||
| }); | ||
| assertTrue(e.getMessage().contains("already has a predicate") | ||
| || e.getCause().getMessage().contains("already has a predicate"), | ||
| "Error message should indicate that the when clause already has a predicate: " + e.getMessage()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testMethodAsPredicateInWhenClauseShouldWork() throws Exception { | ||
| String routesXml = "<routes xmlns=\"http://camel.apache.org/schema/xml-io\">" | ||
| + " <route>" | ||
| + " <from uri=\"direct:start\"/>" | ||
| + " <choice>" | ||
| + " <when>" | ||
| + " <method ref=\"someBean\" method=\"isFoo\"/>" | ||
| + " <to uri=\"mock:foo\"/>" | ||
| + " </when>" | ||
| + " <otherwise>" | ||
| + " <to uri=\"mock:other\"/>" | ||
| + " </otherwise>" | ||
| + " </choice>" | ||
| + " </route>" | ||
| + "</routes>"; | ||
| RoutesDefinition routes = new ModelParser(new StringReader(routesXml)).parseRoutesDefinition().orElse(null); | ||
| assertNotNull(routes); | ||
| assertEquals(1, routes.getRoutes().size()); | ||
|
Comment on lines
+497
to
+498
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using AssertJ assertions will allow to write it in a single assertion and have a more precise error message out of the box
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done — replaced with
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this comment was for another piece of code |
||
| } | ||
|
|
||
| private Path getResourceFolder() { | ||
| final URL resource = getClass().getClassLoader().getResource("barInterceptorRoute.xml"); | ||
| assert resource != null : "Cannot find barInterceptorRoute.xml"; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.