Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: wording / reference to Felix connect

...

Info

camel-test-blueprint does only support testing one CamelContext. So if you have 2 two or more CamelContexts in your blueprint XML files, then only the CamelContext first found CamelContext is used during testing.

Testing is a crucial part of any development or integration work. Camel supports the definition of Blueprint routes, but given that Blueprint is an OSGi specific technology, writing unit tests is quite difficult. This library leverages PojoSR (now Felix Connect) which provides a service registry without using a fully compliant OSGi container. This allows defining real unit tests (as opposed to integration tests using Pax Exam. Please make sure all test jars in you class path your classpath are OSGi bundlebundles.

Wiki Markup
{snippet:lang=java|id=example|url=camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/DebugBlueprintTest.java}
Also notice the use of getBlueprintDescriptor to specify the location of the OSGi Blueprint XML file.
If you have multiple OSGi Blueprint XML files, then you can specify them with a comma-separated list in the getBlueprintDescriptor method.

Here's the Blueprint XML file:

Wiki Markup
{snippet:lang=xml|id=example|url=camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/camelContext.xml}
In order to define blueprint tests, add the following dependency in to your pom:

Code Block
xml
xml
<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-test-blueprint</artifactId>
  <version>2.10</version>
  <scope>test</scope>
</dependency>

...

By default PojoSR test container scans the test classpath for all the OSGi bundles available there. All the bundles with Blueprint descriptor files will be automatically started by the test container. If you would like to prevent particular bundles from being started by the test container, override the getBundleFilter method, just as demonstrated on in the snippet below. 

Code Block
languagejava
@Override
protected String getBundleFilter() {
  // I don't want test container to scan and load Logback bundle during the test
  return "(!(Bundle-SymbolicName=ch.qos.logback.core))";
}


Keep in mind that not specifying the Blueprint descriptor in the getBlueprintDescriptor method will not prevent the test container from loading a given descriptor. Bundle filter The getBundleFilter method is the proper way of filtering out bundles you don't want to start during the test.

...

CamelBlueprintTestSupport waits 30 sec seconds for Camel Context to be ready by default, now you can override this value in two ways:

...

When using camel-test-blueprint you may do unit tests which requires using shared services which is are not available during unit testing, but only in the real OSGi container, for example a shared DataSource.

...