Oracle BRM: A simple test automation setup using SoapUI
Before you start setting up testcase in SoapUI, you should have webservicesmanager installed and webServer up and running in the BRM server.
Verify the following url in your setup.
http://<<host>>:<<port>>/Services/BRMBaseServices?wsdl
If you can’t open above page, that means something is wrong with your web services setup in BRM server. If you can see all the web services defined, then follow the below steps to setup automated testing.
I have used the free version of SoapUI.
- Install SoapUI
- Click on File → Add a project → Add WSDL url mentioned above
- Add a testsuite by right clicking on project name
- Add a test case → add a test step in the test case
- Add a soap request in the test step
Requirement:
Test step requires to do the following in the order.
- Fetch values from Database to form input XML
- Get the soap response XML
- Validate the soap response and display test result
- Fetch values from Database to form input XML
- Add soap input in test case
- Add assertion script
Soap Input XML:
You can add random values for any input if required
<ORDER_ID>
Auto-1${=((int)Math.random()*(9999-1000)+1000)}</ORDER_ID>
Above Java function will generate a random integer of 4 digits.
<MSISDN>61
${=testCase.getPropertyValue("allocateMSISDN")}</MSISDN>
MSISDN value will be 61 and the value that is fetched from database in step 2 below.
- <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:bus="http://xmlns.oracle.com/BRM/schemas/BusinessOpcodes">
- <soapenv:Header/>
- <soapenv:Body>
- <bus:opcode>
- <!--Optional:-->
- <bus:opcode>200000000</bus:opcode>
- <!--Optional:-->
- <bus:inputXML><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
- <PCM_OP_CUSTOM_OPCODE_inputFlist xmlns:bus="http://xmlns.oracle.com/BRM/schemas/BusinessOpcodes">
- <POID>0.0.0.1 /dummy 123 0</POID>
- <MSISDN>61${=testCase.getPropertyValue("fetchMSISDN")}</MSISDN>
- <PROGRAM_NAME>Automated TestStep - SoapUI</PROGRAM_NAME>
- <ORDER_ID>Auto-1${=((int)Math.random()*(9999-1000)+1000)}</ORDER_ID>
- </PCM_OP_CUSTOM_OPCODE_inputFlist>]]></bus:inputXML>
- </bus:opcode>
- </soapenv:Body>
- </soapenv:Envelope>
Groovy script to fetch values(MSISDN in above input XML request) from Database
Set global properties for the path, username and password for the database.
Path will be like below for Oracle Database.
- "jdbc:oracle:thin:@<<DB_HOST>>:<<DB_PORT>>:<<DB_SERVICE>>"
- import groovy.sql.Sql
- def driver="oracle.jdbc.driver.OracleDriver"
- def path=com.eviware.soapui.SoapUI.globalProperties.getPropertyValue("DBconnection")
- def username=com.eviware.soapui.SoapUI.globalProperties.getPropertyValue("DBUser")//'pin10'
- def password=com.eviware.soapui.SoapUI.globalProperties.getPropertyValue("DBPassword")
- def sql =Sql.newInstance(path,username,password,driver)
- def spcode=sql.firstRow("select c.ACCOUNT_NO,b.OFFER_CODE from config_table_t a, config_table2_T b, account_t c where a.OBJ_ID0=b.OBJ_ID0 and a.REC_ID=b.REC_ID2 and a.SP_CODE=c.ACCOUNT_NO and c.account_no not in ('ROOT') and c.account_no not like '0.0.0.1%' and b.offer_code is not null order by DBMS_RANDOM.RANDOM")
- def msisdn_suffix=sql.firstRow("select pt_msisdn_suffix_seq.nextval from dual")
- log.info spcode[0]
- log.info msisdn_suffix[0]
- def a=spcode[0]
- def b=msisdn_suffix[0]
- messageExchange.modelItem.testStep.testCase.setPropertyValue("allocateSPCode","$a")
- messageExchange.modelItem.testStep.testCase.setPropertyValue("allocateMSISDN", "$b")
- log.info messageExchange.modelItem.testStep.testCase.getPropertyValue("allocateSPCode")
- log.info messageExchange.modelItem.testStep.testCase.getPropertyValue("allocateMSISDN")
- sql.close()
2. Get the soap response XML
Click on the execute button above test step and you will see soap response on right hand side.
3. Verify SOAP response
This step is to verify the test results automatically after receiving the SOAP response XML, so the script will return failure or success message depending on our verification logic.
- import com.eviware.soapui.support.XmlHolder
- import groovy.sql.Sql
- responsexmlholder = new XmlHolder( messageExchange.responseContentAsXml )
- responsexmlholder.declareNamespace("ns1","http://xmlns.oracle.com/BRM/schemas/BusinessOpcodes")
- Cdataxml = responsexmlholder.getNodeValue("//ns1:return")
- Cdataxmlholder = new XmlHolder(Cdataxml)
- result = Cdataxmlholder.getNodeValue("//brm:RESULT")
- order_id = Cdataxmlholder.getNodeValue("//brm:ORDER_ID")
- msisdn = Cdataxmlholder.getNodeValue("//brm:MSISDN")
- spCode = Cdataxmlholder.getNodeValue("//brm:PIN_FLD_CUSTOMER_NO")
- action = Cdataxmlholder.getNodeValue("//brm:PIN_FLD_DEF_ACTION_TYPE")
- def driver="oracle.jdbc.driver.OracleDriver"
- def path=com.eviware.soapui.SoapUI.globalProperties.getPropertyValue("DBconnection")
- def username=com.eviware.soapui.SoapUI.globalProperties.getPropertyValue("DBUser")//'pin10'
- def password=com.eviware.soapui.SoapUI.globalProperties.getPropertyValue("DBPassword")
- def sql =Sql.newInstance(path,username,password,driver)
- def status=sql.firstRow("select order_status from vf_ws_interface_log_t where order_id='$order_id'")
- def state=sql.firstRow("select state_id from custom_msisdn_t where device_id='$msisdn'")
- if ( result.toInteger() == 0 )
- {
- if ((status[0] == "SUCCESS") && (state[0] == 1) && (action == "N"))
- {
- log.info "New msisdn added succesfully"
- //fail("Test Case failed")
- }
- else
- {
- log.error "Test case of adding msisdn didn't work, Verify Order $order_id,MSISDN $msisdn"
- assert false : "Adding new msisdn didn't work with new MSISDN, Result is $result Verify Order $order_id,MSISDN $msisdn"
- }
- }
- else if ( result.toInteger() != 0 )
- {
- assert false : "New msisdn not added, Result is $result, Verify Order $order_id"
- }
- sql.close()
As you can see above, the verification logic decides whether your test step is successful or not.
Use
assert false : “message”in groovy script if you want to fail the case if any conditions are not matched.
The script assertions should be arranged properly (shown below in image).
- Groovy script to fetch input XML
- Soap request XML
- Groovy script to verify test results.

Similarly, you can add as many test steps as required in a test case and as many test cases as required in a test suite.
Once after executing test cases in a test suite, soapUI will show results in red or green. Red means a failure and Green means a successful scenario.
Comments
Post a Comment