java - 如何在camel测试中配置application.properties?

标签 java testing apache-camel

我正在为该路线编写测试 问题是我的所有路由都包含 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();

}

}

我应该如何正确设置配置文件?

最佳答案

也许您需要该位置的绝对路径。

我用它来获取 Prop

<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>

关于java - 如何在camel测试中配置application.properties?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60260531/

相关文章:

java - 在 JBoss EAP 6.4 上的 JBoss Fuse 6.3 中使用 Camel 访问环境属性时出错

java - 跟踪 Java 中的内存泄漏/垃圾收集问题

visual-studio-2010 - 用于 Visual Studio 性能测试的新浏览器

database - 数据层测试

spring - 应该测试 @RestController 还是只测试 @Service

apache-camel - 将 OSGi 服务公开为 Camel 端点

java - 从外部 Tomcat 目录读取可重新加载的 xml 文件

JavaFX 正在运行,但 try-catch-finally 代码不起作用

java - 如何将一个存储为java对象的对象的变量传递给另一个也存储为java对象的对象的函数?

java - 我的 Android 应用程序的多任务处理速度缓慢