camel-component-mock
Mock component for rust-camel testing
Overview
The Mock component is a testing utility that records every exchange it receives. It's essential for writing unit tests and integration tests for your routes.
This is a producer-only component - it records exchanges sent to it and provides assertions for testing.
Features
- Record all received exchanges
- Assert exchange count
- Inspect recorded exchanges
- Shared state across endpoint instances
- Perfect for testing route outputs
Installation
Add to your Cargo.toml:
[]
= "0.2"
URI Format
mock:name
Usage
Basic Testing
use RouteBuilder;
use MockComponent;
use CamelContext;
async
Integration Test Example
use RouteBuilder;
use MockComponent;
use DirectComponent;
use CamelContext;
async
Multiple Endpoints
let mock = new;
let route = from
.multicast
.to
.to
.end_multicast
.build?;
// Later, assert on both
let endpoint_a = mock.get_endpoint.unwrap;
let endpoint_b = mock.get_endpoint.unwrap;
endpoint_a.assert_exchange_count.await;
endpoint_b.assert_exchange_count.await;
MockEndpointInner Methods
| Method | Description |
|---|---|
get_received_exchanges() |
Get all recorded exchanges |
assert_exchange_count(n) |
Assert exact count (panics if mismatch) |
Best Practices
- Clone the MockComponent before registering to keep a reference for assertions
- Use descriptive names for mock endpoints to make tests readable
- Assert early - check exchange count before inspecting contents
- Clean shutdown - stop the context before assertions to ensure all exchanges are processed
Documentation
License
Apache-2.0
Contributing
Contributions are welcome! Please see the main repository for details.