You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by winniwinter <wi...@me.com> on 2014/12/19 16:04:58 UTC

@EndpointInject not working

Hi,



I'm using Camel 2.14.x and do Unit tests with
AbstractJUnit4SpringContextTests. 
My routes are written in java dsl. The camelcontext gets instantiated by
spring.

I want to mock my endpoint and don't know/understand the best practise

My route looks like that:

        from("direct:application").id("firstbird-incomming-applications")
               
.to("log:eu.firstbird.firstbirdapi.application.consumer.firstbird-incomming-applications-start?level=INFO")
                .log(LoggingLevel.INFO, logger, "Sending job application to
queue")
                .setExchangePattern(ExchangePattern.InOnly)
                .dynamicRouter().method(customerRouter,
"routeApplicationByCustomerType")
                .process(new FirstbirdApplicationResponseProcessor())
               
.to("log:eu.firstbird.firstbirdapi.application.consumer.firstbird-incomming-applications-end?level=INFO");


Now I would like to mock the last log statement. To do that I thought I just
do it like that:

@EndpointInject(uri =
"mock:log:eu.firstbird.firstbirdapi.application.consumer.firstbird-incomming-applications-end")
    private MockEndpoint mock;


But sadly that doesn't work. I don't have any exchanges...



--
View this message in context: http://camel.465427.n5.nabble.com/EndpointInject-not-working-tp5760927.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: @EndpointInject not working

Posted by winniwinter <wi...@me.com>.
Hi Claus,

thanks for your reply. 

I updated my test according to your description but it doesn't work

@MockEndpoints
public class FirstBirdApplicationsTest extends
AbstractJUnit4SpringContextTests {

....
    @EndpointInject(uri =
"mock:log:eu.firstbird.firstbirdapi.application.consumer.firstbird-incomming-applications-end?level=INFO")
    private MockEndpoint mock;

...
}

That does not work. I payed a little bit around and came across the
AdviceWith statement. That actually works..but I quite don't understand it
:O   :

public class FirstBirdApplicationsTest extends
AbstractJUnit4SpringContextTests {
....
    @EndpointInject(uri =
"mock:log:eu.firstbird.firstbirdapi.application.consumer.firstbird-incomming-applications-end")
    private MockEndpoint mock;

...
    @Test
    public void firstbirdApplicationsConsumerContextTest() throws Exception
{
        ModelCamelContext modelCamelContext =
(ModelCamelContext)camelContext;

        camelContext.setTracing(true);
        assertEquals(true, camelContext.isTracing());

        DefaultExchange exchange = new DefaultExchange(camelContext);
        mock.expectedMessageCount(1);

       
modelCamelContext.getRouteDefinition("firstbird-incomming-applications").adviceWith(modelCamelContext,
                new AdviceWithRouteBuilder() {

                    @Override
                    public void configure() throws Exception {
                       
mockEndpoints("log:eu.firstbird.firstbirdapi.application.consumer*");
                    }
                });
...




--
View this message in context: http://camel.465427.n5.nabble.com/EndpointInject-not-working-tp5760927p5760929.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: @EndpointInject not working

Posted by Minh Tran <da...@gmail.com>.
Hi Claus,

How strict is the @EndpointInject uri parameter? I’ve never included anything past the ? and it has managed to inject the mock endpoints for me? 
eg

<to uri=“jms:queue:my_queue?transacted=true”/>

@EndpointInject(uri=“mock:jms:queue:my_queue”)
MockEndpoint mockJms;


On 20 Dec 2014, at 2:52 am, Claus Ibsen <cl...@gmail.com> wrote:

> Hi
> 
> There is an annotation you need to use
> 
> @MockEndpoints
> 
> And in your @EndpointInject you must use 100% the same url as in the
> route, but with "mock:" as prefix. Also including the ? parameters.
> 
> On Fri, Dec 19, 2014 at 4:04 PM, winniwinter <wi...@me.com> wrote:
>> Hi,
>> 
>> 
>> 
>> I'm using Camel 2.14.x and do Unit tests with
>> AbstractJUnit4SpringContextTests.
>> My routes are written in java dsl. The camelcontext gets instantiated by
>> spring.
>> 
>> I want to mock my endpoint and don't know/understand the best practise
>> 
>> My route looks like that:
>> 
>>        from("direct:application").id("firstbird-incomming-applications")
>> 
>> .to("log:eu.firstbird.firstbirdapi.application.consumer.firstbird-incomming-applications-start?level=INFO")
>>                .log(LoggingLevel.INFO, logger, "Sending job application to
>> queue")
>>                .setExchangePattern(ExchangePattern.InOnly)
>>                .dynamicRouter().method(customerRouter,
>> "routeApplicationByCustomerType")
>>                .process(new FirstbirdApplicationResponseProcessor())
>> 
>> .to("log:eu.firstbird.firstbirdapi.application.consumer.firstbird-incomming-applications-end?level=INFO");
>> 
>> 
>> Now I would like to mock the last log statement. To do that I thought I just
>> do it like that:
>> 
>> @EndpointInject(uri =
>> "mock:log:eu.firstbird.firstbirdapi.application.consumer.firstbird-incomming-applications-end")
>>    private MockEndpoint mock;
>> 
>> 
>> But sadly that doesn't work. I don't have any exchanges...
>> 
>> 
>> 
>> --
>> View this message in context: http://camel.465427.n5.nabble.com/EndpointInject-not-working-tp5760927.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
> 
> 
> 
> -- 
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: cibsen@redhat.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
> hawtio: http://hawt.io/
> fabric8: http://fabric8.io/


Re: @EndpointInject not working

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

There is an annotation you need to use

@MockEndpoints

And in your @EndpointInject you must use 100% the same url as in the
route, but with "mock:" as prefix. Also including the ? parameters.

On Fri, Dec 19, 2014 at 4:04 PM, winniwinter <wi...@me.com> wrote:
> Hi,
>
>
>
> I'm using Camel 2.14.x and do Unit tests with
> AbstractJUnit4SpringContextTests.
> My routes are written in java dsl. The camelcontext gets instantiated by
> spring.
>
> I want to mock my endpoint and don't know/understand the best practise
>
> My route looks like that:
>
>         from("direct:application").id("firstbird-incomming-applications")
>
> .to("log:eu.firstbird.firstbirdapi.application.consumer.firstbird-incomming-applications-start?level=INFO")
>                 .log(LoggingLevel.INFO, logger, "Sending job application to
> queue")
>                 .setExchangePattern(ExchangePattern.InOnly)
>                 .dynamicRouter().method(customerRouter,
> "routeApplicationByCustomerType")
>                 .process(new FirstbirdApplicationResponseProcessor())
>
> .to("log:eu.firstbird.firstbirdapi.application.consumer.firstbird-incomming-applications-end?level=INFO");
>
>
> Now I would like to mock the last log statement. To do that I thought I just
> do it like that:
>
> @EndpointInject(uri =
> "mock:log:eu.firstbird.firstbirdapi.application.consumer.firstbird-incomming-applications-end")
>     private MockEndpoint mock;
>
>
> But sadly that doesn't work. I don't have any exchanges...
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/EndpointInject-not-working-tp5760927.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/