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

cdeppisch 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 1f91d3f4c322 CAMEL-22901: Stream Citrus test logs to Camel JBang output
1f91d3f4c322 is described below

commit 1f91d3f4c322b121d1eb205295da9a5b3b0e43be
Author: Christoph Deppisch <[email protected]>
AuthorDate: Wed Jan 28 10:14:00 2026 +0100

    CAMEL-22901: Stream Citrus test logs to Camel JBang output
    
    - Stream log output while running tests via Camel JBang test plugin
    - Run tests asynchronously and write test log output to Camel JBang process 
output while tests are running
    
    - Make sure to properly handle Json typed message body
    - Set Json payload as nested object in the CloudEvents data field
    - Avoid duplicate data type transformation when content type is Json 
CloudEvents already
---
 .../dsl/jbang/core/commands/test/TestPlugin.java   | 50 +++++++++++++++-------
 1 file changed, 35 insertions(+), 15 deletions(-)

diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestPlugin.java
 
b/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestPlugin.java
index 7166e45c22e9..a556df43b7c3 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestPlugin.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestPlugin.java
@@ -87,21 +87,19 @@ public class TestPlugin implements Plugin {
 
             // Prepare commands
             if ("init".equals(command)) {
-                prepareInitCommand(citrus);
+                return executeInitCommand(citrus, args);
             } else if ("run".equals(command)) {
-                args = prepareRunCommand(citrus, args);
+                return executeRunCommand(citrus, args);
             }
 
-            ProcessAndOutput pao = citrus.run(command, args);
-            main.getOut().print(pao.getOutput());
-            return pao.getProcess().exitValue();
+            return execute(citrus, command, args);
         }
 
         /**
-         * Prepare init command. Automatically uses test subfolder as a 
working directory for creating new tests.
-         * Automatically adds a jbang.properties configuration to add required 
Camel Citrus dependencies.
+         * Prepare and execute init command. Automatically uses test subfolder 
as a working directory for creating new
+         * tests. Automatically adds a jbang.properties configuration to add 
required Camel Citrus dependencies.
          */
-        private void prepareInitCommand(JBangSupport citrus) {
+        private int executeInitCommand(JBangSupport citrus, List<String> args) 
{
             Path currentDir = Paths.get(".");
             Path workingDir;
             // Automatically set test subfolder as a working directory
@@ -134,14 +132,18 @@ public class TestPlugin implements Plugin {
                     main.getOut().println("Failed to create jbang.properties 
for tests in:" + jbangProperties);
                 }
             }
+
+            return execute(citrus, "init", args);
         }
 
         /**
-         * Prepare run command. Automatically navigates to test subfolder if 
it is present and uses this as a working
-         * directory.
+         * Prepare and execute Citrus run command. Automatically navigates to 
test subfolder if it is present and uses
+         * this as a working directory. Runs command asynchronous streaming 
logs to the main output of this Camel JBang
+         * process.
          */
-        private List<String> prepareRunCommand(JBangSupport citrus, 
List<String> args) {
+        private int executeRunCommand(JBangSupport citrus, List<String> args) {
             Path currentDir = Paths.get(".");
+            List<String> runArgs = new ArrayList<>(args);
             // automatically navigate to test subfolder for test execution
             if (currentDir.resolve(TEST_DIR).toFile().exists()) {
                 // set test subfolder as working directory
@@ -149,13 +151,31 @@ public class TestPlugin implements Plugin {
 
                 // remove test folder prefix in test file path if present
                 if (!args.isEmpty() && args.get(0).startsWith(TEST_DIR + "/")) 
{
-                    List<String> newArgs = new ArrayList<>(args.subList(1, 
args.size()));
-                    newArgs.add(0, args.get(0).substring((TEST_DIR + 
"/").length()));
-                    return newArgs;
+                    runArgs = new ArrayList<>(args.subList(1, args.size()));
+                    runArgs.add(0, args.get(0).substring((TEST_DIR + 
"/").length()));
                 }
             }
 
-            return args;
+            citrus.withOutputListener(output -> main.getOut().print(output));
+            ProcessAndOutput pao = citrus.runAsync("run", runArgs);
+            try {
+                pao.waitFor();
+            } catch (InterruptedException e) {
+                main.getOut().printErr("Interrupted while running Citrus 
command", e);
+            }
+
+            return pao.getProcess().exitValue();
+        }
+
+        /**
+         * Uses given Citrus JBang instance to run the given command using the 
given arguments.
+         *
+         * @return exit code of the command process.
+         */
+        private int execute(JBangSupport citrus, String command, List<String> 
args) {
+            ProcessAndOutput pao = citrus.run(command, args);
+            main.getOut().print(pao.getOutput());
+            return pao.getProcess().exitValue();
         }
     }
 }

Reply via email to