簡體   English   中英

如何在駱駝測試中配置 application.properties?

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

我正在為路由編寫測試問題是我所有的路由都包含 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();

}

}

我應該如何正確設置配置文件?

也許您需要該位置的絕對路徑。

我用這個來獲取道具

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM