While not ideal, if I just remove the @OsgiService from the unit test it injects because it is within the same bundle. I'll likely have to use a different testing mechanism to get the provider/service injection to work. I've also added this to make sure the service is exported the way I want from the bundle. This more like what I'd do in blueprint and if I have it right the Pax CDI is using the same proxy mechanism as blueprint.
@OsgiServiceProvider(classes = {DataStore.class}) On Saturday, September 3, 2016 at 10:50:03 AM UTC-5, Brad Johnson wrote: > > I've been using the 2.17 update of Camel that more closely integrates CDI > 1.2 and specifically Pax CDI. I'm quite impressed with and look forward to > using it in the years ahead. I've used blueprint for quite awhile and > while it works well enough the CDI simply makes development much easier and > testing is a snap. > > One problem I've run into is with the CDI testing framework. Within > bundle tests or even bundles listed as dependencies work just fine. But > when I try to use the @OsgiServiceProvider and @OsgiService I run into some > problems. It may simply be that the regular CDI runner with Weld isn't > appropriate for testing service export and import. > > From what I can tell I'm either missing a library dependency or the CDI > test even within bundle will not respect the pick up or use the annotations. > > The @Inject in this unit test shows a squiggly yellow underline indicating > it can't find anything to inject. > > @RunWith(CamelCdiRunner.class) > public class DevelopmentDataStoreTest { > > @Inject > @OsgiService > private DataStore datastore; > > In the same bundle I have am Impl of the DataStore interface that looks > like this: > > @Singleton > @OsgiServiceProvider > public class DevelopmentDataStoreImpl implements DataStore { > > I've tried a number of different permutations such as adding a > dynamic=true to the OsgiService annotation. > > The stack trace on the test seems to indicate that it understand what it > is I want to do but I don't have something right about it (italics are > mine). > > ELD-001408: Unsatisfied dependencies for type DataStore with qualifiers > @OsgiService > at injection point [BackedAnnotatedField] @Inject @OsgiService private > org.enjekt.panda.developmentdatstore.DevelopmentDataStoreTest.datastore > at > org.enjekt.panda.developmentdatstore.DevelopmentDataStoreTest.datastore(DevelopmentDataStoreTest.java:0) > WELD-001475: *The following beans match by type, but none have matching > qualifiers:* > * - Managed Bean [class > org.enjekt.panda.developmentdatastore.DevelopmentDataStoreImpl] with > qualifiers [@OsgiServiceProvider @Any]* > > Italics are mine. So something is off about my annotations. Should the > OsgiServiceProvider be scoped differently? For in bundle testing like this > I could use @Named("dataStore") and inject it that way. > > > My imports look like the following: > <dependency> > <groupId>javax.enterprise</groupId> > <artifactId>cdi-api</artifactId> > <version>${cdi.version}</version> > </dependency> > <dependency> > <groupId>org.ops4j.pax.cdi</groupId> > <artifactId>pax-cdi-api</artifactId> > <version>1.0.0.RC1</version> > </dependency> > <dependency> > <groupId>org.apache.camel</groupId> > <artifactId>camel-cdi</artifactId> > <version>${camel.version}</version> > 2.17.3 > </dependency> > > <!-- testing --> > <dependency> > <groupId>org.apache.camel</groupId> > <artifactId>camel-test-cdi</artifactId> > <version>${camel.version}</version> > <scope>test</scope> > </dependency> > > Any help is appreciated. > -- -- ------------------ OPS4J - http://www.ops4j.org - ops4j@googlegroups.com --- You received this message because you are subscribed to the Google Groups "OPS4J" group. To unsubscribe from this group and stop receiving emails from it, send an email to ops4j+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.