apupier commented on code in PR #21969:
URL: https://github.com/apache/camel/pull/21969#discussion_r2929734920


##########
core/camel-xml-io/src/test/java/org/apache/camel/xml/in/ModelParserTest.java:
##########
@@ -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());

Review Comment:
   using AssertJ assertions will allow to write it in a single assertion and 
have a more precise error message out of the box



##########
core/camel-xml-io/src/test/java/org/apache/camel/xml/in/ModelParserTest.java:
##########
@@ -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>";

Review Comment:
   using String text block will simplify this part



-- 
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]

Reply via email to