Expand description
§camel-component-mock
Mock component for rust-camel — testing utility that records received exchanges for later assertion, useful for verifying route output in tests.
Main types: MockComponent, MockEndpoint, MockProducer, MockExpectations.
§Example
use camel_component_mock::MockComponent;
use camel_component_api::{Component, NoOpComponentContext, Exchange, Message};
// Create a mock component and endpoint
let component = MockComponent::new();
let endpoint = component
.create_endpoint("mock:result", &NoOpComponentContext)
.unwrap();
// In a real route, the producer would be used as a Tower service.
// After sending exchanges, you can inspect them:
let inner = component.get_endpoint("result").unwrap();
// inner.assert_exchange_count(1).await;
// inner.exchange(0).assert_body_text("hello");§expectedCount is inert in the live runtime path
The expectedCount URI parameter records intent only: at first
endpoint creation it registers an exact count expectation on the
endpoint inner. It is enforced only when an explicit assertion method
runs (assert_satisfied / try_assert_satisfied), never by the live
producer — poll_ready and call do not consult it. Under
camel run, where no test caller invokes assertions, expectedCount
never rejects or drops traffic.
Structs§
- Exchange
Assert - A handle for making synchronous assertions on a recorded exchange.
- Mock
Component - The Mock component is a testing utility that records every exchange it receives via its producer. It exposes helpers to inspect and assert on the recorded exchanges.
- Mock
Config - Configuration for
MockComponent. - Mock
Endpoint - A mock endpoint that records all exchanges sent to it.
- Mock
Endpoint Inner - The actual data behind a mock endpoint. Shared across all
MockEndpointinstances created with the same name viaMockComponent. - Mock
Expectations - Expectations set on a mock endpoint for batch-style assertion.
Enums§
- Mock
Assertion Error - Error returned by
MockEndpointInner::try_assert_satisfiedwhen a recorded expectation is not satisfied (or is malformed).