Thursday, February 25, 2010

Using BPELUnit for testing processes in Riftsaw - Part 2

In the first part we showed how to run a BPEL test for a process deployed in Riftsaw from the Eclipse environment. Today we will use the possibility to run this tool via Ant tasks to include it in the Riftsaw integration tests. Currently, the request-response tests are performed via Java code using the standard JUnit framework. In this post I will show you how to transform some of them into BPELUnit automated tests to make them more flexible and transparent.

On top of what we have from Part 1 we need:
The prerequisites are:
  • Clean install of JBoss Application Server 5.1.0 GA
  • JBoss ESB 4.7 GA installed into the clean installation of App Server
  • Installed Ant at version 1.7.1 or higher
  • Installed Maven at version 2.2.1 or higher
  • Installed BPELUnit 1.1.0 Standalone version
In case you need help with the first two prerequisites please refer to the first part of this article to find instructions on how to properly install JBoss + ESB. As for the other three the instructions are provided on the products' websites.

Preparation

If you navigate to the directory with Riftsaw source code you will see a sub-directory called “integration-tests” which contains sources of the tests, build scripts for running them and the generated test reports. Take a look in the RIFTSAW_SRC/integration-tests/src/test/resources/samples/ directory where you can find sub-directories for each test, containing BPEL and WSDL files, XML files with messages and the ant build script (build.xml) that compiles the test and makes everything ready for its execution.

To prepare the integration test to use BPELUnit we need to set up a few things:
  1. Create a “bpelunit” folder in the test sub-directory.
  2. Create a BPELUnit test suite file in this folder.
  3. Create a build file that deploys, runs and undeploys the new tests and generates the reports.
  4. Modify the “deploy” target of the existing build script to compile the BPELUnit tests and deploy them into appropriate directory.
  5. Add an “antcall” command to integration-tests' pom.xml maven script to call bpelunit build file during the integration-tests phase.
Result of this modifications will be that during the execution of Riftsaw integration tests the BPELUnit test suite along with required files will be copied into the “target” directory and later the new test will be executed and the generated report will be saved in a directory along with other test reports.

In the first part we were using the quickstart Hello World sample, so we will stick to this one and show how to test it via BPELUnit automatically during the integration tests.

First we create a BPELUnit test suite file "Quickstart_bpel_hello_world.bpts" in RIFTSAW_SRC/integration-tests/src/test/resources/samples/Quickstart_bpel_hello_world/bpelunit/. We will use the very same file we created using Eclipse, so you can just copy it. In case you didn't follow the first part of this article you can find the test suite source code there and just paste it into the new file.

Next we need to create the build script for this new test. Open a new file “bpelunit_build.xml” and paste the code below.
<project name="Quickstart_bpel_hello_world" default="test" basedir=".">
<description>
${ant.project.name}
${line.separator}
</description>
<property name="version" value="1" />
<property name="server.dir" value="${org.jboss.as.home}/server/${org.jboss.as.config}"/>
<property name="conf.dir" value="${server.dir}/conf"/>
<property name="deploy.dir" value="${server.dir}/deploy"/>
<property name="server.lib.dir" value="${server.dir}/lib"/>
<property name="test.dir" value="${basedir}/target/tests/${ant.project.name}" />
<property name="reports.dir" value="${basedir}/target/bpelunit-reports" />
<property name="sample.jar.name" value="${ant.project.name}-${version}.jar" />
<path id="lib.path">
<fileset dir="${bpelunit.home}/lib">
<include name="*.jar" />
</fileset>
</path>
<condition property="reportsDir.unavailable">
<not>
<available file="${reports.dir}" type="dir" />
</not>
</condition>
<target name="deploy">
<echo>Deploy ${ant.project.name}</echo>
<copy file="${test.dir}/${sample.jar.name}" todir="${deploy.dir}" />
<echo>Waiting 5 seconds to ensure proper deployment</echo>
<sleep seconds="5" />
</target>
<target name="undeploy">
<echo>Undeploy ${ant.project.name}</echo>
<delete file="${deploy.dir}/${sample.jar.name}" />
<echo>Waiting 5 seconds to ensure proper undeployment</echo>
<sleep seconds="5" />
</target>
<target name="create.reportsDir" if="reportsDir.unavailable" >
<mkdir dir="${reports.dir}"/>
</target>
<target name="test">
<antcall target="deploy" />
<echo>Running BPEL Unit test for ${ant.project.name}</echo>
<tstamp>
<format property="timestamp" pattern="yyyy-MM-dd_HH:mm:ss" />
</tstamp>
<typedef name="bpelunit" classname="org.bpelunit.framework.ui.ant.BPELUnit">
<classpath refid="lib.path" />
</typedef>
<antcall target="create.reportsDir" />
<bpelunit testsuite="${test.dir}/${ant.project.name}.bpts" bpelunitdir="${bpelunit.home}">
<output style="PLAIN" file="${reports.dir}/${ant.project.name}.${timestamp}.txt" />
<output style="XML" file="${reports.dir}/${ant.project.name}.${timestamp}.xml" />
</bpelunit>
<antcall target="undeploy" />
</target>
</project>

