Details
-
Bug
-
Status: Resolved
-
Minor
-
Resolution: Won't Fix
-
2.21.0
-
None
-
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); }