For our demonstration I will be using Apache’s ActiveMQ, the most popular cross platform JMS provider. It’s open source product so please go ahead and download it from ActiveMQ download page. Once downloaded just unzip the installer zip file and start running activemq process from inside activemq-install-dir/bin directory.
First we need to start a JMS server where we shall be sending the JMS messages and getting the response from. ActiceMQ developers have provided a really simple JMS client, server code on this page. Go ahead copy full Server side code from this page and paste it into a file called Server.java on your computer. Save the file and compile it using following javac command:
Once compiled just start the JMS Server process using following command
Now our JMS server is running, lets test the JMS messaging by writing a simple JMS client on FitNesse. Client program on this activemq page does just that in Java. Now let’s see how are we going to translate this code into FitNesse wiki test script.
Before we start writing FitNesse test script pay close attention to the supplied Client class on the above page. This class is sending a text message to the JMS queue named “client.messages”. However it is getting response from server asynchronously. Response is asynchronously delivered to onMesssage() callback inside the class.
To send a message to the JMS server FitNesse web based test script we must convert this behaviour of the Client class by making it a synchronous call since we cannot have a callback inside FitNesse test script. That can be achieved by sending a message to the JMS queue named “client.messages” and then making a blocking call to get the response in the same thread. Than can be achieved by MessageConsumer.receive(int timeout) method.
Once that is decided it’s really straight forward to write that up in FitNesse. We must include 4 activemq jar files needed to run our client program. We are making use of run-time variable creation feature of Generic Fixture in this script. Here is the complete test script for the JMS client we have discussed above.
Go ahead and give it a try. This test script if executed correctly should result in 1 green cell in last cell of the 2nd table by matching the server’s response with the expected value in the table.