Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

When using Blueprint property placeholder in the Blueprint XML file, you can declare the properties directly in the XML file as shown below:

Wiki Markup
{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-outside.xml}
 

Notice that we have a <bean> which refers to one of the properties. And in the Camel route we refer to the other using the {{ }} notation.

Now if you want to override these Blueprint properties from an unit test, you can do this as shown below:

Wiki Markup
{snippet:id=e1|lang=java|url=camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminOverridePropertiesOutsideCamelContextTest.java}
 

To do this we override and implement the useOverridePropertiesWithConfigAdmin method. We can then put the properties we want to override on the given props parameter. And the return value must be the persistence-id of the <cm:property-placeholder> tag, which you define in the blueprint XML file.

...

For example in the blueprint XML file we have the persistence-id="stuff", which mean it will load the configuration file as etc/stuff.cfg.

Wiki Markup
{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-loadfile.xml}
 

Now if you want to unit test this blueprint XML file, then you can override the loadConfigAdminConfigurationFile and tell Camel which file to load as shown below:

Wiki Markup
{snippet:id=e1|lang=java|url=camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminLoadConfigurationFileTest.java}
 

Notice that this method requires to return a String[] with 2 values. The 1st value is the path for the configuration file to load. The 2nd value is the persistence-id of the <cm:property-placeholder> tag.

...

You can do both as well. Here is a complete example. First we have the Blueprint XML file:

Wiki Markup
{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-loadfileoverride.xml}
 

And in the unit test class we do as follows:

Wiki Markup
{snippet:id=e1|lang=java|url=camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminLoadConfigurationFileAndOverrideTest.java}
 

And the etc/stuff.cfg configuration file contains:

...

To bridge Spring and Camel you must define a single bean as shown below:

Wiki Markup
{snippet:id=e1|lang=xml|title=Bridging Spring and Camel property placeholders|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/CamelSpringPropertyPlaceholderConfigurerTest.xml}
 

You must not use the spring <context:property-placeholder> namespace at the same time; this is not possible.

After declaring this bean, you can define property placeholders using both the Spring style, and the Camel style within the <camelContext> tag as shown below:

Wiki Markup
{snippet:id=e2|lang=xml|title=Using bridge property placeholders|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/CamelSpringPropertyPlaceholderConfigurerTest.xml}
 

Notice how the hello bean is using pure Spring property placeholders using the ${} notation. And in the Camel routes we use the Camel placeholder notation with {{ }}.

...

So for example in your unit test classes, you can override the useOverridePropertiesWithPropertiesComponent method and return a java.util.Properties that contains the properties which should be preferred to be used.

Wiki Markup
{snippet:id=e1|lang=java|title=Providing properties from within unit test source|url=camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminOverridePropertiesTest.java}
 

This can be done from any of the Camel Test kits, such as camel-test, camel-test-spring and camel-test-blueprint.

...