Loading ...
Sorry, an error occurred while loading the content.

Testing of OSGi declarative services

Expand Messages
  • .
    Hi, I m not able to test a OSGi declarative service with a JUnit Plugin Test in Eclipse. Although all necessary bundles (especially the Service, the Consumer
    Message 1 of 2 , Apr 28 7:19 AM
    View Source
    • 0 Attachment
      Hi,

      I'm not able to test a OSGi declarative service with a JUnit Plugin Test
      in Eclipse.

      Although all necessary bundles (especially the Service, the Consumer
      with the JUnit Test class, org.eclipse.equinox.ds,
      org.eclipse.equinox.util, org.eclipse.jdt.junit.runtime and
      org.eclipse.pde.junit.runtime) are added to the Run Configuration of the
      Plugin Test and the bind/unbind methods are defined in the test class it
      comes to an Null Pointer Exception (the bind method seems to be not
      executed), if I access the Service attribute (e.g. public static
      IMyService myService) in a JUnit Test method.

      According to this site
      http://stackoverflow.com/questions/7161338/using-osgi-declarative-services-in-the-context-of-a-junit-test
      the reason for this exception is that the OSGi framework is in a race
      condition with the JUnit tests runner context. The solution there to use
      a Count Down Latch that waits in a @Before method until the needed
      service (that should be tested) is binded, seems to be not working for
      me. In my case the await() method blocks infinitely, so the test will be
      never executed. On the other hand, if I define a maximum time to wait,
      e.g. await(10, TimeUnit.SECONDS), it comes after this time again to the
      Null Pointer Exception.

      What is the correct way to test a OSGi declarative service with JUnit?

      Any help is appreciated.

      Regards,
      Rene
    • David Saff
      Rene, Sorry for the late reply. Unfortunately, I don t have a lot of experience with declarative services, so I can t be a lot of help. Are there
      Message 2 of 2 , May 10, 2012
      View Source
      • 0 Attachment
        Rene,

        Sorry for the late reply. Unfortunately, I don't have a lot of experience
        with declarative services, so I can't be a lot of help. Are there
        OSGi-related lists that might be more helpful? Have you found a solution?

        David

        On Sat, Apr 28, 2012 at 10:19 AM, . <tesco@...> wrote:

        > Hi,
        >
        > I'm not able to test a OSGi declarative service with a JUnit Plugin Test
        > in Eclipse.
        >
        > Although all necessary bundles (especially the Service, the Consumer
        > with the JUnit Test class, org.eclipse.equinox.ds,
        > org.eclipse.equinox.util, org.eclipse.jdt.junit.runtime and
        > org.eclipse.pde.junit.runtime) are added to the Run Configuration of the
        > Plugin Test and the bind/unbind methods are defined in the test class it
        > comes to an Null Pointer Exception (the bind method seems to be not
        > executed), if I access the Service attribute (e.g. public static
        > IMyService myService) in a JUnit Test method.
        >
        > According to this site
        >
        > http://stackoverflow.com/questions/7161338/using-osgi-declarative-services-in-the-context-of-a-junit-test
        > the reason for this exception is that the OSGi framework is in a race
        > condition with the JUnit tests runner context. The solution there to use
        > a Count Down Latch that waits in a @Before method until the needed
        > service (that should be tested) is binded, seems to be not working for
        > me. In my case the await() method blocks infinitely, so the test will be
        > never executed. On the other hand, if I define a maximum time to wait,
        > e.g. await(10, TimeUnit.SECONDS), it comes after this time again to the
        > Null Pointer Exception.
        >
        > What is the correct way to test a OSGi declarative service with JUnit?
        >
        > Any help is appreciated.
        >
        > Regards,
        > Rene
        >
        >
        > ------------------------------------
        >
        > Yahoo! Groups Links
        >
        >
        >
        >


        [Non-text portions of this message have been removed]
      Your message has been successfully submitted and would be delivered to recipients shortly.