Search code examples
citrus-framework

Citrusframework - Java action - Get result


Besides REST-API Calls, I need to call my own Java-Class, which basically does something, which I want to confirm later in the test via REST-API-Calls.

When calling my Java-Class, there is an expected behavior: It may fail or not fail, depending on the actual Test-Case.

Is there any chance to code this expectation this into my test-class:

java("com.org.xyz.App").method("run").methodArgs(args).build();

As this is the Main-Class, which should be executed later in a automated fashion, I would prefer to validate the Return-Code. However, I'm looking for any possible way (Exception-Assertion, Stdout-Check, ..) to verify the status of the program.


Solution

  • As you are using the Java DSL to write test cases I would suggest to go with custom test action implementation and/or initializing your custom class directly in the test method and call the method as you would do with any other API.

    You can wrap the custom code in a custom AbstractTestAction implementation as you then have access to the TestContext and your custom code is integrated into the test action sequence.

    The java("com.org.xyz.App").method("run").methodArgs(args) API is just for compliance to the XML DSL where you do not have the opportunity to initialize own Java class instances. Way too complicated for your requirement in my opinion.