Wednesday, July 31, 2013

Unit Test Cases tutorial for SOA Composites - Oracle SOA 11G

Hi Everyone,

Today I will be describing how to create, deploy, and run test cases that automate the testing of SOA composite applications. You can also create test cases for testing BPEL process service components included in the SOA composite application. Test cases enable you to simulate the interaction between a SOA composite application and its web service partners before deployment in a production environment. This helps to ensure that a process interacts with web service partners as expected when it is ready for deployment to a production environment.

In this type of testing, wires, service binding components, service components (such as BPEL processes and Oracle Mediator service components), and reference binding components are tested.

Overview of Test Suites

Test suites consist of a logical collection of one or more test cases. Each test case contains a set of commands to perform as the test instance is executed. The execution of a test suite is known as a test run.

Before starting let me explain you two basic terms that will be used while creating test cases. These are

Assertions : You perform assertions to verify variable data or process flow. Assertions enable you to validate test data in an entire XML document as a process is executed. This is done by extracting a value and comparing it to an expected value.

Emulations: These are used to simulate the message data that your SOA composite application receives from web service partners.


I have created a sample SOA application having BPEL service exposed as web service and wired with DB adapter which is used to call a stored proceudre that I have created.The input for this interface is a string variable and its value would be passed to stored procedure as an input parameter by our BPEL process.In response stored procedure will return response based upon the input passed.Below is the list of input and output that would be returned by SP:

Input: 1 , Output: you entered one
Input: 2 , Output: you entered two
Input: 123(any random value) , Output: Default Output

I will be creating test case for first and last input only to show you guys how it works.

Step1: In project explorer,navigate to "testsuites" then right click and click on "Create Test Suite".
Step2: Give the name as "TestSuite1" and click ok.
Step3: Another window will open up prompting for test case name.Give it as Input1 and click OK.
Step4: You will under project explorer test suite is created and your composite will open in test mode.
Step5: Now, the input that would be passed to our interface, we will add.Right click on your exposes services partner link and click "Create Initiate Messages".
Step6: Initiate message window will pop up.Here either you can pass the input payload by loading from a file or manually.I will pass it manually.Click on generate sample button.It will generate sample input payload with dummy value.Since,we are testing for input 1,pass 1 in the input.
Step7: Now right click on wire between BPEL component and DB adapter in the external references lane and click "Create Wire actions".
Step8: Window will pop up with operations in the left pane and Asserts and Emulations tab on the right pane.Here we will pass input that is expected by our DB adapter.Under asserts tab,click on "+".
Step9: Assert Input --> Generate Sample. Again pass 1 in the input payload.
Step10: Similarly for asserting output,click on "+" again and add Assert ouput with correct value in the response that we are expecting from this reference.Please note assertions means the values that are expected by composite and emulation means emulating dummy response rather than calling the external web wervices/references in actual.Emulations for now leave it, I will explain it later on in this post.
Step11: Your test case will look like this.
Step12:  Likewise,add one more test case with name as "RandomInput" to test the composite for scenarios in which random values are passed.

Step13: As we did for our first test case ,create initiate message with input as "123".
Step14: In this case we are expecting output as "Default Output".

Step15: Now we are good to go.Save all and deploy your composite.Open up your composite on EM and click on Unit test tab.Here you will see two tabs beneath "Unit Test" namely "Test Cases" and "Test Runs".You will see two test cases that we had created can either execute both the test cases together or one by one.I will be executing them together by clicking on execute.
Step16: Window will pop up asking you to give a name to this test run.Enter "SampleTestRun" and OK.
Step17: You will be immediately shifted to "Test Runs" tab where you will see the status of your test cases.It will be showing as "RUNNING".Keep on clicking Refresh Test status after some time.
Step18: You will see that test cases has been executed successfully.

Step19: Click on input1.xml which is our first test case and click on the "XML" link.Window will pop up showing you the value that was passed to this test case and value that was expected.If both matches then test case passes.You will see 1 in both actual and expected payload.
Step20: Similarly check for output of our first test case again by clicking on second "XML" blue link and verify the outputs.
Step21: Likewise output for second test case.
Step22: Now how the test case behaves in case value expected and actual value does not match.Go back to JDev and open first test case and edit wire actions section where we had added assertions earlier both for input and output.Now what I will do is,simulate the output that stored procedure returns.Means when we will run this test case ,our DB adapter will not be invoked and in turn emulated output will be returned back by composite in the actual value section.Go to Emulate tab and click on Add.
Step23: Add emulate output and enter dummy data in the output paylaod.
Step24:Save and deploy.Test your this test case again.This time its state will be shown as "Failed" which means our test case did not pass.
Step25: Open up the xml and see the value in actual and expected value section is different.Hence,it failed.
In this way you can add number of test cases you want to your SOA composite application and before deploying them to production you can test your composites functionality whether they are behaving in expecting manner or not.For more information refer Oracle documentation HERE

Hope this post help you guys.

Happy Learning,
Cheers !!!

No comments:

Post a Comment