Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-14099

Mocking OSGi Services failes using classes

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Won't Fix
    • 2.21.0
    • None
    • camel-blueprint
    • Camel 2.21.0 on Karaf 4.2.0

    • Unknown

    Description

      Using Camel with OSGi Blueprint XML, mocking OSGi services in the test class extending CamelBlueprintTestSupport does not work under some speical circumstances.  

      In the blueprint.xml, there is the following code:

      <bean class=com.myexample.FooBar" id="foobar"> 
         <property name="foo" ref="foo" /> 
      </bean> 
      <bean class="com.myexample.FooImpl" id="foo"/> 
      <reference id="fooBarReference" component-name="foobar" interface="com.myexample.FooImpl" ext:proxy-method="classes" />
      

      The execution on the Karaf server works fine.

      Mocking the service 'FooImpl' in the test class failes with
      java.lang.RuntimeException: Gave up waiting for BlueprintContainer from bundle "FooTest" at com.myexample.test.FooTest.setUp(FooTest.java:49)

      The mock setup is done this way:

      protected void addServicesOnStartup(Map<String, KeyValueHolder<Object, Dictionary>> services) {
          FooImpl foo = Mockito.mock(FooImpl.class);      
          services.put(FooImpl.class.getCanonicalName(), asService(foo, null));   
          super.addServicesOnStartup(services); 
      }
      

       Using an interface as reference instead of a class, the mock works fine:

      blueprint.xml:

      <reference id="foo" interface="com.myexample.FooInterface" />
      

       Mock in test class:

      protected void addServicesOnStartup(Map<String, KeyValueHolder<Object, Dictionary>> services) { 
              FooInterface foo = Mockito.mock(FooImpl.class);     
              services.put(FooInterface.class.getCanonicalName(), asService(foo, null));      
              super.addServicesOnStartup(services);       
      }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            ian_Eve Christian Eve
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: