[ 
https://issues.apache.org/jira/browse/CAMEL-14099?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16957658#comment-16957658
 ] 

Christian Eve commented on CAMEL-14099:
---------------------------------------

Using
{code:java}
FooInterface foo = new FooImpl();
services.put(FooInterface.class.getCanonicalName(), asService(foo, null));   
{code}
doesn't work. Or did you mean something else?

 

> 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
>            Priority: Minor
>              Labels: test
>
> 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)

Reply via email to