This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-2.21.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit c59276e0c3e95de86e13eafdff54998297c6b3d9
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Sat May 5 11:33:16 2018 +0200

    CAMEL-12483: route-coverage - Fixed issue with endChoice in CBR problem.
---
 .../parser/helper/CamelJavaTreeParserHelper.java   | 23 +++++++++---
 .../camel/parser/java/MyChoiceRouteBuilder.java    | 40 +++++++++++++++++++++
 .../RoasterChoiceRouteBuilderConfigureTest.java    | 41 ++++++++++++++++++++++
 3 files changed, 100 insertions(+), 4 deletions(-)

diff --git 
a/tooling/camel-route-parser/src/main/java/org/apache/camel/parser/helper/CamelJavaTreeParserHelper.java
 
b/tooling/camel-route-parser/src/main/java/org/apache/camel/parser/helper/CamelJavaTreeParserHelper.java
index 3d2ff1b..ac17d2f 100644
--- 
a/tooling/camel-route-parser/src/main/java/org/apache/camel/parser/helper/CamelJavaTreeParserHelper.java
+++ 
b/tooling/camel-route-parser/src/main/java/org/apache/camel/parser/helper/CamelJavaTreeParserHelper.java
@@ -118,10 +118,21 @@ public final class CamelJavaTreeParserHelper {
             } else if ("routeId".equals(name)) {
                 // should be set on the parent
                 parent.setRouteId(node.getRouteId());
-            } else if ("end".equals(name) || "endChoice".equals(name) || 
"endParent".equals(name) || "endRest".equals(name)
+            } else if ("end".equals(name) || "endParent".equals(name) || 
"endRest".equals(name)
                     || "endDoTry".equals(name) || "endHystrix".equals(name)) {
                 // parent should be grand parent
-                parent = parent.getParent();
+                if (parent.getParent() != null) {
+                    parent = parent.getParent();
+                }
+            } else if ("endChoice".equals(name)) {
+                // we are in a choice block so parent should be the first 
choice up the parent tree
+                while (!"from".equals(parent.getName()) && 
!"choice".equals(parent.getName())) {
+                    if (parent.getParent() != null) {
+                        parent = parent.getParent();
+                    } else {
+                        break;
+                    }
+                }
             } else if ("choice".equals(name)) {
                 // special for some EIPs
                 CamelNodeDetails output = nodeFactory.copyNode(parent, name, 
node);
@@ -129,8 +140,12 @@ public final class CamelJavaTreeParserHelper {
                 parent = output;
             } else if ("when".equals(name) || "otherwise".equals(name)) {
                 // we are in a choice block so parent should be the first 
choice up the parent tree
-                while (!parent.getName().equals("from") && 
!"choice".equals(parent.getName())) {
-                    parent = parent.getParent();
+                while (!"from".equals(parent.getName()) && 
!"choice".equals(parent.getName())) {
+                    if (parent.getParent() != null) {
+                        parent = parent.getParent();
+                    } else {
+                        break;
+                    }
                 }
             } else {
                 boolean hasOutput = hasOutput(name);
diff --git 
a/tooling/camel-route-parser/src/test/java/org/apache/camel/parser/java/MyChoiceRouteBuilder.java
 
b/tooling/camel-route-parser/src/test/java/org/apache/camel/parser/java/MyChoiceRouteBuilder.java
new file mode 100644
index 0000000..c67512a
--- /dev/null
+++ 
b/tooling/camel-route-parser/src/test/java/org/apache/camel/parser/java/MyChoiceRouteBuilder.java
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.parser.java;
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class MyChoiceRouteBuilder extends RouteBuilder {
+
+    @Override
+    public void configure() throws Exception {
+        from("timer:foo")
+            .choice()
+                .when(header("foo"))
+                    .to("log:foo")
+                .endChoice()
+                .when(header("bar"))
+                    .to("log:bar")
+                    .to("mock:bar")
+                .endChoice()
+                .otherwise()
+                    .to("log:other")
+                    .to("mock:other")
+                .end()
+            .to("log:end");
+    }
+}
diff --git 
a/tooling/camel-route-parser/src/test/java/org/apache/camel/parser/java/RoasterChoiceRouteBuilderConfigureTest.java
 
b/tooling/camel-route-parser/src/test/java/org/apache/camel/parser/java/RoasterChoiceRouteBuilderConfigureTest.java
new file mode 100644
index 0000000..21f8a0a
--- /dev/null
+++ 
b/tooling/camel-route-parser/src/test/java/org/apache/camel/parser/java/RoasterChoiceRouteBuilderConfigureTest.java
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.parser.java;
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.camel.parser.helper.CamelJavaTreeParserHelper;
+import org.apache.camel.parser.model.CamelNodeDetails;
+import org.jboss.forge.roaster.Roaster;
+import org.jboss.forge.roaster.model.source.JavaClassSource;
+import org.jboss.forge.roaster.model.source.MethodSource;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class RoasterChoiceRouteBuilderConfigureTest {
+
+    @Test
+    public void parse() throws Exception {
+        JavaClassSource clazz = (JavaClassSource) Roaster.parse(new 
File("src/test/java/org/apache/camel/parser/java/MyChoiceRouteBuilder.java"));
+        MethodSource<JavaClassSource> method = clazz.getMethod("configure");
+
+        List<CamelNodeDetails> list = new 
CamelJavaTreeParserHelper().parseCamelRouteTree(clazz, ".", 
"src/test/java/org/apache/camel/parser/java/MyChoiceRouteBuilder.java", method);
+        Assert.assertNotNull(list);
+    }
+
+}

-- 
To stop receiving notification emails like this one, please contact
davscl...@apache.org.

Reply via email to