ian_eve
ian_eve

Reputation: 107

Testing from-Endpoints with CamelBlueprintTestSupport fails with some components

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

Upvotes: 2

Views: 487

Answers (1)

ian_eve
ian_eve

Reputation: 107

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

Modifying the route to

    @Override
    public boolean isUseAdviceWith() {
        return true;
    }

Upvotes: 0

Related Questions