[英]How to get Apache Camel Docker component to work in OSGi? or (Jersey does not work in OSGi)
[英]Mocking OSGi reference in CamelBlueprintTest does not work
我目前正在使用 CamelBlueprintTestSupport 設置測試。
在我的 blueprint.xml 中,我嘗試了以下實現:
<reference id="foo" interface="com.myexample.FooInterface" />
Mocking FooInterface 在我的測試 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);
}
工作正常(當然,FooImpl 實現了 FooInterface),例如執行測試(測試只包含 assert(true) 因為我只想檢查測試配置)最終是肯定的。
但是在我的實際實現中,我沒有作為服務的接口。 相反,它是以這種方式引用的 class :
<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" />
我在測試中的模擬配置是這樣的:
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);
}
現在執行測試失敗,出現以下異常:
java.lang.RuntimeException:在 com.myexample.test.FooTest.setUp(FooTest.Z93F725A07423FE1C8489F4449B33D2) 處的“FooTest”包中放棄等待 BlueprintContainer:
我看不出實際上出了什么問題。 順便說一句,卡拉夫駱駝路線的實施沒有任何問題。 我不知道我的測試設置是否錯誤,或者是否是 CamelBlueprintTestSupport 中的錯誤。
最后,有一個解決方案:
Properties dictionary = new Properties();
dictionary.setProperty("osgi.service.blueprint.compname","foobar");
services.put(FooImpl.class.getName(), asService(new FooImpl(), dictionary));
銅,即
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.