You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is possible to define Camel routes in a testcase definition by using <camel:create-routes>, see documentation. However, it is not possible to use testcase specific variables within that route definition.
Example
The following is not possible. ${fileId} will not be replaced with 1.
Find a way to replace the variables within the Camel route definition.
BTW Camel does not support the default Spring Property Placeholder, see documentation.
Workaround
To get all properties from citrus.properties you can do as follows in your Citrus context:
<camelContextid="citrusCamelContext"xmlns="http://camel.apache.org/schema/spring">
<!-- camel doesn't use the spring default property-placeholder -->
<propertyPlaceholderid="camelProperties"location="classpath:citrus.properties"/>
</camelContext>
This way you can access the same citrus.properties from within the Camel context. ⚠️NOTE Camel uses a different notation for variables, like this {{variable_to_be_replaced}}.
However, there is still no way to access test (local) variables from within a test case. The only workaround I have found so far is setting the test variables again as JVM properties with a groovy script since Camel reads the JVM properties by default as well:
<groovy>
// workaround for Camel route which can't access citrus test variables but JVM system properties
System.setProperty('testVar', '${testVar}')
</groovy>
Obviously, variables are duplicated and its tedious.
System properties are JVM specific, i.e. global. So there may be collisions with other properties especially with other Citrus tests if they run in parallel, so a best practice is to use a test specific prefix.
The text was updated successfully, but these errors were encountered:
christophd
changed the title
Testcase Camel Routes definitions cannot access test case variables
Access test case variables in Camel Routes definitions
Jul 5, 2017
Problem
It is possible to define Camel routes in a testcase definition by using
<camel:create-routes>
, see documentation. However, it is not possible to use testcase specific variables within that route definition.Example
The following is not possible.
${fileId}
will not be replaced with1
.Solution
Find a way to replace the variables within the Camel route definition.
BTW Camel does not support the default Spring Property Placeholder, see documentation.
Workaround
To get all properties from
citrus.properties
you can do as follows in your Citrus context:This way you can access the same
⚠️ NOTE Camel uses a different notation for variables, like this
citrus.properties
from within the Camel context.{{variable_to_be_replaced}}
.Example
However, there is still no way to access test (local) variables from within a test case. The only workaround I have found so far is setting the test variables again as JVM properties with a groovy script since Camel reads the JVM properties by default as well:
Then in the finally block I clear them:
NOTE There are two drawbacks to this approach:
The text was updated successfully, but these errors were encountered: