You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Christian Eve (Jira)" <ji...@apache.org> on 2019/10/23 07:00:00 UTC
[jira] [Created] (CAMEL-14099) Mocking OSGi Services failes using
classes
Christian Eve created CAMEL-14099:
-------------------------------------
Summary: Mocking OSGi Services failes using classes
Key: CAMEL-14099
URL: https://issues.apache.org/jira/browse/CAMEL-14099
Project: Camel
Issue Type: Bug
Components: camel-blueprint
Affects Versions: 2.21.0
Environment: Camel 2.21.0 on Karaf 4.2.0
Reporter: Christian Eve
Assignee: Grzegorz Grzybek
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:
{code:java}
<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" />
{code}
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:
{code:java}
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);
}
{code}
Using an interface as reference instead of a class, the mock works fine:
blueprint.xml:
{code:java}
<reference id="foo" interface="com.myexample.FooInterface" />
{code}
Mock in test class:
{code:java}
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);
}
{code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)