鉴于到目前为止我还没有找到任何相关的答案,所以我发布了这个问题。我不知道如何使用 Spring-Dynamic Modules 运行集成测试。
问题定义
模板申请
- 一个包含业务逻辑的 OSGi 包。使用 Spring DM 导出/引用一些服务
- 一个用于集成测试的 OSGi 片段。测试应该能够注入在片段应用程序上下文中定义的辅助测试 bean(使用 META-INF/spring 下的 xml 文件)以及导出的 OSGi 服务(来自 API 包)
版本
- OSGi 3.6
- Spring 框架 3.1.0
- Spring 动态模块 1.2.1
问题
- 如何运行集成测试以了解 Spring 应用程序上下文和公开的 OSGi 服务?使用
@RunWith(SpringJUnit4ClassRunner.class)
并@ContextConfiguration(locations = { "classpath:META-INF/spring/context.xml" })
导致FileNotFoundException
存在的有关 context.xml... 调试XmlBeanDefinitionReader
证实了我的疑问:SpringJUnit4ClassRunner
正在尝试从其 OSGi 类路径加载应用程序上下文,并且无法访问我的捆绑资源。
请问您如何最好地解决这个问题?
我提前感谢您的帮助。
ps:我看了一下Spring DM Test,但没有发现任何相关内容。
例子
捆绑清单
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: HelloWorldDM
Bundle-SymbolicName: HelloWorldDM
Bundle-Version: 1.0.0.qualifier
Require-Bundle: org.eclipse.core.runtime,
ContactDAO;bundle-version="1.0.0",
org.springframework.osgi.extensions.annotations;bundle-version="1.2.1"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Import-Package: ch.xxx.test.contact
集成测试片段清单
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: HelloWorldTest
Bundle-SymbolicName: HelloWorldTest
Bundle-Version: 1.0.0.qualifier
Fragment-Host: HelloWorldDM;bundle-version="1.0.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Require-Bundle: org.junit4;bundle-version="4.8.1",
org.springframework.spring-test;bundle-version="3.1.0",
org.springframework.spring-context;bundle-version="3.1.0",
org.springframework.spring-beans;bundle-version="3.1.0",
org.springframework.osgi.test;bundle-version="1.2.1",
org.springframework.spring-core;bundle-version="3.1.0"
分片应用上下文
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<bean class="org.springframework.osgi.extensions.annotation.ServiceReferenceInjectionBeanPostProcessor"/>
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
</beans>
测试班
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:META-INF/spring/context.xml" })
public class TestCase {
private BitemporalityService bitemporalityService;
@ServiceReference
public void setBitemporalityService(BitemporalityService service) {
this.bitemporalityService = service;
}
@Test
public void dummy(){
System.err.println("in Test: ");
assertNotNull(bitemporalityService);
}
}