The important target in this script is “test” which first deploys the process into Riftsaw running in JBoss AS, then runs the test and generates reports (in plain-text and XML format) and then undeploys the process.


Now we have two files in the Quickstart_bpel_hello_world/bpelunit directory, the test suite and the build script we've just created. We want these files to be copied into the deploy directory for the test to be properly executed. On top of that we need to copy the WSDL file as well. To do this, open the "build.xml" file located in the test's root directory and at the end of the first "target" element add:
<echo>Deploy BPELUnit files for ${ant.project.name}</echo>
<copy todir="${deploy.dir}/${ant.project.name}">
<fileset dir="${test.dir}/bpelunit"/>
</copy>
<copy todir="${deploy.dir}/${ant.project.name}">
<fileset dir="${test.dir}/bpel">
<include name="*.wsdl" />
</fileset>
</copy>

This ensures that the WSDL file, the test suite and the BPELUnit build script will be copied into the deploy directory, which is RIFTSAW_SRC/integration-tests/target/tests/Quickstart_bpel_hello_world/.

One last thing remaining is modifying the "pom.xml" in integration-tests root directory. Open this file and in the project/build/plugins/plugin/executions element create a new "execution" node that will look like this:
<execution>
<id>test-riftsaw-bpelunit</id>
<phase>integration-test</phase>
<configuration>
<tasks>
<ant antfile="${basedir}/target/tests/Quickstart_bpel_hello_world/bpelunit_build.xml" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>

Running the automated tests

First we need to build Riftsaw itself, so from the RIFTSAW_SRC directory we run:
mvn clean install

Now in the final step we are going to execute the automated test by running this command from the "integration-tests" directory:
mvn -Dorg.jboss.as.home={path_to_jboss_as}
-Dbpelunit.home={path_to_bpelunit}
-Dorg.jboss.esb.home={path_to_jboss_esb}
-Dorg.jboss.as.config=default
-Ddatabase=hsql -Dws.stack=default -Dreplace.qa.jdbc=false clean install

In the log file you can find the report of the test that was made. It should look similar to this:
deploy:
[echo] Deploy Quickstart_bpel_hello_world
[copy] Copying 1 file to /opt/local/jboss/jboss-5.1.0.GA/server/default/deploy
[echo] Waiting 5 seconds to ensure proper deployment
[echo] Running BPEL Unit test for Quickstart_bpel_hello_world

create.reportsDir:
[mkdir] Created dir: /opt/local/jboss/riftsaw-2.0-CR1-src/integration-tests/target/bpelunit-reports
MEASURECOVERAGE=FALSE
ROOTPATH=/ws/
Test Run Completed. 1 run (0 failures, 0 errors)

undeploy:
[echo] Undeploy Quickstart_bpel_hello_world
[delete] Deleting: /opt/local/jboss/jboss-5.1.0.GA/server/default/deploy/Quickstart_bpel_hello_world-1.jar
[echo] Waiting 5 seconds to ensure proper undeployment

During the test the reports (in TXT and XML format) will be generated in the target/bpelunit-reports directory. The XML report contains extensive information that describe what message were sent to the BPEL engine, what was the expected and received outcome and how it affected the result of the test.

In the log you can see the build waits 5 seconds before and after the test run. This is to ensure the proper deployment. Of course in case there are more tests the deployment wouldn't be made for each single test separately, but for efficiency reasons a deployment of all processes would happen at one moment. In the presented example we use the approach just to make it as simple as possible.

Conclusion

We've just managed to successfully test the Quickstart Hello World process using a simple request-response test via BPELUnit. Transforming other samples to use this tool will be now even more easy, because now after we create the test suite (for example using the Eclipse wizard), we only need to copy the build script file with one small modification – changing the project name. The second piece of code also stays the same and as for the "pom.xml", we just need to add one line for each test.

Friday, January 22, 2010

