camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From contactreji <>
Subject Re: Camel Unit Test Cases - Using TestNG
Date Tue, 20 Oct 2015 07:17:18 GMT
Hey all

As of now, I have a route created using RouteBuilder API in my below test

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;
	public void testPrintMessage() {
		String message = "TestSample";
		Assert.assertEquals(message, "TestSample");

	public void testSendMatchingMessage() throws Exception {
		String expectedBody = "<matched/>";
		template.sendBodyAndHeader("direct:start", expectedBody, "foo", "bar");

	protected RouteBuilder createRouteBuilder() {
		System.out.println("Starting route...............");
		return new RouteBuilder() {
			public void configure() {
						.log("Route EXECUTED .......").to("mock:result");

Reji Mathews
Sr. Developer - Middleware Integration / SOA ( Open Source - Apache Camel & Jboss Fuse
ESB | Mule ESB )
LinkedIn -
Twitter - reji_mathews
View this message in context:
Sent from the Camel - Users mailing list archive at

View raw message