gnodet-bot commented on code in PR #30029:
URL: https://github.com/apache/camel/pull/30029#discussion_r4578889759
##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelSendAction.java:
##########
@@ -162,6 +162,11 @@ public class CamelSendAction extends ActionBaseCommand {
@Option(name = "logging-color", hasValue = false, description = "Use
colored logging", defaultValue = "true")
boolean loggingColor = true;
+ @Option(name = "json", hasValue = false,
+ description = "Output the outcome of the send in JSON Format: the
status, the exchange id and, with --reply, the"
+ + " reply message (as --show-headers, --show-body
and the other --show options say)")
+ boolean jsonOutput;
Review Comment:
💬 **Nit:** The description is 29 words long — the longest in this command's
option list. Consider a tighter phrasing, e.g.:
> Output the send outcome as JSON: status, exchange ID, and (with `--reply`)
the reply message, filtered by `--show-*` options
Shorter option descriptions are easier to read in `--help` output.
##########
dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/action/CamelSendActionResultTest.java:
##########
@@ -253,4 +253,32 @@ private static JsonObject answer(String status) {
answer.put("message", message);
return answer;
}
+
+ @Test
+ void theOutcomeAsJson() throws Exception {
+ // CAMEL-26929: send had no --json, so a script or an AI agent had to
read the status line and the table
+ writeStatusFile(TEST_PID, "orders");
+
+ int exit = callWithResponse(command("orders",
"--endpoint=direct:start", "--body=hello", "--reply", "--json"),
+ answer("success"));
+
+ assertThat(exit).isEqualTo(CliExitCode.OK);
+ JsonObject out = (JsonObject) Jsoner.deserialize(printer.getStdout());
+ assertThat(out.getString("status")).isEqualTo("success");
+ assertThat(out.getString("exchangeId")).isEqualTo("ex-1");
+ assertThat(out.getLong("pid")).isEqualTo(TEST_PID);
+ assertThat(printer.getStdout()).doesNotContain("Sent (");
+ }
+
+ @Test
+ void aFailedSendAsJsonIsAFailure() throws Exception {
+ writeStatusFile(TEST_PID, "orders");
+
+ int exit = callWithResponse(command("orders",
"--endpoint=direct:start", "--json"), answer("error"));
+
+ assertThat(exit).isEqualTo(CliExitCode.FAILURE);
+ JsonObject out = (JsonObject) Jsoner.deserialize(printer.getStdout());
+ assertThat(out.getString("status")).isEqualTo("error");
+ assertThat(out.containsKey("exception")).isTrue();
+ }
}
Review Comment:
💬 **Minor test gap:** The two new tests cover single-message success and
failure, but the `--json` early-exit branch (`if (jsonOutput) { return
showJson(result, jo); }`) is inserted before the `if (jo.containsKey("sent"))`
multi-message path. A test for `--json + --repeat` or a folder send would
verify that `showJson` handles the `sent`/`errors` keys correctly. The PR body
mentions these cases work because the raw `jo` has the right keys — worth a
test to lock it in.
--
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]