2 Replies Latest reply on Aug 9, 2011 1:27 PM by wayn23

    BundleContext not injected in Pax-Exam

    wayn23

      I am trying to get PAX-Exam working as described on http://fusesource.com/docs/esb/4.2/deploy_osgi/BestPractices-PaxExam.html

       

      I have implemented the sample of the page, but when I run the test, the BundleContext is not being injected.

       

      Here is the relevant portion of my pom file

      -


      ...

            

      -


       

      Here is my source code.

       

      -


      import static org.junit.Assert.assertNotNull;

      import static org.ops4j.pax.exam.CoreOptions.equinox;

      import static org.ops4j.pax.exam.CoreOptions.maven;

      import static org.ops4j.pax.exam.CoreOptions.systemProperty;

      import static org.ops4j.pax.exam.CoreOptions.waitForFrameworkStartup;

      import static org.ops4j.pax.exam.OptionUtils.combine;

      import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.scanFeatures;

      import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.workingDirectory;

       

      import org.apache.felix.karaf.testing.AbstractIntegrationTest;

      import org.apache.felix.karaf.testing.Helper;

      import org.junit.Test;

      import org.ops4j.pax.exam.Option;

      import org.ops4j.pax.exam.junit.Configuration;

      import org.osgi.service.blueprint.container.BlueprintContainer;

      import org.osgi.service.command.CommandProcessor;

      import org.osgi.service.command.CommandSession;

       

      public class DiagnosticTester extends AbstractIntegrationTest {

       

      @Test

      public void testFeatures() throws Exception {

        assertNotNull("Bundle Context not injected", bundleContext);

        // Make sure the command services are available

        assertNotNull(getOsgiService(

              BlueprintContainer.class,

              "osgi.blueprint.container.symbolicname=org.apache.felix.karaf.shell.obr",

              20000));

        assertNotNull(getOsgiService(

              BlueprintContainer.class,

              "osgi.blueprint.container.symbolicname=org.apache.felix.karaf.shell.wrapper",

              20000));

        // Run some commands to make sure they are installed properly

        CommandProcessor cp = getOsgiService(CommandProcessor.class);

        CommandSession cs = cp.createSession(System.in, System.out, System.err);

        cs.execute("obr:listUrl");

        cs.execute("wrapper:install --help");

        cs.close();

      }

       

      @Configuration

      public static Option[] configuration() throws Exception {

        return combine(

          // Default Karaf environment

          Helper.getDefaultOptions(

          // this is how you set the default log level when using pax

          // logging (logProfile)

          systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG")),

       

          // add two features

          scanFeatures(maven().groupId("org.apache.felix.karaf").artifactId("apache-felix-karaf").type("xml")

               .classifier("features").versionAsInProject(), "obr","wrapper"),

       

          workingDirectory("target/paxrunner/features/"),

          waitForFrameworkStartup(),

            equinox()

          );

        }

      }

      -


       

      The test fails on the first test

         assertNotNull("Bundle Context not injected", bundleContext);

       

      Any ideas on what I am missing?

       

      Thanks

      Wayne

       

      Edited by: wayn23 on Aug 5, 2011 6:30 PM