【发布时间】:2020-02-17 10:32:21
【问题描述】:
我正在为路线编写测试 问题是我的所有路由都包含 application.properties 文件中描述的属性,例如
from("oracleQueue:{{oracle.queue.url}}").to("my.endpoint")
它工作正常,但是当我尝试编写测试时 - 似乎这条路线找不到 application.properties 文件及其属性。 错误:
java.lang.IllegalArgumentException: Property with key [oracle.queue.url] not found in properties from text: oracleQueue:{{oracle.queue.url}}
我的测试用例:
public class RouteTest extends CamelTestSupport {
@Override
protected RoutesBuilder createRouteBuilder() {
MyRouteBulder route = new MyRouteBulder ();
ApplicationContext appContext = new ClassPathXmlApplicationContext("camel-context.xml");
PropertiesComponent pc = new PropertiesComponent();
pc.setLocation("application.properties");
CamelContext context = new SpringCamelContext(appContext);
context.addComponent("properties", pc);
route.setContext(context);
return route;
}
@Test
public void test() throws InterruptedException {
MockEndpoint mockEndpoint = resolveMandatoryEndpoint("my.endpoint", MockEndpoint.class);
mockEndpoint.expectedMessageCount(1);
template.sendBody("oracleQueue:{{oracle.queue.url}}", "hello world");
mockEndpoint.assertIsSatisfied();
}
}
我应该如何正确设置配置文件?
【问题讨论】:
-
这是一个 Spring Boot 应用吗?
标签: java testing apache-camel