Ok, I've solve my issue (using a really naive solution). With maven I've created a bundle out of all the classes which were in the conditional-package BND instruction. Then I've simply added the newly created bundle within the @Configuration Pax-Exam method.
Maybe it's not the best solution, but works. Il giorno mar 20 nov 2018 alle ore 11:34 Massimo Bono < massimobo...@gmail.com> ha scritto: > Hello, > > I want to test an OSGi bundle built with bnd using conditional-packages > via pax-exam. The conditional-package allows the bundle to use some utility > classes (e.g., like from https://stackoverflow.com/a/39500621/1887602) > > The test is setup like the following: > > @Test > public void exampleTest() { > UtilityClass.foo(this.wiredService) > } > > where: > - wiredService is a service which has been injected via @javax.Inject; > - UtilityClass is the class which has been bundled in the jar with the > conditional-package. > > The test container I'm using is Karaf. > > When testing the application, Osgi alerts me that it cannot find the class > "x.y.z.UtilityClass". > > So my question is: how can I retrieve conditional-package classes using > pax-exam? > > Here's the (anonymized) stack trace: > > java.lang.ClassNotFoundException: x.y.z.UtilityClass not found by >> PAXEXAM-PROBE-1ac529cd-015d-4378-a3fa-f4cef4789ef8 [75] >> at >> org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1639) >> at >> org.apache.felix.framework.BundleWiringImpl.access$200(BundleWiringImpl.java:80) >> at >> org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2053) >> at java.lang.ClassLoader.loadClass(ClassLoader.java:357) >> at x.y.z.TestOsgiCommon.test00(TestOsgiCommon.java:271) >> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >> at >> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) >> at >> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) >> at java.lang.reflect.Method.invoke(Method.java:498) >> at >> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) >> at >> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) >> at >> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) >> at >> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) >> at >> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) >> at >> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) >> at >> org.ops4j.pax.exam.invoker.junit.internal.ContainerTestRunner.runLeafWithRetry(ContainerTestRunner.java:97) >> at >> org.ops4j.pax.exam.invoker.junit.internal.ContainerTestRunner.runChildWithRetry(ContainerTestRunner.java:84) >> at >> org.ops4j.pax.exam.invoker.junit.internal.ContainerTestRunner.runChild(ContainerTestRunner.java:75) >> at >> org.ops4j.pax.exam.invoker.junit.internal.ContainerTestRunner.runChild(ContainerTestRunner.java:43) >> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) >> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) >> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) >> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) >> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) >> at >> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) >> at >> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) >> at org.junit.runners.ParentRunner.run(ParentRunner.java:363) >> at org.junit.runner.JUnitCore.run(JUnitCore.java:137) >> at org.junit.runner.JUnitCore.run(JUnitCore.java:115) >> at >> org.ops4j.pax.exam.invoker.junit.internal.JUnitProbeInvoker.invokeViaJUnit(JUnitProbeInvoker.java:124) >> at >> org.ops4j.pax.exam.invoker.junit.internal.JUnitProbeInvoker.findAndInvoke(JUnitProbeInvoker.java:97) >> at >> org.ops4j.pax.exam.invoker.junit.internal.JUnitProbeInvoker.call(JUnitProbeInvoker.java:73) >> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >> at >> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) >> at >> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) >> at java.lang.reflect.Method.invoke(Method.java:498) >> at >> org.ops4j.pax.exam.rbc.internal.RemoteBundleContextImpl.remoteCall(RemoteBundleContextImpl.java:85) >> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >> at >> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) >> at >> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) >> at java.lang.reflect.Method.invoke(Method.java:498) >> at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:324) >> at sun.rmi.transport.Transport$1.run(Transport.java:200) >> at sun.rmi.transport.Transport$1.run(Transport.java:197) >> at java.security.AccessController.doPrivileged(Native Method) >> at sun.rmi.transport.Transport.serviceCall(Transport.java:196) >> at >> sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568) >> at >> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826) >> at >> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683) >> at java.security.AccessController.doPrivileged(Native Method) >> at >> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682) >> at >> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) >> at >> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) >> at java.lang.Thread.run(Thread.java:745) > > > > Thanks for any kind reply > > -- *Ing. Massimo Bono*