I am getting up to speed with the FUSE and OSGi and trying to put together a simple blueprint test that should check a Camel route (written by another developer):
public class CamelBrokerTest extends CamelBlueprintTestSupport {
@Override
protected String getBlueprintDescriptor() {
return "OSGI-INF/blueprint/peoplesoft-service.xml";
}
@Test
public void testRoute() throws Exception {
MockEndpoint endpoint = getMockEndpoint("seda:peopleSoftFinanceSchedulerProcessInstances");
endpoint.expectedMessageCount(1);
template.sendBody("activemq:peopleSoftFinanceIncomingFiles", "TRANSACTION_INFO");
assertMockEndpointsSatisfied();
}
}
However, when I try to run it, I end up getting
Caused by: java.lang.ClassNotFoundException: ca.custom.camel.servlet.registry.CamelServletHTTPRegistry
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
... 40 more
The dependency containing the class is included in the POM file with the test scope:
<dependency>
<groupId>ca.custom</groupId>
<artifactId>camel-servlet-osgi</artifactId>
<version>${camel.servlet.osgi.version}</version>
<scope>test</scope>
</dependency>
And I verified that the file is in the repo, and actually contains the required files. It also looks like the generated OSGi bundle descriptor has the correct dependencies also:
Import-Package: ca.custom.camel.servlet.osgi;version="[1.1,2)",ca.
custom.camel.servlet.registry,ca.mcmaster.uts.service.directory.i
ntegration;version="[1.2,2)",javax.jws,javax.jws.soap,javax.net.ssl,jav
ax.security.auth.callback,javax.xml.bind,javax.xml.bind.annotation,java
This code seems to be running well in production, yet, fails when executed as a JUnit test. Any ideas as to why this exception might occur? Did I miss any configuration steps?
ClassNotFoundException is as far as I know the way of osgi to enforce you to use only packages and bundles that you have declared as dependencies in the manifest file so what I would check is the export packages of the bundle containing the class you are trying to use and see if it matches with the imports that you are using! Another thing is that the bundle you are trying to use might not be activated yet !