jueves, 30 de junio de 2016

Oracle Soa Suite Unit test with Groovy (11g, 12c) - part 2

A month ago I wrote a blog about how to create dynamic xml request with groovy (http://carlgira.blogspot.com.es/2016/05/oracle-soa-suite-unit-test-with-groovy.html i recommend to read that blog first). Since that, i'been working to make it better.

The idea is that you can use groovy code inside the XMLs of a test case to create dynamic values like dates, numbers, alphanumeric (you can do anything you want with groovy), but i wanted one more thing.

PROBLEM

For testing you probably have some pre and post conditions steps, probably you are going to need to share some information between service calls, and maybe you are going to need to get or assign a value to a field from outside the test case.

SOLUTION

The idea was to create a little framework that helps to create more robust test for the SOA Suite, executing and configuring the test case from a JUnit test. The solution allows to:
  1. Create dynamic xml request with groovy.
  2. Pre-load information to groovy for the execution of the test case.
  3. Get a saved value from groovy to the java client, for post-processing or validation.
With these points you can get two scenarios. 

SAMPLE 1 - Simple Test Case (Execution of groovy code)

In the first scenario you get every variable loaded from the XML, (you don't pre-load any information or share fields between requests). all the information of the test case is on the XML request with the groovy code.


Groovy code on Xml request
Xml generated


SAMPLE 2 - Complex Test Case (Execution of groovy code, pre-load of data, saved data for post-processing)

The second example is more complex
Groovy code on Xml request
Generated XML

  • A variable "name" is called but is not initialized in groovy. We are going to set that variable before start of the Test in Java with the value "outName"
  • The variable "token" is initialized and is saved so it can be used or obtained later for post processing.

HOW IT WORKS

Those samples are executed from a Java client with the desired configuration.

The first sample just execute the test case as it is, the second one has a little more logic that i'm going to explain.

Java Code of Test Sample 2
Test results
  1. The first thing is the definition of the names of the composite, test suite and test case that is going to be executed.
  2. Before the execution of Test, the variable "name" is set with value "outName". (like a pre-step for the test)
  3. Execution of Test.
  4. The variable "token" that is set inside of the XML can be obtained after the execution of the test. You can see the value "74" for the token variable in the generated XML and in the test result. (like a post-step for the test)
I'm using two classes inside of the Java Test.
  • GroovyShellService: The class has some utilities to create/delete a groovy shell and also functions to get/set variables inside a groovy shell of a test case. 
  • UnitTestManager: It has some functions to execute test suites or test cases for a specific composite.
CODE

In Github you are going to find four projects

https://github.com/carlgira/soa-unit-test

  • custom-test-case: Lib used to  to resolve the groovy code in the Xml requests.
  • soa-unit-test-webapp: War with REST services to manage the creation/deletion/execution of the groovy shells for every test case.
  • soa-unit-test-client: Lib with functions to call the REST services and also a utility class to call the test-suites and test-cases from the SOA suite.
  • sample-unit-test-project: A simple class with the execution of the two test cases presented on this blog. Also has the sample SOA app for 11g and 12c so you can test it.
After installation the only thing you need to learn is how to use the two classes inside the soa-unit-test-client so you can build your own test cases. Check the sample inside sample-unit-test-project to know how to use them.

INSTALLATION/CONFIGURATION

 

You need to package, install and deploy the four projects.
  • Follow all the instructions from http://carlgira.blogspot.com.es/2016/05/oracle-soa-suite-unit-test-with-groovy.html to install custom-test-case in Weblogic server.
  • Open the pom.xml from soa-unit-test-client, and sample-unit-test-project and modify the variable of the "mdw.home" in the profile according with your version (11.1.1.7 or 12.1.3) and put the path to your SOA installation.
  • Install in the maven repository the soa-unit-test-client. (11.1.1.7 or 12.1.3)
    • mvn clean install -Dsoa-version=11.1.1.7 -Dmaven.test.skip=true
    • mvn clean install -Dsoa-version=12.1.3 -Dmaven.test.skip=true
  • Package soa-unit-test-webapp.
    • mvn clean package -Dmaven.test.skip=true
  • Deploy the generated war soa-unit-test-webapp in Weblogic.
  • Install the SOA-app using the Enterprise manager from sample-unit-test-project/src/test/resources (11.1.1.7 or 12.1.3)
    • soa11.1.1.7/sca_soa-test-project_rev1.0.jar
    • soa12.1.3/sca_soa-test-project_rev1.0.jar
  • Open the project sample-unit-test-project and in the class "SoaUnitTest" modify in the constructor the host, port, username and password. 
  • In sample-unit-test-project  execute the tests (takes like 2 minutes)
    • mvn clean test -Dsoa-version=11.1.1.7
    • mvn clean test -Dsoa-version=12.1.3
  • Check the two instances created and check that the two test cases are executed correctly.

Thats all,  thanks and i hope someone find this useful.