简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM