Camel Properties加载

时间:2018-06-15 20:45:49

标签: junit properties apache-camel

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

Loading Properties File In JUnit @BeforeClass

属性加载似乎有效但我不知道如何在我的单元测试中引用特定属性...任何想法 - 我试图加载 <的值我的属性文件中的em> testinput 条目?

=============================================== ============= 属性文件 users.properties content:

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}}";
}

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

好的......我尝试了显而易见的......在 之前定义了 类之外的Property对象并且有效......似乎还有另外一种方法引用在前一类中加载的属性对象。