Hi,
I want to test a complex route that involves sending messages to ActiveMQ and
calling webservices with SpringWs.
The route itself is working fine using spring-boot (1.2.7.RELEASE) and the
camel-spring-boot plugin (2.16.0).
Here are the important parts of the code:
@Component
public class MyRoute extends SpringRouteBuilder {
@Override
public void configure() throws Exception {
from(direct:responseQueue)
.transacted()
.split(...)
.to(activemq:individual_persist_queue)
.end()
.to("spring-ws:http://localhost:8088/acknowledge_webservice")
.log("DONE");
}
}
Now I want to test this route by mocking the activemq and spring-ws endpoints
so the test can be run without any dependency on the broker or the webserver.
My basic requirement is to verify that the right amount of messages are sent to
each endpoint.
In my current scenario, the original message is split into three parts which
should be sent to ActiveMQ, followed by a single acknowledge message to the
WebService.
The transaction is there to roll-back the JMS deliveries in case the
web-service call fails. None of that should be important for this test however.
My test looks as follows:
@RunWith(CamelSpringJUnit4ClassRunner.class)
@BootstrapWith(CamelTestContextBootstrapper.class)
@SpringApplicationConfiguration(classes = MyConfig.class)
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@MockEndpointsAndSkip
public class CamelSpringBootTest {
@Produce(uri = "direct:responseQueue ")
protected ProducerTemplate template;
@EndpointInject(uri = "mock:
spring-ws:http://localhost:8088/acknowledge_webservice")
MockEndpoint webserviceMock;
@EndpointInject(uri = "mock:activemq:individual_persist_queue ")
MockEndpoint activemqMock;
@Test
public void test() throws Exception {
activemqMock.expectedMessageCount(3);
webserviceMock.expectedMessageCount(1);
template.sendBody(someXML);
MockEndpoint.assertIsSatisfied(10L, TimeUnit.SECONDS, toKcxMock);
}
}
When I run the test with the webservice and ActiveMQ available then everything
works as expected.
The assertions fail however as the mock endpoints don't register any messages.
If I disable the ActiveMQ broker, then I get 'Connection refused' exceptions
from the ActiveMQ component.
As far as I understand Camel shouldn't have tried to send the messages to
ActiveMQ though because of the @MockEndpointsAndSkip annotation.
What am I missing?
Thanks for any suggestion,
Kai
IMPORTANT NOTICE: This email is intended solely for the use of the individual
to whom it is addressed and may contain information that is privileged,
confidential or otherwise exempt from disclosure under applicable law. If the
reader of this email is not the intended recipient or the employee or agent
responsible for delivering the message to the intended recipient, you are
hereby notified that any dissemination, distribution, or copying of this
communication is strictly prohibited. If you have received this communication
in error, please immediately return the original message to the sender at the
listed email address. In accordance with Kewill policy, emails sent and
received may be monitored. Although Kewill takes reasonable precautions to
minimize the risk, Kewill accepts no responsibility for any loss or damage
should this email contain any virus, or similar destructive or mischievous code.