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

Mocking OSGi Services failes using classes

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Won't Fix
    • Affects Version/s: 2.21.0
    • Fix Version/s: None
    • Component/s: camel-blueprint
    • Labels:
    • Environment:

      Camel 2.21.0 on Karaf 4.2.0

    • Estimated Complexity:
      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

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

              Dates

              • Created:
                Updated:
                Resolved: