Skip to content

(test): add test coverage for camel-rest component#21162

Merged
orpiske merged 1 commit intoapache:mainfrom
orpiske:ci-issue-rest-coverage
Feb 6, 2026
Merged

(test): add test coverage for camel-rest component#21162
orpiske merged 1 commit intoapache:mainfrom
orpiske:ci-issue-rest-coverage

Conversation

@orpiske
Copy link
Contributor

@orpiske orpiske commented Jan 30, 2026

Summary

  • Add comprehensive unit tests for the camel-rest component
  • Increase code coverage from 0% to 68%
  • Create 21 test files with 256 tests covering all major classes

Test Coverage

Tests cover the following classes:

  • RestComponent and RestEndpoint
  • RestApiComponent and RestApiEndpoint
  • RestProducer and RestApiProducer
  • DefaultRestRegistry and DefaultRestRegistryFactory
  • RestProducerBindingProcessor and callbacks
  • Component and endpoint configurers
  • URI factories
  • REST constants

Test plan

  • All 256 tests pass
  • Code compiles without errors
  • Code formatted according to project standards

@github-actions
Copy link
Contributor

🌟 Thank you for your contribution to the Apache Camel project! 🌟

🤖 CI automation will test this PR automatically.

🐫 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.

  • You can label PRs using build-all, build-dependents, 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 have access to the summary.

  • ⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

Copy link
Contributor

@squakez squakez left a comment

Choose a reason for hiding this comment

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

From a quick look it seems that these tests are just checking the creation of the mock, asserting that some value is initialized or not null. I don't see any business logic really tested, am I wrong?

@orpiske
Copy link
Contributor Author

orpiske commented Jan 30, 2026

From a quick look it seems that these tests are just checking the creation of the mock, asserting that some value is initialized or not null. I don't see any business logic really tested, am I wrong?

indeed, it does seem to be leaning a bit too much on that. I'll mark this one as a draft ... I am still adjusting the spec for coverage and this one need further checks

@orpiske orpiske marked this pull request as draft January 30, 2026 11:38
@orpiske orpiske force-pushed the ci-issue-rest-coverage branch from 50251b8 to ccef330 Compare January 30, 2026 11:50
@davsclaus
Copy link
Contributor

camel-rest is tested via other components where you use it with platform-http / jetty / undertow that has rest-dsl tests.

@squakez
Copy link
Contributor

squakez commented Jan 30, 2026

camel-rest is tested via other components where you use it with platform-http / jetty / undertow that has rest-dsl tests.

Yes. We may need to see how to account aggregate report for coverage to have a more meaningful value and don't get tricked by that 0% which is not accurate. I will work on this one.

Copy link
Contributor Author

@orpiske orpiske left a comment

Choose a reason for hiding this comment

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

I finally had some time to look at this one. There's some unnecessary tests, indeed ... but there are others that do test some of the code in this component.

Even though it might be tested somewhere, relying on test at a distance could be ... tricky for contributors to figure out what broke.

I'm going to remove the useless tests and we can keep the remaining bits.


import static org.assertj.core.api.Assertions.assertThat;

class RestApiComponentTest {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test is unnecessary

import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class RestApiEndpointFactoryTest {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test is unnecessary


import static org.assertj.core.api.Assertions.assertThat;

class RestConfigurerTest {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test is unnecessary

@squakez
Copy link
Contributor

squakez commented Feb 6, 2026

FYI, with the aggregate coverage we already have 73.2% in this component. This is now available in the report. For sure, any useful test which cover the business logic here should be evaluated and kept.

@orpiske
Copy link
Contributor Author

orpiske commented Feb 6, 2026

Another thing: this component must not depend on camel-test-junit5. It causes a cyclic dependency issue.

@orpiske orpiske force-pushed the ci-issue-rest-coverage branch 2 times, most recently from e821199 to ec5c738 Compare February 6, 2026 09:41
Add unit tests for camel-rest component focusing on meaningful behavior tests:
- RestComponent URI parsing and endpoint creation
- RestEndpoint behavior and error handling
- RestProducer query parameter resolution and exchange preparation
- RestApiEndpoint creation and factory interactions
- DefaultRestRegistry service management
- RestProducerBindingProcessor and callback behavior

Tests cover:
- Error conditions and exception handling
- URI template placeholder resolution
- Query parameter substitution with optional placeholders
- Host scheme handling and normalization
- Component property propagation
- Consumer/producer creation with factories
@orpiske orpiske force-pushed the ci-issue-rest-coverage branch from ec5c738 to 9e608dd Compare February 6, 2026 09:45
@orpiske
Copy link
Contributor Author

orpiske commented Feb 6, 2026

Another thing: this component must not depend on camel-test-junit5. It causes a cyclic dependency issue.

On a side note: this one is very picky with the dependencies required. Likely to be a byproduct of https://issues.apache.org/jira/browse/CAMEL-18701, which I hope we'll fix sometime when we work on the next major.

@orpiske orpiske marked this pull request as ready for review February 6, 2026 10:15
@orpiske orpiske merged commit 1cc74b3 into apache:main Feb 6, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants