CAMEL-23688: Add extensive test coverage for camel-jbang CLI commands#23812
CAMEL-23688: Add extensive test coverage for camel-jbang CLI commands#23812ammachado wants to merge 11 commits into
Conversation
Mockito 5 with mockito-junit-jupiter is needed to mock the JDK static methods ProcessHandle.allProcesses() and ProcessHandle.current() that process-inspection CLI commands use to discover running Camel integrations. The version is already managed in parent/pom.xml. The pattern matches the existing usage in camel-bonita. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…mand tests Provides shared infrastructure for testing CLI commands that inspect running Camel processes: - Redirects status file directory to target/test-process via CommandLineHelper - Writes <pid>-status.json files with controlled JSON content - Mocks ProcessHandle instances (pid, info, commandLine, startInstant) - Provides buildContextStatus() and buildRouteStatus() JSON helpers Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Tests that all known phase integer values map to the expected human-readable status strings (Starting, Running, Suspending, Suspended, Terminating, Terminated) so regressions in the mapping are caught immediately. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
CamelStartupRecorderActionTest: Tests rendering of startup steps using an inner test subclass that overrides findPids() and waitForOutputFile() to bypass process discovery. Covers display output, name parentheses, sort by duration (ascending and descending), and empty-pid handling. LoggerActionTest: Tests logger list display and sort-by-name behavior using two processes with distinct context names to verify row ordering. MessageTableHelperTest: Unit tests for MessageTableHelper covering body display, header visibility toggle, null root handling, and exchange ID. CamelSourceActionTest: Unit tests for the public static extractSourceName() method covering null input, plain filenames, scheme stripping, path stripping, and multi-colon (scheme + line number) handling. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
CamelContextStatusTest: Tests camel context status display for Running, Starting, and Stopped phases including table rendering and JSON output. CamelRouteStatusTest: Tests route status listing with empty result, single route, multiple routes, suspended route, JSON output, routeId filter, and row limit behavior. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ListProcessTest: Covers table display, sort by pid/name/age, name filter, reload-error display, and JSON output for the process list command. ListEndpointTest: Covers endpoint URI display, empty result, direction filter (from/to), and JSON output. ListHealthTest: Covers empty result, UP/DOWN health check display, readiness filter, and JSON output. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ListRestTest: Covers REST endpoint listing (URL, method), empty result, and JSON output. Notes that JSON-encoded URLs use escaped slashes (\/path). ListConsumerTest: Covers consumer URI and state display, empty result, and JSON output. The class field is required to avoid NPE in getType(). ListErrorTest: Covers error display from <pid>-error.json (separate from the status file), empty result (no error file), routeId display, and JSON output. The exception field must be a JsonObject, not a plain String. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…Test ListVariableTest: Covers variable key/value display using the global scope JSON structure, empty result, and JSON output. ListMetricTest: Covers counter metric display. Requires command.all=true to show metrics regardless of count value, empty result, and JSON output. ListCircuitBreakerTest: Covers CLOSED and OPEN circuit breaker state display, empty result, and JSON output. Uses the resilience4j JSON structure. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ListVaultTest includes two @disabled regression tests documenting a row-mutation bug in ListVault.doProcessWatchCall(): when multiple vault types each have exactly one secret, the same Row object is reused and its vault field is overwritten by each subsequent vault block. Affects both table and JSON output paths.
davsclaus
left a comment
There was a problem hiding this comment.
Nice work adding comprehensive test coverage for the camel-jbang CLI commands — going from zero process-command tests to full coverage of 20+ commands is a significant contribution. The ProcessCommandTestSupport base class is well-designed, the mock pattern is appropriate for these process-scanning commands, and the test fixtures accurately model the status JSON structures.
Particularly appreciated the thorough investigation in ListVaultTest where the @Disabled tests document an actual production bug with a precise root-cause analysis. Please consider filing a JIRA ticket for that bug so it gets tracked (see inline comment).
One trivial cosmetic nit on ListMetricTest (also inline).
This review checks the PR against project rules and conventions. It does not replace specialized review tools such as CodeRabbit, SonarCloud, or similar static analysis.
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
| } | ||
| } | ||
|
|
||
| @Disabled("ListVault row-mutation bug: when each vault type has exactly 1 secret, doProcessWatchCall() " |
There was a problem hiding this 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 — ...")
| return ctx; | ||
| } | ||
|
|
||
| private JsonObject micrometerObj(JsonObject... counters) { |
There was a problem hiding this 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.
| private JsonObject micrometerObj(JsonObject... counters) { | |
| private static JsonObject micrometerObj(JsonObject... counters) { |
Description
Adds test coverage for
camel-jbang-coreCLI commands to prepare the codebase for a refactoring pass (CAMEL-23688).Before this PR,
commands/process/had zero tests andcommands/action/had only 2 test classes for 38+ command files.Approach for process commands (
ListProcess,CamelRouteStatus,ListEndpoint, etc.): mock the JDK static methodsProcessHandle.allProcesses()andProcessHandle.current()with Mockito 5'smockStatic, then write hand-crafted<pid>-status.jsonfixtures viaCommandLineHelper.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 overridesfindPids()andwaitForOutputFile()to inject a prepared JSON response.New files:
commands/package:CamelCommandHelperTest— phase integer to human-readable status string mappingcommands/action/package:CamelStartupRecorderActionTest— step display, name parentheses, sort by duration, empty-pid errorLoggerActionTest— logger list display, sort by context name across two processesMessageTableHelperTest— body/header visibility toggle, null root, exchange ID in outputCamelSourceActionTest—extractSourceName()edge cases (null, plain file, scheme, path, multi-colon)commands/process/package:ProcessCommandTestSupport— shared base: MockedStatic wiring, status-file helpers, JSON buildersCamelContextStatusTest— Running/Starting/Stopped phase display, JSON outputCamelRouteStatusTest— single/multiple routes, suspended route, filter, limit, JSON outputListProcessTest— table display, sort by pid/name/age, name filter, reload-error display, JSON outputListEndpointTest— URI display, direction filter (from/to), JSON outputListHealthTest— UP/DOWN health check display, readiness-only filter, JSON outputListRestTest— REST endpoint URL/method display, JSON outputListConsumerTest— consumer URI/state display, JSON outputListErrorTest— error display from<pid>-error.json, routeId, JSON outputListVariableTest— variable key/value/scope display, JSON outputListMetricTest— counter metric display (all=true), JSON outputListCircuitBreakerTest— CLOSED/OPEN state display, JSON outputTest count: 525 total in this module (previously ~470), 0 failures, 0 errors.
Claude Code on behalf of Adriano Machado
Target
mainbranch)Tracking
Apache Camel coding standards and style
mvn clean install -DskipTestslocally from root folder and I have committed all auto-generated changes.