Pax-Testing camel routes in Karaf with CamelTestSupport on recent versions

30 views
Skip to first unread message

Dietrich Schulten

unread,
Nov 29, 2019, 3:59:18 AM11/29/19
to OPS4J
Hi,

I want to test Camel routes in Karaf. I use Pax-Exam to run Karaf. 
For older Karaf and Camel versions, I found a blog article by J.B. Onofre which shows how one can use CamelTestSupport to do that.

I got it working on JDK 8 for an older combination of Camel, Karaf and PaxExam with numerous adjustments (see links below). But when I switch to the current versions (Camel 2.24.2, Karaf 4.2.7, Pax-Exam 4.13.1), the CamelTestSupport setup fails, complaining with ClassNotFoundException: org.apache.camel.util.jndi.CamelInitialContextFactory.

When I disable the CamelTestSupport.setUp() method by overriding it with an empty method, I can see that the camel-core feature is present:

assertTrue(featuresService.isInstalled(featuresService.getFeature("camel-core")));

I have also tried to import the org.apache.camel.util.jndi package into the probe bundle. The package gets exported by the camel-core bundle jar, at least its MANIFEST.MF says so.

    @ProbeBuilder
    public TestProbeBuilder probeConfiguration(TestProbeBuilder probe) {
        probe.setHeader(Constants.IMPORT_PACKAGE, "*,org.apache.camel.util.jndi");
        return probe;
    }

The import appears to work, at least I get no import error during test execution.

Why can the test bundle not find the CamelInitialContextFactory?

I have created a clone of J.B. Onofre's Github example which fixes the JDK 8 issues and another one with recent versions which demonstrates the problem.


Here is my stack overflow question with all the details and other attempts I have made:
https://stackoverflow.com/questions/59075424/testing-camel-2-24-x-routes-in-karaf-4-2-7-with-cameltestsupport

Best,
Dietrich

Jean-Baptiste Onofré

unread,
Nov 29, 2019, 4:02:38 AM11/29/19
to op...@googlegroups.com

Hi,

CamelTestSupport is for utest whereas pax-exam is more for itest.

You can take a look on some itest I did about Camel, for instance:

https://github.com/apache/karaf-decanter/pull/111/files#diff-f23addf50c34ea79c8df17bb2861d649

So, you should *NOT* use CamelTestSupport for itest (and keep it for utest), and directly use producerTemplate, etc for itest.

Regards

JB

--
--
------------------
OPS4J - http://www.ops4j.org - op...@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ops4j+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/99d4fc11-99bb-44b9-8385-f07bd559a22c%40googlegroups.com.

Dietrich Schulten

unread,
Nov 29, 2019, 6:03:50 AM11/29/19
to OPS4J
Hi,

thank you very much, I was already wondering if CamelTestSupport is still a good fit for Pax Karaf Tests. You gave a clear opinion here :)

I see you have built your test upon KarafTestSupport and I was already able to get that to work in my environment, so that looks most promising.
I'll try to update my clone of your older tutorial accordingly.

Best,
Dietrich

To unsubscribe from this group and stop receiving emails from it, send an email to op...@googlegroups.com.

Jean-Baptiste Onofré

unread,
Nov 29, 2019, 6:50:45 AM11/29/19
to op...@googlegroups.com

Hi Dietrich

Just a small note: I did cleanups/improvements on KarafTestSupport in Karaf 4.2.8-SNAPSHOT. It's easier to use now. So I would advice to use KarafTestSupport from Karaf 4.2.8-SNAPSHOT (I'm preparing Karaf 4.2.8 anyway ;) ).

Regards
JB

To unsubscribe from this group and stop receiving emails from it, send an email to ops4j+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/4122b478-6c40-4f75-bad3-e4b9491e8bde%40googlegroups.com.

Dietrich Schulten

unread,
Nov 30, 2019, 4:25:41 AM11/30/19
to OPS4J
Exactly. Those spring and activemq versions were a bit painful indeed :)

Btw your old blog code is running again
https://github.com/dschulten/blog-camel-blueprint/tree/karaf4-paxexam4. Care for a PR to your blog sample after 4.2.8 is out?

Best,
Dietrich

Jean-Baptiste Onofré

unread,
Nov 30, 2019, 4:46:14 AM11/30/19
to op...@googlegroups.com
Hi Dietrich,

Yeah, it's a pretty old blog post ;) I think it makes sense to add or
extend the Karaf examples.

I will do it.

Thanks,
Regards
JB
Reply all
Reply to author
Forward
0 new messages