首页 > 解决方案 > 骆驼属性加载

问题描述

我刚刚阅读了一篇讨论在 Junit 中加载属性的帖子

在 JUnit @BeforeClass 中加载属性文件

属性加载似乎有效,但我不确定如何在我的单元测试中引用特定属性......任何想法 - 我正在尝试在我的属性文件中加载testinput条目的值?

==================================================== ========== 属性文件users.properties内容:

testinput =D/somefolder/somefile

public class OrderRouterTest2 extends CamelSpringTestSupport {

  @Override
    protected AbstractXmlApplicationContext createApplicationContext() {
        return new ClassPathXmlApplicationContext("META-INF/spring/camel- context.xml");
    }

    @BeforeClass
    public static void setUpBeforeClass() throws Exception {
        final Properties props = new Properties();
        final InputStream fileIn = OrderRouterTest2.class.getResourceAsStream("/**users.properties**");
        **props.load(fileIn)**;
    }

    @Test
    public void testSendToWebService() throws Exception { 

          // These don't work
          String value1 = context.resolvePropertyPlaceholders("{{testinput}}");
          String value2 = "I see ${testinput}";
          String value3 = "I see {{testinput}}";
}

标签: junitpropertiesapache-camel

解决方案


您应该使用 CamelTestSupport 中的 useOverridePropertiesWithPropertiesComponent,请参阅:https ://camel.apache.org/camel-test.html


推荐阅读