1

I'd like to test Camel Routes implemented with Blueprint-XML. When trying to test a route with a simple "direct"-from endpoint, everything works fine.

But changing the "from" endpoint to the netty or jetty component, the test fails with the following exception:

java.lang.RuntimeException: Gave up waiting for BlueprintContainer from bundle 'MyRouteTest'

The route I have looks like this:

<route id="test">
 <from uri="jetty:http://test:8080/sample/test?matchOnUriPrefix=true" />
 <log id="_log1" loggingLevel="INFO" message="Test " />
</route>

My test class which extends CamelBlueprintTestSupport looks like this:

// imports...

public class MyRouteTest extends CamelBlueprintTestSupport {


    @Override
    protected String getBlueprintDescriptor() {
        return "/OSGI-INF/blueprint/blueprint2.xml";
    }

    @Test
    public void testRoute() throws Exception {

        context.getRouteDefinition("test").adviceWith(context, new AdviceWithRouteBuilder() {
            @Override
            public void configure() throws Exception {
                replaceFromWith("direct:myMock");
            }
        });
        assert (true);

    }
}

Modifying the route to

<route id="test">
  <from
    uri="direct:halloTest" />
  <log id="_log1" loggingLevel="INFO" message="Test " />
</route>

by replacing the from part from jetty to direct works fine (e.g. the test runs without errors and of course ends up positive beccause of the assert(true) check)

Can anybody help me?

The output of mvn test is

ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 31.843 s <<< FAILURE! - myPackage.MyRouteTest
[ERROR] testRoute(myPackage.MyRouteTest)  Time elapsed: 31.544 s  <<< ERROR!
java.lang.RuntimeException: Gave up waiting for BlueprintContainer from bundle "MyRouteTest"

[INFO]
[INFO] Results:
[INFO]
[ERROR] Errors:
[ERROR]   MyRouteTest>CamelBlueprintTestSupport.setUp:241->CamelBlueprintTestSupport.createBundleContext:175 ▒ Runtime
[INFO]
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
ian_eve
  • 97
  • 2
  • 8
  • You need to install these new components you are using, eg camel-jetty for jetty component and so on. This can also be done via CamelBlueprintTestSupport or use camel-test-karaf – Claus Ibsen Oct 02 '19 at 10:43
  • OK, even when I want to mock the component and not use it in real for the test? How exactly is the installation done? I can't find a documentation, neither in the corresponding JavaDoc, nor in your Camel book. – ian_eve Oct 02 '19 at 10:58
  • You need to tell the test class that you are using advice, see the docs about that, or in the book (p 385) – Claus Ibsen Oct 02 '19 at 15:23

1 Answers1

0

The soultion is to add the following code to the test class:

Modifying the route to

    @Override
    public boolean isUseAdviceWith() {
        return true;
    }
ian_eve
  • 97
  • 2
  • 8