Skip to content

CAMEL-23688: Add extensive test coverage for camel-jbang CLI commands#23812

Draft
ammachado wants to merge 11 commits into
apache:mainfrom
ammachado:CAMEL-23688
Draft

CAMEL-23688: Add extensive test coverage for camel-jbang CLI commands#23812
ammachado wants to merge 11 commits into
apache:mainfrom
ammachado:CAMEL-23688

Conversation

@ammachado
Copy link
Copy Markdown
Contributor

Description

Adds test coverage for camel-jbang-core CLI commands to prepare the codebase for a refactoring pass (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
  • CamelSourceActionTestextractSourceName() 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

  • I checked that the commit is targeting the correct branch (Camel 4 uses the main branch)

Tracking

  • If this is a large change, bug fix, or code improvement, I checked there is a JIRA issue filed for the change (usually before you start working on it).

Apache Camel coding standards and style

  • I checked that each commit in the pull request has a meaningful subject line and body.
  • I have run mvn clean install -DskipTests locally from root folder and I have committed all auto-generated changes.

ammachado and others added 11 commits June 7, 2026 08:24
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.
Copy link
Copy Markdown
Contributor

@davsclaus davsclaus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() "
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
private JsonObject micrometerObj(JsonObject... counters) {
private static JsonObject micrometerObj(JsonObject... counters) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants