Enterprise Application Integration testing with Citrus Framework

Last week i read a thread on the Oracle forums on how to test the Oracle Service Bus processes.
A comment from one of the users lead to me this framework, Citrus Framework.

Citrus is an integration testing framework written in Java that tests your software application to fit into your customer’s environment. The tool simulates
surrounding systems across various transports (e.g. Http, JMS, TCP/IP, SOAP, …) in order to perform automatic end-to-end use case testing.

For one of my customers we had a lot of unit tests for testing all the flows in the middleware. Different scenarios, different protocols, eventually all needed to be tested.
Constructing all theses possible scenarios, we build everything from scratch to be able to send messages on different protocols and do all the correlation of the messages which go in and which eventually arrive at target destination.

To simulate a one of these scenarios i wanted to try the Citrus Framework to see what it could do for me.

For my test i used the greetings sample which ships with the citrus-1.1-SNAPSHOT distribution.

Directory structure
Create the directory structure as desribed over here.
When all done you should have a structure like this

  • src/citrus/java – location of the generated Testng testcases
  • src/citrus/resoruces – location of all the configuration needed for the framework
  • src/citrus/tests – location of all the defined testcases
  • optional – lib – location of all the dependency libraries
  • optional – log – location in which citrus framework will store logging (payload fragments)
  • build.xml – ant build script

Example of the used build.xml
[sourcecode language=”xml”]






































[/sourcecode]

Scenario
Middleware gets delivered a new message on a queue. Some process picks up the message, does some transformation/validation on it, and passes it on. Eventually a new message will get sended to some other queue.

– Pre-Requirements

  • weblogic jms queue (citrus_queue_in, citrus_queue_out)
  • weblogic connection factory (TestCF)
  • wlfullclient.jar (cd WL_HOME/server/lib, java -jar wljarbuilder.jar)
  • available process flow for testing (i used a simple Oracle Service Bus (OSB)) flow which received a message on citrus_queue_in and routes the mesage to citrus_queue_out)

First we need to config src/citrus/resources/citrus-context.xml
[sourcecode language=”xml”]



weblogic.jndi.WLInitialContextFactory t3://localhost:7001

TestCF

true






[/sourcecode]

Let’s discuss a few parts

  • bean id=”schemaRepository” class=”com.consol.citrus.xml.XsdSchemaRepository”
  • Registrate the xsd for the message payload, which eventually will be used to validate the messages
  • bean class=”com.consol.citrus.variable.GlobalVariables”
  • Setup some global settings
  • bean class=”com.consol.citrus.aop.StoreMessageInterceptorAspect”
  • Activate extra debugging
  • bean id=”jndiTemplate, connectionFactory and jmsDestinationResolver”
  • Configuration for the lookup of the weblogic resources
  • bean id=”sendGreeting” class=”com.consol.citrus.jms.JmsMessageSender”
  • used for sending the messages to the jms queue
  • bean id=”receiveGreeting” class=”com.consol.citrus.jms.JmsMessageReceiver”
  • used for receiving the messages of the jms queue

** Note. Default configuration describes to make use of :
[sourcecode language=”xml”]

[/sourcecode]

This gave me errors about Spring/Citrus not able to find the destination queue.
In case of weblogic resources use the “bean id-….” definition. (thanks to Christoph of the Consol team for helping me out on this one)

Secondly we need to config src/citrus/tests/com/consol/citrus/samples/greeting/jms/GreetingJmsTest.xml
[sourcecode language=”xml”]




Eric Elzinga
2010-03-25
FINAL
Eric Elzinga
2010-03-28T00:00:00












CorrelationId = ‘${correlationId}’










[/sourcecode]

**Notes

  • resource vs data tag. To include the payload of the test we can either use
    [sourcecode language=”xml”]



    [/sourcecode]
    or
    [sourcecode language=”xml”]


    ${correlationId} sayHello ${user} Hello Citrus! ]]>


    [/sourcecode]
  • header tag adds/validates header information (soap headers/jms properties/etc)
  • selector tag gives us the option to let the framework only select the message we would expect there to be.
    If we were testing against a ‘running’ environment, it could be possible that other processes are also sending messages to queue. With the selector tag we only select the message from the queue which succeed the criteria.
    [sourcecode language=”xml”]

    CorrelationId = ‘${correlationId}’

    [/sourcecode]

    If we skip this selector, put some messages in the out-queue and do the test again we will see the next error message :
    [sourcecode language=”xml”]
    [citrus] Caused by: java.lang.IllegalArgumentException: Values not equal for header element ‘CorrelationId’, expected ‘2243051261’ but was ‘2791756984’
    [/sourcecode]
    So it will try to match the first message it will find in the queue.

  • the ignore tag will give us the option to select elements the framework should not validate
    elements which consist of current datetime values are an example of these
  • full validation vs partial validation
  • in the example included i validate the whole xml message. in case we only want to validate/check a few elements from the message we can use the next :
    [sourcecode language=”xml”]



    [/sourcecode]

    The result
    Run the ant buildfile, ant citrus.run.tests
    [sourcecode language=”css”]
    [citrus] 4547 INFO port.LoggingReporter| TEST FINISHED: GreetingJmsTest
    [citrus] 4547 INFO port.LoggingReporter| ————————————————————————
    [citrus] 4563 INFO port.LoggingReporter| FINISH TESTSUITE citrus-samples-greeting
    [citrus] 4563 INFO port.LoggingReporter| ————————————————————————
    [citrus] 4563 INFO port.LoggingReporter| ________________________________________________________________________
    [citrus] 4563 INFO port.LoggingReporter|
    [citrus] 4563 INFO port.LoggingReporter| CITRUS TEST RESULTS
    [citrus] 4563 INFO port.LoggingReporter|
    [citrus] 4563 INFO port.LoggingReporter| GreetingJmsTest ……………………………………….. SUCCESS
    [citrus] 4563 INFO port.LoggingReporter|
    [citrus] 4563 INFO port.LoggingReporter| Total number of tests: 1
    [citrus] 4563 INFO port.LoggingReporter| Skipped: 0 (0.0%)
    [/sourcecode]

    Successful result!

    What we have tested in here :
    – Are we able to put a message on the in-queue, and get a response back on the out-queue.
    – Does the response xml validates against the supplied schema definition (xsd)
    – Do the response queue message also have the correct header properties

    Other features
    Ant/Maven support
    Database access/validation
    Adapters (tibco/ws/http)
    … and more

    In a following blog item i will try to simulate some other scenario to see if the framework covers it all.
    Original blog

Share this Post:
Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

2 Responses to “Enterprise Application Integration testing with Citrus Framework”

[…] Posted in osb, testing by Eric Elzinga on April 12, 2010 Before reading on, read my first article on the Citrus Framework. In this second part of testing by use of the Citrus Framework i want to […]

[…] reading on, read my first article on the Citrus Framework. In this second part of testing by use of the Citrus Framework i want to […]

Leave a Reply:

Name (required):
Mail (will not be published) (required):
Website:
Comment (required):
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>