You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Olaf <om...@gmail.com> on 2013/10/17 20:15:41 UTC

How to mock a processor

Hello,

I'm trying to test a simple route which downloads emails and then split
attachments, replace body and sends each attachment to an another email.
Now, ReplaceBodyProcessor does some network calls and I'd like to mock it
out and simulate its work, to avoid external calls. What is the right way to
do it?

Thanks in advance!

        @Override
        public void configure() {
          
           from("imap://host?username=user&password=pass")
                .split(new SplitAttachmentsExpression())
                .process(new MailProcessor())
                .process(new ReplaceBodyProcessor())
                .choice()
                .when(header("attachmentName").regex("^.*(txt|TXT)$"))
                    .to("imap://host?username=user2&password=pass2")
                    .id("targetmail");
        }








--
View this message in context: http://camel.465427.n5.nabble.com/How-to-mock-a-processor-tp5741786.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to mock a processor

Posted by Olaf <om...@gmail.com>.
I did add the id later, so it worked, but weaveByToString does not work.
Anyway, I'm going to use ids



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-mock-a-processor-tp5741786p5741801.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to mock a processor

Posted by Christian Posta <ch...@gmail.com>.
It would be wise to give your nodes IDs so you can intercept them easier:

eg:

.process(new ReplaceBodyProcessor()).id("replaceBody")

I'm not even sure how it did work for you with

weaveById("ReplaceBodyProcessor") because camel uses a default id of
"processN" where N is an incrementing integer if no ID is defined.

weaveByToString should work as you have it...




On Thu, Oct 17, 2013 at 12:11 PM, Olaf <om...@gmail.com> wrote:

> Thanks! That helps a lot.
>
> Somehow, I can only mock with weaveBeId method:
>
>
> weaveById("ReplaceBodyProcessor").replace().to("mock:ReplaceBodyProcessor");
>
> then it is ReplaceBodyProcessor is skipped in test.
>
> If using
>
> weaveByToString(".*ReplaceBodyProcessor.*").replace().to("mock:ReplaceBodyProcessor");
>
> or public String isMockEndpoints() {return "*";}
>
> my test fails. What am I doing wrong?
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/How-to-mock-a-processor-tp5741786p5741793.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta

Re: How to mock a processor

Posted by Olaf <om...@gmail.com>.
Thanks! That helps a lot. 

Somehow, I can only mock with weaveBeId method:

weaveById("ReplaceBodyProcessor").replace().to("mock:ReplaceBodyProcessor");

then it is ReplaceBodyProcessor is skipped in test. 

If using 
weaveByToString(".*ReplaceBodyProcessor.*").replace().to("mock:ReplaceBodyProcessor"); 

or public String isMockEndpoints() {return "*";}

my test fails. What am I doing wrong?




--
View this message in context: http://camel.465427.n5.nabble.com/How-to-mock-a-processor-tp5741786p5741793.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to mock a processor

Posted by Christian Posta <ch...@gmail.com>.
Take a look here:

http://camel.apache.org/mock.html

and the "Mocking existing endpoint" section




On Thu, Oct 17, 2013 at 11:15 AM, Olaf <om...@gmail.com> wrote:

> Hello,
>
> I'm trying to test a simple route which downloads emails and then split
> attachments, replace body and sends each attachment to an another email.
> Now, ReplaceBodyProcessor does some network calls and I'd like to mock it
> out and simulate its work, to avoid external calls. What is the right way
> to
> do it?
>
> Thanks in advance!
>
>         @Override
>         public void configure() {
>
>            from("imap://host?username=user&password=pass")
>                 .split(new SplitAttachmentsExpression())
>                 .process(new MailProcessor())
>                 .process(new ReplaceBodyProcessor())
>                 .choice()
>                 .when(header("attachmentName").regex("^.*(txt|TXT)$"))
>                     .to("imap://host?username=user2&password=pass2")
>                     .id("targetmail");
>         }
>
>
>
>
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/How-to-mock-a-processor-tp5741786.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta

Re: How to mock a processor

Posted by contactreji <co...@gmail.com>.
I shall give u a small advice on this .
Pls note. All components don't support attachment . Attachments in the Camel exchange might be lost while passing throughout some Camel components. So by rule of thumb,  make sure attachments are added to the exchange just before calling an email component.

Cheers 
Reji

"Olaf [via Camel]" <ml...@n5.nabble.com> wrote:

>
>
>Hello,
>
>I'm trying to test a simple route which downloads emails and then split
>attachments, replace body and sends each attachment to an another email.
>Now, ReplaceBodyProcessor does some network calls and I'd like to mock it
>out and simulate its work, to avoid external calls. What is the right way to
>do it?
>
>Thanks in advance!
>
>        @Override
>        public void configure() {
>          
>           from("imap://host?username=user&password=pass")
>                .split(new SplitAttachmentsExpression())
>                .process(new MailProcessor())
>                .process(new ReplaceBodyProcessor())
>                .choice()
>                .when(header("attachmentName").regex("^.*(txt|TXT)$"))
>                    .to("imap://host?username=user2&password=pass2")
>                    .id("targetmail");
>        }
>
>
>
>
>
>
>
>
>_______________________________________________
>If you reply to this email, your message will be added to the discussion below:
>http://camel.465427.n5.nabble.com/How-to-mock-a-processor-tp5741786.html
>
>To unsubscribe from Camel - Users, visit http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=465428&code=Y29udGFjdHJlamlAZ21haWwuY29tfDQ2NTQyOHwxMDA0OTE4MjMz



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-mock-a-processor-tp5741786p5741792.html
Sent from the Camel - Users mailing list archive at Nabble.com.