Using BPELUnit for testing processes in Riftsaw - Part 1

BPELUnit (http://www.bpelunit.net) is a testing framework intended for testing BPEL processes on a request-response basis. It comes with a plug-in for Eclipse for creating and running BPEL test suites as well as a possibility to run automated tests via Ant tasks. This makes it possible for including BPELunit tests in the Riftsaw integration tests. In this post I'll try to give you some tips and instructions on how to test a process deployed on Riftsaw using the BPELUnit Eclipse plug-in.

Preparation:

If you start from the scratch you will need:
  1. Unzip JBossAS, JBossESB and Riftsaw to appropriate directories.
  2. Set the environment variable JBOSS_HOME to point to JBossAS directory.
  3. Edit ESB_HOME/install/deployment.properties to modify org.jboss.esb.server.home to point to JBOSS_HOME directory
  4. Edit RIFTSAW/install/deployment.properties to modify AS and ESB home directories.
  5. From ESB_HOME/install run “ant deploy” - this deploys ESB to the application server.
  6. From RIFTSAW/install run “ant deploy” - this deploys Riftsaw to the application server
  1. Run Eclipse and choose a workspace directory.
  2. Go to the URL above and follow instructions on how to install BPELUnit into Eclipse.
Last thing remaining is to verify that Riftsaw has been deployed, start the server and deploy the sample project that we are going to test:
  1. In Eclipse, select to add a server and choose your installation of JBoss AS
  2. Start the server
  3. After the start-up navigate to http://localhost:8080/bpel-console.
  4. If a login dialog comes up, Riftsaw was installed successfully.
  5. Log in with “admin”/”password” credentials, you will see that no processes are deployed.
  6. From RIFTSAW/samples/quickstart/hello_world directory run “ant eploy”.
  7. Refresh the Process Definitions window. A Hello World process should appear.
Creating a test:

Now that everything is ready it's time to finally do some testing. On the BPELUnit website there is a Hello World tutorial which I strongly recommend to go through as the following example will be very similar. The only difference will be that we're going to use a Hello World sample that we have just deployed on the server. With BPELUnit we can create and run a test that will verify that the sample is working correctly. Here are the steps for setting up this project in Eclipse:
  1. Create a new project in you workspace using File -> New -> Other -> General -> Project
  2. Name it “bpelunit_test”
  3. Copy RIFTSAW/samples/quickstart/hello_world/bpelContent/HelloWorld.wsdl to the “bpelunit_test” directory in your Eclipse workspace
  4. Refresh the project to see the WSDL file has been added
  5. Add a test suite into the project via File -> New -> Other -> BPELUnit -> BPELUnit Test Suite
The test suite we've just created is an xml file that defines which process is going to be tested and how. This Hello World process functionality is that it takes a string input, connects it with “ World” and sends it back. So if the input is “HELLLO” the output should be “HELLO World”. And this is what we're going to test. Now fill the details as following:
  • Base URL: http://localhost:7777/ws (prefix for mock service url, unimportant for now)
  • PUT Name: HelloWorld
  • PUT Type: Fixed deployer
  • WSDL: Click “Browse” and select the HelloWorld.wsdl file
Now save (Ctrl+S). Change the view under the form to “Source” and verify that it looks like the code below. If not, you can modify it so it does.

<?xml version="1.0" encoding="UTF-8"?>
<tes:testSuite xmlns:tes="http://www.bpelunit.org/schema/testSuite">
<tes:name>suite.bpts</tes:name>
<tes:baseURL>http://localhost:7777/ws</tes:baseURL>
<tes:deployment>
<tes:put name="HelloWorld" type="fixed">
<tes:wsdl>HelloWorld.wsdl</tes:wsdl>
</tes:put>
</tes:deployment>
<tes:testCases/>
</tes:testSuite>
This is in fact how the test suite file really looks like. Now let's switch back to the “Test Suite” view and finally add a test case that will let us test the functionality of the process. In the section “Test Cases and Tracks” click “Add”, fill “SayHello” as a name and confirm. The SayHello test case is created which you can see in the list. Under this test case is a “client” node. This represents a client partner that will invoke the process. Now we will specify what message is going to be sent and what we are expecting to get. To do this follow these steps:
  1. Select the “client” node under the SayHello test case.
  2. In the “Activities” panel on the right click the “Add” button.
  3. Select “Send/Receive Synchronous” - this is the most basic a request-response activity.
  4. Notice that service, port and operation are already filled as there's only one operation - “hello”.
  5. Check the box “Enter XML literal” and switch to “XML to be sent” tab.
We've done this because we want to specify what data will be sent to the process in the XML format. Now to the windows that appeared paste this code:
<TestPart>HELLO</TestPart>
This means the input string will be “HELLO”. Now click “Next” so we can specify what outcome we are expecting. Let's add a condition to check by clicking on the appropriate button. The “Expression” here is an expression in XPath format that will select the proper response XML node, in our case the outgoing message. Fill in these:
  • Expression: //TestPart
  • Value: 'HELLO World' (including the apostrophes)
Now click “Finish” and save the test suite (Ctrl + S). Switch back to the “Source” view and inspect the code that has been created. It should look like this:

<?xml version="1.0" encoding="UTF-8"?>
<tes:testSuite xmlns:tes="http://www.bpelunit.org/schema/testSuite">
<tes:name>suite.bpts</tes:name>
<tes:baseURL>http://localhost:7777/ws</tes:baseURL>
<tes:deployment>
<tes:put name="HelloWorld" type="fixed">
<tes:wsdl>HelloWorld.wsdl</tes:wsdl>
</tes:put>
</tes:deployment>
<tes:testCases>
<tes:testCase name="SayHello" basedOn="" abstract="false" vary="false">
<tes:clientTrack>
<tes:sendReceive service="wsdl:HelloService" port="HelloPort" operation="hello" xmlns:wsdl="http://www.jboss.org/bpel/examples/wsdl">
<tes:send service="wsdl:HelloService" port="HelloPort" operation="hello" fault="false" delaySequence="">
<tes:data>
<TestPart>HELLO</TestPart>
</tes:data>
</tes:send>
<tes:receive service="wsdl:HelloService" port="HelloPort" operation="hello" fault="false">
<tes:condition>
<tes:expression>//TestPart</tes:expression>
<tes:value>'HELLO World'</tes:value>
</tes:condition>
</tes:receive>
</tes:sendReceive>
</tes:clientTrack>
</tes:testCase>
</tes:testCases>
</tes:testSuite>
That's it, we've just created a test case that will call the “hello” operation with the “HELLO” string as input and then it will check that the return value is “HELLO World”. The process itself is already deployed so the only thing that's left is to launch this test on it.

Running the test suite:

In the Project Explorer window right click on the “suite.bpts” file and choose “Run As” -> “BPELUnit TestSuite”. Now a new left tab should appear that will show the test results. If everything works correctly, the bars are going to be filled with green color. You can expand the nodes to see the SOAP messages that have been sent and received.


This tutorial presented how can be processes that are deployed on Riftsaw simply tested thanks to the BPELUnit framework. In the next blog post we will use the other way of using this tool – Ant build script. We are going to include BPELUnit testing into the present integration tests which will give us the opportunity to automate testing via this framework.

So have fun testing BPEL and please share your thoughts in comments :-)

