With the release of Soa Suite 11g you can make a unit tests to test your Soa Composite Application. In this blog I will show all the steps you have to do, to make a successfull unit test. For this I made a simple Composite application which retrieves the last name of an employee. The Composite application with an exposed BPEL process has EmployeeId as input and BPEL invokes a database adapter to get the Employee’s lastname and return this as response.
First we start by making a XML schema with a input and response element
Add a BPEL process to the Composite xml and use the above XML schema as input and output and expose this BPEL as a webservice. After this I created a Database adapter which has employeeId as input and returns the lastname of the employee. Add a wire between the BPEL process and the Database adapter so I can invoke this adapter in the BPEL process
Open the BPEL process and add the invoke operation. I use an assign operation to fill the input variable of the database adapter and an other assign operation to retrieve the lastname and add this to the response of the BPEL process
The employee Composite application is finished and now I can create a new Test Suite.
The Test Suite creates a copy of the Composite xml.
Select the Exposed Service where we can create a new input request
In this dialog I can generate a sample xml and change the EmployeeId with a real value
Select the wire of the database adapter where we add a input and output assertion so the unit test can compare this to the adapter values
First we create the input assert, use the generate Sample button and change the employeeId value
Do the same for the output of the Database adapter.
Do the same for the exposed Service and the BPEL process
In this wire I want to compare the output of the BPEL process with the Callback Assert.
Now we only have to deploy the whole composite application. The just created Test Suite is part of this deployment.
To test this unit test I have to go to the new improved EM website of the Soa Suite server where I can select the Employee Composite
Select the Unit Test tab of the Employee Composite and select the testcase and press the Execute Button
Take a look at the Test Runs to see the results of the test.
We can see the test4 is successfull and the assertions are succesfull too.
Finally we can compare the expected and actual Value by selecting an assertion
That’s all
Hi Edwin,
ReplyDeleteNice article.
We have a question that is a bit unrelated. I couldn't find any writings on this by you so I thought I would ask it here.
We are using a fault policy in our 11g SOA application. We have a number of places that even if there is a fault that we want to continue. We do this by wrapping a scope around that process with a catch all so it will continue. Today we have a Java action in the fault policy that fires and when the fault occurs we send an email.
In the future we want to send one email at the end if there were any faults rather than one at every fault. In BPEL is there any way to send a summary email at the final step of any faults that were thrown? Is there an API to look for faults based on an instance or is there a way to query the infrastructure database?
Our issue is that same of the BPEL processes have 40 steps. It's ok if 30 of them fault. But we need to notify if this happens 30 times. 10 of the steps we terminate on.
Thanks very much for any insight!
Hi,
ReplyDeleteA very interesting case. I think there are more solution but I probably would put the errors in jms queue with a correlationId and the end I would fire a event ( when there is a error ) and this will trigger an composite who reads the message from the queue with that correlationId and send a email.
let me know what you did to get this working,
thanks
Hi,
ReplyDeleteThanks for the article
Before tests run, I need to setup data fixture using framework like DBUnit. Is it possible ?
Hi,
ReplyDeletewhen you can call dbunit from ANT then everything is possible
like in hudson http://biemond.blogspot.com/2009/10/continious-build-with-soa-suite-11g-and.html
or with ant http://biemond.blogspot.com/2009/09/deploy-soa-suite-11g-composite.html
thanks
Hello Edwin,
ReplyDeleteThanks for your article.
It confirmed the implementation of unit tests and first integration tests we did so far.
However, there is one thing which is not described: how to test the OnAlarm path of a pick activity.
I couldn't find how to do such a test. Can you help with that?
Thanks!
I'm a bit concerned with the statement "The Test Suite creates a copy of the Composite xml." This means we aren't really testing our composite but a copy of it? How does one manage such a situation? Is the copy versioned? Do you have to always make changes in both places? Does a client see 2 endpoints when your composite is fronted with a web service, etc...
ReplyDeleteThanks very much,
Hi,
DeleteSorry, The test suite wizard generates a representation of the composite, no copy and this is done only visually.
thanks
very helpful i just have one question what's the diff b/w XML Similar and XML Identical option and how if i just want to check xml formate returned not actual values??
ReplyDeleteHi,
DeleteI think similar maybe allows whitespace differences other namespace names or maybe empty elements.
thank
Hi Edwin,
ReplyDeleteThanks for the great article.
Could you please suggest how we can test BPMN process using SCA test framework?
Thanks,
Biltu
Hi,
DeleteI am not a BPM expert but it is not just a service component in the soa suite sca composite. It should work the same as soa suite. only can be hard when it is started by a human workflow.
thanks
Hi Edwin,
ReplyDeleteWould it possible to run test suite in jenkins ?
thanks
Hi,
Deleteindeed it should work cause you can start ANT and capture the junit xml results.
it works like Hudson.
Thanks
Hi Edwin,
ReplyDeleteWhen an invoke is done within a while loop. Is it possible to have the wire action emulate a different message on different iterations? So the first iteration gets message A and the second iteration gets message 2.
Thanks,
Stephan
Hi,
DeleteI think you can only have 1 output per operation. There is no support for expression. Maybe you should update the endpoint is a deployment plan and use soapUI mock service with groovy
thanks
Hi Edwin,
ReplyDeleteThanks for the article, it really got me started on writing unit tests. I have a questions concerning assertions on the output of a service. Is it possible to test if a field is NOT present in the output? I want to test if a service returns a functional error. The field cannot be empty, it should not exist at all. I thought there might be a way to count and make sure the result of that count is 0, but really wouldn't know how to do it, and Google wasn't too helpful.
Hope you can help,
Roemer
Hi,
DeleteDon't think so, you can only use similar or exact compare. Maybe you can use soapui and check the response with groovy.
Thanks
Hi Edwin,
ReplyDeleteHow Can I Retrieve data from Database without using DB Adapter in BPEL.
Hi,
Deleteyou can make an EJB service and use the ejb adapter or make a web services which use jdbc , oci or odbc.
or use embedded java in BPEL and use JDBC ( be very careful with solution ) better use JPA/EJB with a Contract First Java WS
thanks
Hi thanks for beautiful post. I learned a lot. Is there anyway to include soap header in unit test?
ReplyDeleteNo, you can only provide the payload. it is an internal test and not like soapUI
DeleteCan we create all the tests in a separate composite and refer to main composite. Let say we have 40-50 test cases, this might increase the size of the deployment Archive and may cause deployment issues
ReplyDeleteDon't think so, but it is just some xml and don't think your composite will be that big with 50 test cases
DeleteCan we create all the tests in a separate composite and refer to main composite. Let say we have 40-50 test cases, this might increase the size of the deployment Archive and may cause deployment issues
ReplyDeleteCan we create all the tests in a separate composite and refer to main composite. Let say we have 40-50 test cases, this might increase the size of the deployment Archive and may cause deployment issues
ReplyDeleteHi Edwin,
ReplyDeleteall goes well except when I try to emulate a Fault. Whether entered manually, automatically generated with "Generate Sample" or loaded from a file, whatever the fault type is (binding, remote or specific to partnerlink), I encounter the same issue: the fault received on the invocation of the service on which the emulation is done is of type "owsmPolicyFault".
Hi Edwin,
ReplyDeletedoes the soa unit test actually invoke the endpoint? Or we will just emulate the output of the endpoint test only the composite?
Thank you Edwin for this. Now its like a piece of cake to me. :)
ReplyDelete