You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "ammachado (via GitHub)" <gi...@apache.org> on 2026/06/07 01:28:59 UTC
[PR] CAMEL-23688: Add extensive test coverage for camel-jbang CLI commands [camel]
ammachado opened a new pull request, #23812:
URL: https://github.com/apache/camel/pull/23812
# Description
Adds test coverage for `camel-jbang-core` CLI commands to prepare the codebase for a refactoring pass ([CAMEL-23688](https://issues.apache.org/jira/browse/CAMEL-23688)).
Before this PR, `commands/process/` had zero tests and `commands/action/` had only 2 test classes for 38+ command files.
**Approach for process commands** (`ListProcess`, `CamelRouteStatus`, `ListEndpoint`, etc.): mock the JDK static methods `ProcessHandle.allProcesses()` and `ProcessHandle.current()` with Mockito 5's `mockStatic`, then write hand-crafted `<pid>-status.json` fixtures via `CommandLineHelper.useHomeDir()`. This exercises the full table-rendering, sorting, filtering, and JSON-output paths without a running Camel integration.
**Approach for action commands**: pure unit tests against public/package-private utility methods, and an inner test-subclass pattern (already established in this module by `CamelRouteDiagramActionTest`) that overrides `findPids()` and `waitForOutputFile()` to inject a prepared JSON response.
**New files:**
`commands/` package:
- `CamelCommandHelperTest` — phase integer to human-readable status string mapping
`commands/action/` package:
- `CamelStartupRecorderActionTest` — step display, name parentheses, sort by duration, empty-pid error
- `LoggerActionTest` — logger list display, sort by context name across two processes
- `MessageTableHelperTest` — body/header visibility toggle, null root, exchange ID in output
- `CamelSourceActionTest` — `extractSourceName()` edge cases (null, plain file, scheme, path, multi-colon)
`commands/process/` package:
- `ProcessCommandTestSupport` — shared base: MockedStatic wiring, status-file helpers, JSON builders
- `CamelContextStatusTest` — Running/Starting/Stopped phase display, JSON output
- `CamelRouteStatusTest` — single/multiple routes, suspended route, filter, limit, JSON output
- `ListProcessTest` — table display, sort by pid/name/age, name filter, reload-error display, JSON output
- `ListEndpointTest` — URI display, direction filter (from/to), JSON output
- `ListHealthTest` — UP/DOWN health check display, readiness-only filter, JSON output
- `ListRestTest` — REST endpoint URL/method display, JSON output
- `ListConsumerTest` — consumer URI/state display, JSON output
- `ListErrorTest` — error display from `<pid>-error.json`, routeId, JSON output
- `ListVariableTest` — variable key/value/scope display, JSON output
- `ListMetricTest` — counter metric display (`all=true`), JSON output
- `ListCircuitBreakerTest` — CLOSED/OPEN state display, JSON output
**Test count:** 525 total in this module (previously ~470), 0 failures, 0 errors.
_Claude Code on behalf of Adriano Machado_
# Target
- [x] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch)
# Tracking
- [x] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL-23688) filed for the change (usually before you start working on it).
# Apache Camel coding standards and style
- [x] I checked that each commit in the pull request has a meaningful subject line and body.
- [x] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes.
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-23688: Add extensive test coverage for camel-jbang CLI commands [camel]
Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #23812:
URL: https://github.com/apache/camel/pull/23812#discussion_r3368868157
##########
dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/process/ListVaultTest.java:
##########
@@ -0,0 +1,309 @@
+/*
+ * 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.dsl.jbang.core.commands.process;
+
+import java.util.stream.Stream;
+
+import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
+import org.apache.camel.util.json.JsonArray;
+import org.apache.camel.util.json.JsonObject;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.MockedStatic;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mockStatic;
+
+@ExtendWith(MockitoExtension.class)
+class ListVaultTest extends ProcessCommandTestSupport {
+
+ @Test
+ void testEmptyOutputWhenNoVaults() throws Exception {
+ JsonObject root = new JsonObject();
+ root.put("context", contextObj());
+ writeStatusFile(TEST_PID, root);
+
+ ListVault command = new ListVault(new CamelJBangMain().withPrinter(printer));
+ command.sort = "pid";
+
+ try (MockedStatic<ProcessHandle> mocked = mockStatic(ProcessHandle.class)) {
+ ProcessHandle ph = mockProcessHandle(TEST_PID);
+ ProcessHandle currentHandle = mockCurrentHandle();
+ mocked.when(ProcessHandle::current).thenReturn(currentHandle);
+ mocked.when(ProcessHandle::allProcesses).thenAnswer(inv -> Stream.of(ph));
+
+ int exit = command.doCall();
+
+ assertEquals(0, exit);
+ assertEquals("", printer.getOutput().trim());
+ }
+ }
+
+ @Test
+ void testShowsAwsVault() throws Exception {
+ JsonObject root = new JsonObject();
+ root.put("context", contextObj());
+ root.put("vaults", vaults("aws-secrets", vault("us-east-1", "aws-secret")));
+ writeStatusFile(TEST_PID, root);
+
+ ListVault command = new ListVault(new CamelJBangMain().withPrinter(printer));
+ command.sort = "pid";
+
+ try (MockedStatic<ProcessHandle> mocked = mockStatic(ProcessHandle.class)) {
+ ProcessHandle ph = mockProcessHandle(TEST_PID);
+ ProcessHandle currentHandle = mockCurrentHandle();
+ mocked.when(ProcessHandle::current).thenReturn(currentHandle);
+ mocked.when(ProcessHandle::allProcesses).thenAnswer(inv -> Stream.of(ph));
+
+ int exit = command.doCall();
+
+ assertEquals(0, exit);
+ String output = printer.getOutput();
+ assertTrue(output.contains("AWS"), "Should show AWS vault");
+ assertTrue(output.contains("aws-secret"), "Should show AWS secret name");
+ }
+ }
+
+ @Test
+ void testShowsHashicorpVault() throws Exception {
+ JsonObject root = new JsonObject();
+ root.put("context", contextObj());
+ root.put("vaults", vaults("hashicorp-secrets", hashicorpVault()));
+ writeStatusFile(TEST_PID, root);
+
+ ListVault command = new ListVault(new CamelJBangMain().withPrinter(printer));
+ command.sort = "pid";
+
+ try (MockedStatic<ProcessHandle> mocked = mockStatic(ProcessHandle.class)) {
+ ProcessHandle ph = mockProcessHandle(TEST_PID);
+ ProcessHandle currentHandle = mockCurrentHandle();
+ mocked.when(ProcessHandle::current).thenReturn(currentHandle);
+ mocked.when(ProcessHandle::allProcesses).thenAnswer(inv -> Stream.of(ph));
+
+ int exit = command.doCall();
+
+ assertEquals(0, exit);
+ assertTrue(printer.getOutput().contains("Hashicorp"), "Should show Hashicorp vault");
+ }
+ }
+
+ @Test
+ void testShowsKubernetesConfigMapVault() throws Exception {
+ JsonObject root = new JsonObject();
+ root.put("context", contextObj());
+ root.put("vaults", vaults("kubernetes-configmaps", configMapVault("app-config")));
+ writeStatusFile(TEST_PID, root);
+
+ ListVault command = new ListVault(new CamelJBangMain().withPrinter(printer));
+ command.sort = "pid";
+
+ try (MockedStatic<ProcessHandle> mocked = mockStatic(ProcessHandle.class)) {
+ ProcessHandle ph = mockProcessHandle(TEST_PID);
+ ProcessHandle currentHandle = mockCurrentHandle();
+ mocked.when(ProcessHandle::current).thenReturn(currentHandle);
+ mocked.when(ProcessHandle::allProcesses).thenAnswer(inv -> Stream.of(ph));
+
+ int exit = command.doCall();
+
+ assertEquals(0, exit);
+ String output = printer.getOutput();
+ assertTrue(output.contains("Kubernetes-cm"), "Should show Kubernetes configmap vault");
+ assertTrue(output.contains("app-config"), "Should show configmap name");
+ }
+ }
+
+ @Disabled("ListVault row-mutation bug: when each vault type has exactly 1 secret, doProcessWatchCall() "
Review Comment:
The bug documented here (row-mutation when each vault type has exactly 1 secret) is well-investigated and the root cause analysis looks accurate. Could you file a separate JIRA ticket for this bug and reference it in the `@Disabled` message? That way it gets tracked for the refactoring pass (CAMEL-23688) or as a standalone fix.
Something like:
```
@Disabled("CAMEL-XXXXX: ListVault row-mutation bug — ...")
```
##########
dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/process/ListMetricTest.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.dsl.jbang.core.commands.process;
+
+import java.util.Collections;
+import java.util.stream.Stream;
+
+import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
+import org.apache.camel.util.json.JsonArray;
+import org.apache.camel.util.json.JsonObject;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.MockedStatic;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mockStatic;
+
+@ExtendWith(MockitoExtension.class)
+class ListMetricTest extends ProcessCommandTestSupport {
+
+ @Test
+ void testEmptyOutputWhenNoMetrics() throws Exception {
+ JsonObject root = new JsonObject();
+ root.put("context", contextObj());
+ writeStatusFile(TEST_PID, root);
+
+ ListMetric command = new ListMetric(new CamelJBangMain().withPrinter(printer));
+ command.sort = "pid";
+
+ try (MockedStatic<ProcessHandle> mocked = mockStatic(ProcessHandle.class)) {
+ ProcessHandle ph = mockProcessHandle(TEST_PID);
+ ProcessHandle currentHandle = mockCurrentHandle();
+ mocked.when(ProcessHandle::current).thenReturn(currentHandle);
+ mocked.when(ProcessHandle::allProcesses).thenAnswer(inv -> Stream.of(ph));
+
+ int exit = command.doCall();
+
+ assertEquals(0, exit);
+ assertEquals("", printer.getOutput().trim());
+ }
+ }
+
+ @Test
+ void testShowsCounterMetric() throws Exception {
+ JsonObject root = new JsonObject();
+ root.put("context", contextObj());
+ root.put("micrometer", micrometerObj(counterEntry(42.0)));
+ writeStatusFile(TEST_PID, root);
+
+ ListMetric command = new ListMetric(new CamelJBangMain().withPrinter(printer));
+ command.sort = "pid";
+ command.all = true;
+
+ try (MockedStatic<ProcessHandle> mocked = mockStatic(ProcessHandle.class)) {
+ ProcessHandle ph = mockProcessHandle(TEST_PID);
+ ProcessHandle currentHandle = mockCurrentHandle();
+ mocked.when(ProcessHandle::current).thenReturn(currentHandle);
+ mocked.when(ProcessHandle::allProcesses).thenAnswer(inv -> Stream.of(ph));
+
+ int exit = command.doCall();
+
+ assertEquals(0, exit);
+ String output = printer.getOutput();
+ assertTrue(output.contains("myCounter"), "Should show metric name");
+ }
+ }
+
+ @Test
+ void testJsonOutput() throws Exception {
+ JsonObject root = new JsonObject();
+ root.put("context", contextObj());
+ root.put("micrometer", micrometerObj(counterEntry(10.0)));
+ writeStatusFile(TEST_PID, root);
+
+ ListMetric command = new ListMetric(new CamelJBangMain().withPrinter(printer));
+ command.sort = "pid";
+ command.all = true;
+ command.jsonOutput = true;
+
+ try (MockedStatic<ProcessHandle> mocked = mockStatic(ProcessHandle.class)) {
+ ProcessHandle ph = mockProcessHandle(TEST_PID);
+ ProcessHandle currentHandle = mockCurrentHandle();
+ mocked.when(ProcessHandle::current).thenReturn(currentHandle);
+ mocked.when(ProcessHandle::allProcesses).thenAnswer(inv -> Stream.of(ph));
+
+ int exit = command.doCall();
+
+ assertEquals(0, exit);
+ String output = printer.getOutput();
+ assertTrue(output.startsWith("["), "JSON output should be array");
+ assertTrue(output.contains("myCounter"));
+ }
+ }
+
+ private static JsonObject contextObj() {
+ JsonObject ctx = new JsonObject();
+ ctx.put("name", "myApp");
+ return ctx;
+ }
+
+ private JsonObject micrometerObj(JsonObject... counters) {
Review Comment:
Nit: this helper is an instance method while every other helper in this test class (and across all other test classes in this PR) is `static`. Consider making it `static` for consistency.
```suggestion
private static JsonObject micrometerObj(JsonObject... counters) {
```
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-23688: Add extensive test coverage for camel-jbang CLI commands [camel]
Posted by "ammachado (via GitHub)" <gi...@apache.org>.
ammachado commented on PR #23812:
URL: https://github.com/apache/camel/pull/23812#issuecomment-4643827350
Rebased on top of main, after merging #23822.
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-23688: Add extensive test coverage for camel-jbang CLI commands [camel]
Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus merged PR #23812:
URL: https://github.com/apache/camel/pull/23812
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-23688: Add extensive test coverage for camel-jbang CLI commands [camel]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #23812:
URL: https://github.com/apache/camel/pull/23812#issuecomment-4646228726
:star2: Thank you for your contribution to the Apache Camel project! :star2:
:robot: CI automation will test this PR automatically.
:camel: Apache Camel Committers, please review the following items:
* First-time contributors **require MANUAL approval** for the GitHub Actions to run
* You can use the command `/component-test (camel-)component-name1 (camel-)component-name2..` to request a test from the test bot although they are normally detected and executed by CI.
* You can label PRs using `skip-tests` and `test-dependents` to fine-tune the checks executed by this PR.
* Build and test logs are available in the summary page. **Only** [Apache Camel committers](https://camel.apache.org/community/team/#committers) have access to the summary.
:warning: Be careful when sharing logs. Review their contents before sharing them publicly.
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-23688: Add extensive test coverage for camel-jbang CLI commands [camel]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #23812:
URL: https://github.com/apache/camel/pull/23812#issuecomment-4646429685
<!-- ci-tested-modules -->
:test_tube: **CI tested the following changed modules:**
- `dsl/camel-jbang/camel-jbang-core`
:warning: **Some tests are disabled on GitHub Actions** (`@DisabledIfSystemProperty(named = "ci.env.name")`) and require manual verification:
- `dsl/camel-jbang/camel-jbang-core`: 1 test(s) disabled on GitHub Actions
:bulb: **Manual integration tests recommended:**
> You modified `dsl/camel-jbang/camel-jbang-core`. The related integration tests in `dsl/camel-jbang/camel-jbang-it` are excluded from CI. Consider running them manually:
> ```
> mvn verify -f dsl/camel-jbang/camel-jbang-it -Djbang-it-test
> ```
<details><summary>All tested modules (6 modules)</summary>
- Camel :: JBang :: Core
- Camel :: JBang :: MCP
- Camel :: JBang :: Plugin :: Route Parser
- Camel :: JBang :: Plugin :: TUI
- Camel :: JBang :: Plugin :: Validate
- Camel :: Launcher :: Container
</details>
---
:gear: [View full build and test results](https://github.com/apache/camel/actions/runs/27102975350)
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org