我目前正在使用CamelBlueprintTestSupport设置测试。
在我的blueprint.xml中,我尝试了以下实现:
<reference id="foo" interface="com.myexample.FooInterface" />
在测试类中模拟FooInterface与
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),原因是我只想检查测试配置)最终为正。
但是在我的实际实现中,我没有接口作为服务。相反,它是这样引用的类:
<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:放弃等待BlueprintContainer来自捆绑包“ FooTest”在com.myexample.test.FooTest.setUp(FooTest.java:49)
我看不出实际出了什么问题。顺便说一下,在Karaf上骆驼路线的实施没有任何问题。我不知道我的测试设置是否错误或错误在CamelBlueprintTestSupport中。
最后,有一个解决方案:
Properties dictionary = new Properties();
dictionary.setProperty("osgi.service.blueprint.compname","foobar");
services.put(FooImpl.class.getName(), asService(new FooImpl(), dictionary));
CU,iE