camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Owain McGuire <>
Subject Re: Mocks receive no messages in Camel-SpringBoot test
Date Wed, 07 Jun 2017 11:45:22 GMT

You appear not to be mocking the activemq:queue:output endpoint before you get the mock endpoint
i the test.  If you temporarily change the route uri to mock:activemq:queue:output then the
test works.  I am not sure how you would do it using injection.  I use advicewith on the route
to mock URIs before the test.  Here is a previous response
to the same issue.

Here is another code snippet

@SpringBootTest(classes = MyApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)

public class AssignOrderReferenceTests {

  public static final String ROUTE_ID = “myroute";
  public static final String MOCK_ENRICH = "mock:put";
  public static final String MOCK_OUT = "mock:out";
  private ProducerTemplate template;

  private CamelContext camelContext;

  public void formatReferenceFromCounter() throws Exception {

    camelContext.getRouteDefinition(ROUTE_ID).adviceWith(camelContext, new AdviceWithRouteBuilder()
      public void configure() throws Exception {
        weaveById(“id-of-endpoint").replace().inOut(MOCK_ENRICH);  // you can use enpoint
patterns.  Have a look at the adviceWith docs. 

    MockEndpoint mockEnrich = camelContext.getEndpoint(MOCK_ENRICH, MockEndpoint.class);
    MockEndpoint mockOut = camelContext.getEndpoint(MOCK_OUT, MockEndpoint.class);
      mockEnrich.whenAnyExchangeReceived(new Processor() {
      public void process(Exchange exchange) throws Exception {


    mockOut.expectedBodyReceived().constant(Prefix + (COUNTER));


    template.sendBody("direct:in", 1);


The AdviceWith is very powerful. 


> On 7 Jun 2017, at 11:27, Burkard Stephan <> wrote:
> Hi 
> I built Camel route tests in a Spring Boot project. My injected mock endpoints do not
receive any messages. I also tried to get the mock through Camel context, but also without
> The log output says that the mock endpoints are created and the mocked endpoint receives
messages. Have I missed something or is this a known problem? If the latter, how can I bring
my mocks to work?
> I have attached a very simple Maven test project to show the problem. 
> SpringBoot 1.4.2.RELEASE
> Camel 2.17.3
> Thanks 
> Stephan
> <>

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message