You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Michael Rambichler <mi...@rambichler.at> on 2020/07/03 19:09:31 UTC
Unit Test with @producer endpoints
Dear Camel Specialists,
I have an EventNotifier where I send a message to another camel endpoint
(JMS Queue) from a POJO.
This works fine.
But I cannot test this Notifier because of this @Producer Endpoint.
*My EventNotifier:*
public class TrackingEventNotifier extends EventNotifierSupport {
private static final Logger LOG =
LoggerFactory.getLogger(TrackingEventNotifier.class);
@Produce("jms:queue:" + TRACKING_QUEUE)
private JmsProducer trackingProducer;
.....
*My Unit Test Route is quite simple:*
@SpringBootTest
@RunWith(CamelSpringBootRunner.class)
@ActiveProfiles("test")
@ContextConfiguration(classes = {
TrackingTestSpring.ContextConfig.class,
TrackingEventNotifier.class, JmsConfiguration.class,
JmsProducer.class, JmsEndpoint.class,
EventMessageBuilderFactory.class, TrackingFileMessageBuilder.class,
TrackingDefaultMessageBuilder.class})
@MockEndpointsAndSkip("jms")
public class TrackingTestSpring
...........
@Configuration
public static class ContextConfig extends SingleRouteCamelConfiguration
{
@Bean
public RouteBuilder route() {
return new RouteBuilder() {
public void configure() {
interceptSendToEndpoint("jms:queue")
.log("INTERCEPTED");
from("direct:start")
.routeId("TestRoute")
.log("Content: ${body}")
*Within the UnitTest* I tried to intercept this endpoint. But this does not
work because Camel tries to send to this endpoint which is not configured
during the Unit Tests Run.
Any suggestions how i can avoid this?
20:57:03.221 [main] WARN org.apache.camel.support.EventHelper - Error
notifying event ID-atcw-033195-1593802621850-0-1 exchange
Exchange[ID-atcw-033195-1593802621850-0-1] sent to: file://data took: 12
ms.. This exception will be ignored.
java.lang.IllegalArgumentException: *connectionFactory must be specified*
at org.apache.camel.util.ObjectHelper.notNull(ObjectHelper.java:152)
at
org.apache.camel.component.jms.JmsConfiguration.createConnectionFactory(JmsConfiguration.java:1629)
Thank you so much for any help
Re: Unit Test with @producer endpoints
Posted by Claus Ibsen <cl...@gmail.com>.
You need to mark to skip also for intercept send to endpoint.
On Fri, Jul 3, 2020 at 9:09 PM Michael Rambichler <mi...@rambichler.at> wrote:
>
> Dear Camel Specialists,
>
> I have an EventNotifier where I send a message to another camel endpoint
> (JMS Queue) from a POJO.
> This works fine.
>
> But I cannot test this Notifier because of this @Producer Endpoint.
>
> *My EventNotifier:*
>
> public class TrackingEventNotifier extends EventNotifierSupport {
> private static final Logger LOG =
> LoggerFactory.getLogger(TrackingEventNotifier.class);
>
> @Produce("jms:queue:" + TRACKING_QUEUE)
> private JmsProducer trackingProducer;
> .....
>
> *My Unit Test Route is quite simple:*
>
> @SpringBootTest
> @RunWith(CamelSpringBootRunner.class)
> @ActiveProfiles("test")
> @ContextConfiguration(classes = {
> TrackingTestSpring.ContextConfig.class,
> TrackingEventNotifier.class, JmsConfiguration.class,
> JmsProducer.class, JmsEndpoint.class,
> EventMessageBuilderFactory.class, TrackingFileMessageBuilder.class,
> TrackingDefaultMessageBuilder.class})
> @MockEndpointsAndSkip("jms")
> public class TrackingTestSpring
>
> ...........
>
> @Configuration
> public static class ContextConfig extends SingleRouteCamelConfiguration
> {
>
> @Bean
> public RouteBuilder route() {
> return new RouteBuilder() {
> public void configure() {
>
> interceptSendToEndpoint("jms:queue")
> .log("INTERCEPTED");
>
> from("direct:start")
> .routeId("TestRoute")
> .log("Content: ${body}")
>
>
> *Within the UnitTest* I tried to intercept this endpoint. But this does not
> work because Camel tries to send to this endpoint which is not configured
> during the Unit Tests Run.
> Any suggestions how i can avoid this?
>
> 20:57:03.221 [main] WARN org.apache.camel.support.EventHelper - Error
> notifying event ID-atcw-033195-1593802621850-0-1 exchange
> Exchange[ID-atcw-033195-1593802621850-0-1] sent to: file://data took: 12
> ms.. This exception will be ignored.
> java.lang.IllegalArgumentException: *connectionFactory must be specified*
> at org.apache.camel.util.ObjectHelper.notNull(ObjectHelper.java:152)
> at
> org.apache.camel.component.jms.JmsConfiguration.createConnectionFactory(JmsConfiguration.java:1629)
>
> Thank you so much for any help
--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2