-- Petr

Thursday, December 17, 2009

We hang out at the ODE IRC channel

Since RiftSaw is part of the larger ODE community we tend to hang out at the ODE IRC channel. Come find us at irc.codehaus.org #apache-ode. The logs can be found at http://echelog.matzon.dk/logs/browse/apache-ode, and don't forget to check out the stats. They are pretty funny.

Wednesday, December 16, 2009

RiftSaw Release 2.0-RC1

Release Candidate 1 has landed. All targeted features have been implemented and we were able to port lots of examples from the jBPM BPEL project. Note that this release is tested to run on the combination of JDK-1.6, JBAS-5.1 and JBossESB-4.7 only. This release supports any JAX-WS compliant WS stack, but at this time we could only test running with JBossWS (the default WS provider in JBAS-5.1). You can download the release from here.

Cheers,

the RiftSaw team

Wednesday, November 25, 2009

RiftSaw Release 2.0-M2

The RiftSaw team is pleased to announce the availability of 2.0-M2.
This release provides early access to the new JAX-WS (using JBossWS) based integration, that replaces the Axis2 transport layer in the previous release, and the new admin console based on GWT.
This release is based on Apache ODE 1.3.3, and therefore if you had previously installed RiftSaw-2.0-M1, you will need to undeploy that version prior to installing M2. This is because M1 was based on the ODE 2.0 branch, which does not yet have a stable release. As the database schema changed between ODE1.x and ODE2.x, it will also be necessary to remove any database that had been configured for RiftSaw-2.0-M1 (BPELDB in the default/data folder if using derby).
Full release notes are available in the binary distribution.