Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access test case variables in Camel Routes definitions #243

Closed
gucce opened this Issue May 22, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@gucce
Copy link
Contributor

gucce commented May 22, 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 with 1.

<testcase>
    <variables>
        <variable name="fileId" value="1"/>
    </variables>

    <actions>
        <camel:create-routes>
            <routeContext xmlns="http://camel.apache.org/schema/spring">
                <route id="testRoute">
                    <from uri="sftp://someurl?fileName=File_${fileId}.xml"/>
                    <to uri="file:target/"/>
                </route>
            </routeContext>
        </camel:create-routes>
    </actions>
</testcase>

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:

<camelContext id="citrusCamelContext" xmlns="http://camel.apache.org/schema/spring">
    <!-- camel doesn't use the spring default property-placeholder -->
    <propertyPlaceholder id="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}}.

Example

<citruscamel:create-routes>
    <routeContext xmlns="http://camel.apache.org/schema/spring">
        <route id="someCamelRoute">
            <from uri="seda:{{seda.queue}"/>
            <to uri="file:{{file.path}}"/>
        </route>
    </routeContext>
</citruscamel:create-routes>

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>

Then in the finally block I clear them:

<groovy>
    System.clearProperty('testVar')
</groovy>

NOTE There are two drawbacks to this approach:

  1. Obviously, variables are duplicated and its tedious.
  2. 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.

@christophd christophd added the READY label May 28, 2017

@christophd christophd added this to the v2.7.2 milestone May 28, 2017

@christophd christophd added IN PROGRESS and removed READY labels Jul 4, 2017

@christophd christophd self-assigned this Jul 4, 2017

@christophd christophd changed the title Testcase Camel Routes definitions cannot access test case variables Access test case variables in Camel Routes definitions Jul 5, 2017

@christophd christophd closed this in 8d5bc1e Jul 5, 2017

@christophd christophd removed the IN PROGRESS label Jul 5, 2017

@gucce

This comment has been minimized.

Copy link
Contributor Author

gucce commented Jul 5, 2017

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.