简体   繁体   English

如何在骆驼测试中配置 application.properties?

[英]How to configure application.properties in camel tests?

I'm working on writing tests for the route The problem is all my routes contain properties that described in application.properties file eg我正在为路由编写测试问题是我所有的路由都包含 application.properties 文件中描述的属性,例如

from("oracleQueue:{{oracle.queue.url}}").to("my.endpoint")

It works fine but when I try to write a test - seems like this route can't find application.properties file with its properties.它工作正常,但是当我尝试编写测试时 - 似乎这条路线找不到具有其属性的 application.properties 文件。 The error:错误:

java.lang.IllegalArgumentException: Property with key [oracle.queue.url] not found in properties from text: oracleQueue:{{oracle.queue.url}}

My testcase:我的测试用例:

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();

}

} }

How should I set up configuration file properly?我应该如何正确设置配置文件?

Maybe you need an absolute path for the location.也许您需要该位置的绝对路径。

I use this to get props我用这个来获取道具

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Boot 2:如何使用application.properties文件配置HikariCP - Spring Boot 2: How to configure HikariCP using application.properties file 如何配置Spring以从jar外部加载application.properties? - How to configure Spring to load application.properties from outside of jar? 如何在 Jenkins maven 作业中从外部配置 application.properties? - How to configure the application.properties externally in the Jenkins maven job? spring application.properties中的第二个数据源用于测试? - Second datasource in spring application.properties for tests? 如何将 Spring Data JPA 正确配置到 Spring Boot 2.X 应用程序的 application.properties 配置文件中? - How to correctly configure Spring Data JPA into the application.properties configuration file of a Spring Boot 2.X application? "如何在 application.properties 文件中的 Spring Boot 应用程序中配置 HikariCP?" - How do I configure HikariCP in my Spring Boot app in my application.properties files? Spring-如何从application.properties中的spring.datasource配置OracleDataSource - Spring - How to configure OracleDataSource from spring.datasource in application.properties Spring Boot MVC-如何在application.properties中配置多视图视图目录 - Spring Boot MVC - How to configure multipe view directories in application.properties 运行测试时如何指示 Spring Boot 使用测试资源中的 application.properties 文件 - How to instruct Spring Boot to use application.properties file in test's resources when running tests testcontainer 启动后,如何在集成测试中覆盖 application.properties 中定义的端口? - How to overwrite ports defined in application.properties in integration tests after testcontainer started?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM