【问题标题】:Camel Properties file load from Junit Integration Test从 Junit 集成测试加载骆驼属性文件
【发布时间】: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


【解决方案1】:

这是我们正在使用的解决方案(但没有 Arquillian):

首先为 Camel“属性”组件定义一个 CDI 替代方案,它将使用测试属性值。

然后注释您的单元测试,以便使用 Camel 组件的替代生产者。

@Alternative
public class CamelAlternatives {

    @Produces
    @ApplicationScoped
    @Named("properties")
    public PropertiesComponent propertiesComponent() {      
        PropertiesComponent component = new PropertiesComponent();      
        component.setLocations( Arrays.asList("classpath:common.properties", "classpath:testing.properties") );
        return component;
    }

@RunWith(CamelCdiRunner.class)
@Beans(alternatives = {CamelAlternatives.class})
public class MyUnitTest {
    ...
}   

【讨论】:

    猜你喜欢
    • 2017-04-30
    • 1970-01-01
    • 2018-10-08
    • 1970-01-01
    • 1970-01-01
    • 2014-12-14
    • 1970-01-01
    • 2013-01-21
    • 1970-01-01
    相关资源
    最近更新 更多