You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by contactreji <co...@gmail.com> on 2015/10/20 06:33:58 UTC
Camel Unit Test Cases - Using TestNG
Hello friends
I am trying to write a unit test suite for my camel project. I use TestNG
for running my test. My unit test class looks as follows. Can someone who
has done this kind of test cases help me out :-)
*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.impl.DefaultCamelContext;
import org.apache.camel.test.junit4.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;
UnitTests() throws Exception {
context = new DefaultCamelContext();
context.addRoutes(createRouteBuilder());
context.start();
}
@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");
}
};
}
}
*
But unfortunately I get a null pointor on execution. The log looks like
this..
*
Starting route...............
[ main] DefaultCamelContext INFO Apache
Camel 2.15.1.redhat-620133 (CamelContext: camel-1) is starting
[ main] ManagedManagementStrategy INFO JMX is
enabled
[ main] DefaultTypeConverter INFO Loaded
199 type converters
[ main] DefaultCamelContext INFO
AllowUseOriginalMessage is enabled. If access to the original message is not
needed, then its recommended to turn this option off as it may improve
performance.
[ main] DefaultCamelContext INFO
StreamCaching is not in use. If using streams then its recommended to enable
stream caching. See more details at
http://camel.apache.org/stream-caching.html
[ main] DefaultCamelContext INFO Route:
route1 started and consuming from: Endpoint[direct://start]
[ main] DefaultCamelContext INFO Total
1 routes, of which 1 is started.
[ main] DefaultCamelContext INFO Apache
Camel 2.15.1.redhat-620133 (CamelContext: camel-1) started in 0.531 seconds
[TestNG] Running:
C:\Users\Z001NLH\AppData\Local\Temp\testng-eclipse-462829702\testng-customsuite.xml
PASSED: testPrintMessage
FAILED: testSendMatchingMessage
java.lang.NullPointerException
at com.ds.case1.test.UnitTests.testSendMatchingMessage(UnitTests.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at
org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at
org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
===============================================
Default test
Tests run: 2, Failures: 1, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 2, Failures: 1, Skips: 0
===============================================
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@68f7aae2: 16
ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 15 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@5f8ed237: 0
ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@2e5c649: 63 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@3caeaf62: 46 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@75828a0f: 0 ms
*
My POM.xml looks like follows
*
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ds</groupId>
<artifactId>case1</artifactId>
<packaging>bundle</packaging>
<version>1.0.0-SNAPSHOT</version>
<name>ActiveMQ embedded with Camel</name>
<url>http://www.myorganization.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<timestamp>${maven.build.timestamp}</timestamp>
<maven.build.timestamp.format>yyyyMMdd-HHmm</maven.build.timestamp.format>
</properties>
<repositories>
<repository>
<id>release.fusesource.org</id>
<name>FuseSource Release Repository</name>
<url>http://repo.fusesource.com/nexus/content/repositories/releases</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
<repository>
<id>ea.fusesource.org</id>
<name>FuseSource Community Early Access Release Repository</name>
<url>http://repo.fusesource.com/nexus/content/groups/ea</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>release.fusesource.org</id>
<name>FuseSource Release Repository</name>
<url>http://repo.fusesource.com/nexus/content/repositories/releases</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</pluginRepository>
<pluginRepository>
<id>ea.fusesource.org</id>
<name>FuseSource Community Early Access Release Repository</name>
<url>http://repo.fusesource.com/nexus/content/groups/ea</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.15.1.redhat-620133</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-http</artifactId>
<version>2.15.1.redhat-620133</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-saxon</artifactId>
<version>2.15.1.redhat-620133</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jms</artifactId>
<version>2.15.1.redhat-620133</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring</artifactId>
<version>2.15.1.redhat-620133</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-client</artifactId>
<version>5.11.1</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-camel</artifactId>
<version>5.11.1</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-pool</artifactId>
<version>5.11.1</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-broker</artifactId>
<version>5.11.1</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-spring</artifactId>
<version>5.11.1</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-kahadb-store</artifactId>
<version>5.11.1</version>
</dependency>
<dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean-spring</artifactId>
<version>3.18</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.10</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.10</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-testng</artifactId>
<version>2.15.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.camel</groupId>
<artifactId>camel-maven-plugin</artifactId>
<version>2.15.1.redhat-620133</version>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.4</version>
<extensions>true</extensions>
<configuration>
<instructions>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<reportsDirectory>./test-output/${timestamp}</reportsDirectory>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</project>
*
-----
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-tp5772886.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel Unit Test Cases - Using TestNG
Posted by Claus Ibsen <cl...@gmail.com>.
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 <cl...@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 <co...@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
Re: Camel Unit Test Cases - Using TestNG
Posted by Claus Ibsen <cl...@gmail.com>.
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 <co...@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
Re: Camel Unit Test Cases - Using TestNG
Posted by contactreji <co...@gmail.com>.
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.
Re: Camel Unit Test Cases - Using TestNG
Posted by contactreji <co...@gmail.com>.
Thanks Claus.
It worked :-) . The import package statement was the culprit.
I replaced it with import org.apache.camel.testng.CamelTestSupport;
Cheers
-Reji
-----
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-tp5772886p5772894.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel Unit Test Cases - Using TestNG
Posted by Claus Ibsen <cl...@gmail.com>.
> import org.apache.camel.test.junit4.CamelTestSupport;
If you want to use tesgng you should use the camel-testng module, and
not the junit based.
On Tue, Oct 20, 2015 at 6:33 AM, contactreji <co...@gmail.com> wrote:
> Hello friends
>
> I am trying to write a unit test suite for my camel project. I use TestNG
> for running my test. My unit test class looks as follows. Can someone who
> has done this kind of test cases help me out :-)
>
> *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.impl.DefaultCamelContext;
> import org.apache.camel.test.junit4.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;
>
> UnitTests() throws Exception {
> context = new DefaultCamelContext();
> context.addRoutes(createRouteBuilder());
> context.start();
> }
>
> @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");
> }
> };
> }
> }
> *
>
>
> But unfortunately I get a null pointor on execution. The log looks like
> this..
>
> *
> Starting route...............
> [ main] DefaultCamelContext INFO Apache
> Camel 2.15.1.redhat-620133 (CamelContext: camel-1) is starting
> [ main] ManagedManagementStrategy INFO JMX is
> enabled
> [ main] DefaultTypeConverter INFO Loaded
> 199 type converters
> [ main] DefaultCamelContext INFO
> AllowUseOriginalMessage is enabled. If access to the original message is not
> needed, then its recommended to turn this option off as it may improve
> performance.
> [ main] DefaultCamelContext INFO
> StreamCaching is not in use. If using streams then its recommended to enable
> stream caching. See more details at
> http://camel.apache.org/stream-caching.html
> [ main] DefaultCamelContext INFO Route:
> route1 started and consuming from: Endpoint[direct://start]
> [ main] DefaultCamelContext INFO Total
> 1 routes, of which 1 is started.
> [ main] DefaultCamelContext INFO Apache
> Camel 2.15.1.redhat-620133 (CamelContext: camel-1) started in 0.531 seconds
> [TestNG] Running:
>
> C:\Users\Z001NLH\AppData\Local\Temp\testng-eclipse-462829702\testng-customsuite.xml
>
> PASSED: testPrintMessage
> FAILED: testSendMatchingMessage
> java.lang.NullPointerException
> at com.ds.case1.test.UnitTests.testSendMatchingMessage(UnitTests.java:37)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:497)
> at
> org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
> at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
> at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
> at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
> at
> org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
> at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
> at org.testng.TestRunner.privateRun(TestRunner.java:767)
> at org.testng.TestRunner.run(TestRunner.java:617)
> at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
> at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
> at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
> at org.testng.SuiteRunner.run(SuiteRunner.java:240)
> at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
> at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
> at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
> at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
> at org.testng.TestNG.run(TestNG.java:1057)
> at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
> at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
> at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
>
>
> ===============================================
> Default test
> Tests run: 2, Failures: 1, Skips: 0
> ===============================================
>
>
> ===============================================
> Default suite
> Total tests run: 2, Failures: 1, Skips: 0
> ===============================================
>
> [TestNG] Time taken by org.testng.reporters.JUnitReportReporter@68f7aae2: 16
> ms
> [TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 15 ms
> [TestNG] Time taken by org.testng.reporters.EmailableReporter2@5f8ed237: 0
> ms
> [TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@2e5c649: 63 ms
> [TestNG] Time taken by org.testng.reporters.jq.Main@3caeaf62: 46 ms
> [TestNG] Time taken by org.testng.reporters.XMLReporter@75828a0f: 0 ms
> *
>
>
>
> My POM.xml looks like follows
>
> *
> <?xml version="1.0" encoding="UTF-8"?>
> <project xmlns="http://maven.apache.org/POM/4.0.0"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
> http://maven.apache.org/maven-v4_0_0.xsd">
>
> <modelVersion>4.0.0</modelVersion>
>
> <groupId>com.ds</groupId>
> <artifactId>case1</artifactId>
> <packaging>bundle</packaging>
> <version>1.0.0-SNAPSHOT</version>
>
> <name>ActiveMQ embedded with Camel</name>
> <url>http://www.myorganization.org</url>
>
> <properties>
> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
> <timestamp>${maven.build.timestamp}</timestamp>
> <maven.build.timestamp.format>yyyyMMdd-HHmm</maven.build.timestamp.format>
> </properties>
>
> <repositories>
> <repository>
> <id>release.fusesource.org</id>
> <name>FuseSource Release Repository</name>
> <url>http://repo.fusesource.com/nexus/content/repositories/releases</url>
> <snapshots>
> <enabled>false</enabled>
> </snapshots>
> <releases>
> <enabled>true</enabled>
> </releases>
> </repository>
> <repository>
> <id>ea.fusesource.org</id>
> <name>FuseSource Community Early Access Release Repository</name>
> <url>http://repo.fusesource.com/nexus/content/groups/ea</url>
> <snapshots>
> <enabled>false</enabled>
> </snapshots>
> <releases>
> <enabled>true</enabled>
> </releases>
> </repository>
> </repositories>
>
> <pluginRepositories>
> <pluginRepository>
> <id>release.fusesource.org</id>
> <name>FuseSource Release Repository</name>
> <url>http://repo.fusesource.com/nexus/content/repositories/releases</url>
> <snapshots>
> <enabled>false</enabled>
> </snapshots>
> <releases>
> <enabled>true</enabled>
> </releases>
> </pluginRepository>
> <pluginRepository>
> <id>ea.fusesource.org</id>
> <name>FuseSource Community Early Access Release Repository</name>
> <url>http://repo.fusesource.com/nexus/content/groups/ea</url>
> <snapshots>
> <enabled>false</enabled>
> </snapshots>
> <releases>
> <enabled>true</enabled>
> </releases>
> </pluginRepository>
> </pluginRepositories>
>
> <dependencies>
> <dependency>
> <groupId>org.apache.camel</groupId>
> <artifactId>camel-core</artifactId>
> <version>2.15.1.redhat-620133</version>
> </dependency>
> <dependency>
> <groupId>org.apache.camel</groupId>
> <artifactId>camel-http</artifactId>
> <version>2.15.1.redhat-620133</version>
> </dependency>
> <dependency>
> <groupId>org.apache.camel</groupId>
> <artifactId>camel-saxon</artifactId>
> <version>2.15.1.redhat-620133</version>
> </dependency>
> <dependency>
> <groupId>org.apache.camel</groupId>
> <artifactId>camel-jms</artifactId>
> <version>2.15.1.redhat-620133</version>
> </dependency>
> <dependency>
> <groupId>org.apache.camel</groupId>
> <artifactId>camel-spring</artifactId>
> <version>2.15.1.redhat-620133</version>
> </dependency>
>
>
> <dependency>
> <groupId>org.apache.activemq</groupId>
> <artifactId>activemq-client</artifactId>
> <version>5.11.1</version>
> </dependency>
> <dependency>
> <groupId>org.apache.activemq</groupId>
> <artifactId>activemq-camel</artifactId>
> <version>5.11.1</version>
> </dependency>
> <dependency>
> <groupId>org.apache.activemq</groupId>
> <artifactId>activemq-pool</artifactId>
> <version>5.11.1</version>
> </dependency>
>
>
> <dependency>
> <groupId>org.apache.activemq</groupId>
> <artifactId>activemq-broker</artifactId>
> <version>5.11.1</version>
> </dependency>
> <dependency>
> <groupId>org.apache.activemq</groupId>
> <artifactId>activemq-spring</artifactId>
> <version>5.11.1</version>
> </dependency>
> <dependency>
> <groupId>org.apache.activemq</groupId>
> <artifactId>activemq-kahadb-store</artifactId>
> <version>5.11.1</version>
> </dependency>
> <dependency>
> <groupId>org.apache.xbean</groupId>
> <artifactId>xbean-spring</artifactId>
> <version>3.18</version>
> </dependency>
> <dependency>
> <groupId>org.springframework</groupId>
> <artifactId>spring-context</artifactId>
> <version>4.1.6.RELEASE</version>
> </dependency>
>
>
> <dependency>
> <groupId>org.slf4j</groupId>
> <artifactId>slf4j-api</artifactId>
> <version>1.7.10</version>
> </dependency>
> <dependency>
> <groupId>org.slf4j</groupId>
> <artifactId>slf4j-log4j12</artifactId>
> <version>1.7.10</version>
> </dependency>
> <dependency>
> <groupId>log4j</groupId>
> <artifactId>log4j</artifactId>
> <version>1.2.17</version>
> </dependency>
>
>
> <dependency>
> <groupId>org.apache.camel</groupId>
> <artifactId>camel-testng</artifactId>
> <version>2.15.1</version>
> <scope>compile</scope>
> </dependency>
>
>
>
> </dependencies>
>
> <build>
> <defaultGoal>install</defaultGoal>
>
> <plugins>
> <plugin>
> <groupId>org.apache.maven.plugins</groupId>
> <artifactId>maven-compiler-plugin</artifactId>
> <version>2.5.1</version>
> <configuration>
> <source>1.7</source>
> <target>1.7</target>
> </configuration>
> </plugin>
> <plugin>
> <groupId>org.apache.maven.plugins</groupId>
> <artifactId>maven-resources-plugin</artifactId>
> <version>2.6</version>
> <configuration>
> <encoding>UTF-8</encoding>
> </configuration>
> </plugin>
>
>
> <plugin>
> <groupId>org.apache.camel</groupId>
> <artifactId>camel-maven-plugin</artifactId>
> <version>2.15.1.redhat-620133</version>
> </plugin>
> <plugin>
> <groupId>org.apache.felix</groupId>
> <artifactId>maven-bundle-plugin</artifactId>
> <version>2.3.4</version>
> <extensions>true</extensions>
> <configuration>
> <instructions>
>
> </instructions>
> </configuration>
> </plugin>
> <plugin>
> <groupId>org.apache.maven.plugins</groupId>
> <artifactId>maven-surefire-plugin</artifactId>
> <version>2.16</version>
> <configuration>
> <reportsDirectory>./test-output/${timestamp}</reportsDirectory>
> <suiteXmlFiles>
> <suiteXmlFile>testng.xml</suiteXmlFile>
> </suiteXmlFiles>
> </configuration>
> </plugin>
> </plugins>
> </build>
>
> </project>
>
> *
>
>
>
> -----
> 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-tp5772886.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