我正在为路线编写测试 问题是我所有的路线都包含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();
}
}
如何正确设置配置文件?
答案 0 :(得分:0)
也许您需要该位置的绝对路径。
我用它来获得道具
<bean
class="org.apache.camel.component.properties.PropertiesComponent"
id="properties" name="properties">
<property name="cache" value="false"/>
<property name="locations">
<list>
<value>file:${CONF}/broker.properties</value>
<value>file:${CONF}/sops/domains/properties/a92fe32d-01c9-4c00-b2c0-b17a71503bbe.properties;optional=true</value>
</list>
</property>
</bean>