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

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


The following commit(s) were added to refs/heads/main by this push:
     new 7b7787e26428 chore: camel-jbang - the route tree shows the otherwise 
of a Switch as otherwise[..], not to: otherwise[..] (#27252)
7b7787e26428 is described below

commit 7b7787e2642835527f939032b715f1210304ebb2
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Oct 2 08:45:44 2026 +0200

    chore: camel-jbang - the route tree shows the otherwise of a Switch as 
otherwise[..], not to: otherwise[..] (#27252)
    
    Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
---
 .../jbang/core/commands/tui/RouteTreePreview.java  |  7 ++++++
 .../core/commands/tui/RouteTreePreviewTest.java    | 25 ++++++++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/RouteTreePreview.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/RouteTreePreview.java
index 05b848f1c120..f35170a622bc 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/RouteTreePreview.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/RouteTreePreview.java
@@ -19,6 +19,7 @@ package org.apache.camel.dsl.jbang.core.commands.tui;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
+import java.util.regex.Pattern;
 
 import dev.tamboui.style.Style;
 import dev.tamboui.text.Line;
@@ -36,6 +37,8 @@ class RouteTreePreview {
             "throttle", "threads", "onException", "onCompletion",
             "intercept", "interceptFrom", "interceptSendToEndpoint");
 
+    private static final Pattern SELF_NAMED = 
Pattern.compile("[A-Za-z]+[\\[(]");
+
     private RouteTreePreview() {
     }
 
@@ -133,6 +136,10 @@ class RouteTreePreview {
             if (code.startsWith(type + "[") || code.startsWith(type + "(")) {
                 return code;
             }
+            // a code that names its own node, such as otherwise[direct:x] of 
a Switch (a node of type to)
+            if (SELF_NAMED.matcher(code).lookingAt()) {
+                return code;
+            }
             if (STRUCTURAL_TYPES.contains(type)) {
                 return type;
             }
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/RouteTreePreviewTest.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/RouteTreePreviewTest.java
index 56021200fce7..f0a54fb3b2bc 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/RouteTreePreviewTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/RouteTreePreviewTest.java
@@ -26,6 +26,7 @@ import 
org.apache.camel.diagram.RouteDiagramLayoutEngine.TreeNode;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 class RouteTreePreviewTest {
@@ -154,6 +155,30 @@ class RouteTreePreviewTest {
         return layout;
     }
 
+    @Test
+    void theOtherwiseOfASwitchIsLabelledAsItself() {
+        LayoutRoute layout = new LayoutRoute();
+        TreeNode root = node("from", "kafka:orders");
+        TreeNode sw = node("switch", null);
+        TreeNode case1 = node("case", "case[direct:gold]");
+        // the otherwise of a Switch is a node of type to whose code names it
+        TreeNode otherwise = node("to", "otherwise[direct:normal]");
+        TreeNode out = node("to", "kafka:out");
+        addChild(root, sw);
+        addChild(sw, case1);
+        addChild(sw, otherwise);
+        addChild(root, out);
+        for (TreeNode n : List.of(root, sw, case1, otherwise, out)) {
+            addLayoutNode(layout, n);
+        }
+
+        String tree = lineToPlainText(RouteTreePreview.buildTree(layout, 20, 
60, null));
+        assertTrue(tree.contains("otherwise[direct:normal]"), tree);
+        assertFalse(tree.contains("to: otherwise"), tree);
+        // an endpoint keeps its type
+        assertTrue(tree.contains("to: kafka:out"), tree);
+    }
+
     private TreeNode node(String type, String code) {
         NodeInfo info = new NodeInfo();
         info.type = type;

Reply via email to