camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: Camel Unit Test Cases - Using TestNG
Date Tue, 20 Oct 2015 07:36:16 GMT
Ah sorry I was to fast, there is a CamelSpringTestSupport in
camel-testng you can use.

See how it test itself in its own unit tests of camel-testng

On Tue, Oct 20, 2015 at 9:34 AM, Claus Ibsen <claus.ibsen@gmail.com> wrote:
> If camel-context.xml is a spring xml file, then you must use
> camel-test-spring for unit testing
>
> On Tue, Oct 20, 2015 at 9:17 AM, contactreji <contactreji@gmail.com> wrote:
>> Hey all
>>
>> As of now, I have a route created using RouteBuilder API in my below test
>> class.
>>
>> I was kinda wondering if I can start routes defined in camel-context.xml
>> file in the project class path. What if I wanna unit test the routes in
>> camel-context.xml file. Is there a way I can modify my below test class to
>> start the routes in xml dsl file?
>>
>>
>> *
>> package com.ds.case1.test;
>>
>> import org.apache.camel.EndpointInject;
>> import org.apache.camel.Produce;
>> import org.apache.camel.ProducerTemplate;
>> import org.apache.camel.builder.RouteBuilder;
>> import org.apache.camel.component.mock.MockEndpoint;
>> import org.apache.camel.testng.CamelTestSupport;
>> import org.testng.Assert;
>> import org.testng.annotations.Test;
>>
>> public class UnitTests extends CamelTestSupport {
>>
>>         @EndpointInject(uri = "mock:result")
>>         protected MockEndpoint resultEndpoint;
>>
>>         @Produce(uri = "direct:start")
>>         protected ProducerTemplate template;
>>
>>         @Test
>>         public void testPrintMessage() {
>>                 String message = "TestSample";
>>                 Assert.assertEquals(message, "TestSample");
>>         }
>>
>>         @Test
>>         public void testSendMatchingMessage() throws Exception {
>>                 String expectedBody = "<matched/>";
>>                 getMockEndpoint("mock:result").expectedBodiesReceived(expectedBody);
>>                 template.sendBodyAndHeader("direct:start", expectedBody, "foo", "bar");
>>                 assertMockEndpointsSatisfied();
>>                 assertTrue(true);
>>         }
>>
>>         @Override
>>         protected RouteBuilder createRouteBuilder() {
>>                 System.out.println("Starting route...............");
>>                 return new RouteBuilder() {
>>                         public void configure() {
>>                                 from("direct:start").filter(header("foo").isEqualTo("bar"))
>>                                                 .log("Route EXECUTED .......").to("mock:result");
>>                         }
>>                 };
>>         }
>> }
>> *
>>
>>
>>
>> -----
>> Reji Mathews
>> Sr. Developer - Middleware Integration / SOA ( Open Source - Apache Camel & Jboss
Fuse ESB | Mule ESB )
>> LinkedIn - http://in.linkedin.com/pub/reji-mathews/31/9a2/40a
>> Twitter - reji_mathews
>> --
>> View this message in context: http://camel.465427.n5.nabble.com/Camel-Unit-Test-Cases-Using-TestNG-tp5772886p5772895.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2nd edition:
> https://www.manning.com/books/camel-in-action-second-edition



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2nd edition:
https://www.manning.com/books/camel-in-action-second-edition

Mime
View raw message