【发布时间】:2019-01-14 18:15:57
【问题描述】:
我有一个 Camel Route,它使用 CDI 从 JBoss 配置目录加载属性文件...完美运行。
我需要做的是加载已加载的属性之一 我正在编写的 Arquillian 集成测试。
例子:
JBoss配置目录中Fiddler.properties文件的内容
silly.value = 笑
严肃的价值=政治
用于加载属性的示例 Producer 类
/**
* Create the Camel properties component using CDI @Produces
*/
@Produces
@Named("properties")
PropertiesComponent propertiesComponent() {
final PropertiesComponent component = new PropertiesComponent();
// load JBoss properties file
component.setLocation(
"file:${jboss.server.config.dir}/fiddler.properties"
);
return component;
}
Fiddler.properties 文件中的给定属性现在可以在 Camel 主路由中以 {{silly.value}} 或 {{serious.value}} 的形式使用
问题:
我想做的是从我的 Arquillian 集成测试中加载/引用这些属性值之一……可能在 @BeforeClass 方法中……如下所示:
@RunWith(Arquillian.class)
public class MainRouteIT {
.
.
Boolean allOK = false;
@BeforeClass
public static void setupTest() throws Exception {
allOK = new testCheck(
{{silly.value}}, {{serious.value}}
);
.
.
知道在 Camel 中是否可以在 Arquillian 测试中进行类似的操作?
【问题讨论】:
-
嗯...我有一种方法...几乎:
-
属性 p = new Properties();最终字符串 jbossCfgDir = System.getProperty("jboss.server.config.dir");最终文件 inpPropFile = new File(jbossCfgDir, "DEV_PROPS/fiddler.properties"); p.load(IOUtils.toBufferedInputStream(FileUtils.openInputStream(inpPropFile)));
-
唯一的问题是 System.getProperty("jboss.server.config.dir") 不断返回 null :=(
-
可能有一些 ENV 变量指向 jboss 服务器配置目录 og jboss 服务器目录,因此您可以使用它而不是 JVM 系统属性。
-
@BeforeClass 在客户端而不是在容器中运行。因此,预期的系统属性不可用。您可以通过在 maven-surefire-plugin 上配置
来尝试自己设置系统属性。
标签: apache-camel jboss-arquillian