This is a good source: http://camel.apache.org/mock.html

Sent from a mobile device
Am 26.02.2013 12:02 schrieb "shyenuganti" <shyenuga...@gmail.com>:

> Hi ,
>
> Here is a sample test for my Camel route.
>
> I am overriding the camel context to replace a JMS Endpoint  with a Mock.
> And setting the expectations on the route and trying to assert it.  But
> this
> test is failing. Can anyone see a problem in my test ? Instead of adding a
> mock to my production route, I am changing the JMS to Mock on the fly in
> the
> unit test. Can this be done ? If yes, What is wrong in my unit test ?
>
> Please help.
>
>
>
> public class EventListenerRouteMockTest extends CamelSpringTestSupport {
>
>                 @EndpointInject(uri = "jms:queue/jbossEventQueue")
>             protected MockEndpoint mock;
>
>             @EndpointInject(uri = "jms:queue/jbossEventQueue")
>             Endpoint endPoint;
>
>             @Produce(uri = "direct:eventMessageList")
>             protected ProducerTemplate producer;
>
>             @Test
>             public void testSendMatchingMessage() throws Exception {
>
>                 System.out.println("Starting the test ...");
>                 EventQueue event = new EventQueue();
>                         event.setEventMessage("TestMessage");
>
>                         List<EventQueue> expectedBodies = new
> ArrayList<EventQueue>();
>                         expectedBodies.add(event);
>
>                         mock.setExpectedMessageCount(1);
>                         mock.expectedBodiesReceived(expectedBodies);
>
>                         producer.sendBody("direct:eventMessageList",
> event);
>                         mock.assertIsSatisfied();
>
>
>
>             }
>
>             @Override
>             protected RouteBuilder createRouteBuilder() {
>
>                 System.out.println("Creating RouteBuilder ...");
>                 //return new EventListenerRoute();
>                 return new RouteBuilder() {
>                     public void configure() {
>
> from("direct:eventMessageList").id("PseudoEventQueue")
>                                 .to("log:{exchange}?level=INFO")
>                                 .to("jms:queue");
>                     }
>                 };
>             }
>
>             @Override
>             protected CamelContext createCamelContext() throws Exception {
>                 System.out.println("Overriding JMS with Mock ...");
>                 CamelContext context = super.createCamelContext();
>                         context.addComponent("jms",
> context.getComponent("mock"));
>                     return context;
>             }
>
>                 @Override
>                 protected AbstractApplicationContext
> createApplicationContext() {
>                         System.out.println("createApplicationContext()
> method");
>                         return new
> ClassPathXmlApplicationContext("META-INF/spring/testCamelContext.xml");
>                 }
>         }
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Issue-Replacing-a-component-with-Mock-in-Camel-Context-tp5728195.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Reply via email to