Validate database values
In this use case, a test executes an action that modifies a database. The goal of this use case is to validate that the resulting values in the database are correct.
The following table shows a typical flow for a Web Services of the script. You can use a similar validation for other protocols.
Step
|
API function
|
---|---|
Connect to database
|
lr_db_connect (in vuser_init section)
|
Web Service call
|
web_service_call
|
Execute an SQL query
|
lr_db_executeSQLStatement
|
Retrieve and save the data
|
lr_db_getvalue to <param_name>
|
Check the data
|
lr_checkpoint
|
Disconnect from database
|
lr_db_disconnect (in vuser_end section)
|
For more information, see the Function Reference (select the relevant version).
The following example illustrates this process of checking the data:
Action() { /* A Web Service call that modifies a database on the back end. */ web_service_call( "StepName=addAddr_102", "SOAPMethod=Axis2AddrBookService|Axis2AddrBookPort|addAddr", "ResponseParam=response", "Service=Axis2AddrBookService", "ExpectedResponse=SoapResult", "Snapshot=t1227169681.inf", BEGIN_ARGUMENTS, "xml:arg0=" "<arg0>" "<name>{Customers}</name>" "<city>{City}</city>" "</arg0>", END_ARGUMENTS, LAST); /* Query the database by the customer name that was modified by the Web Service*/ lr_db_executeSQLStatement("StepName=MyStep", "ConnectionName=MyConnection", "SQLQuery=SELECT * FROM Addresses WHERE name = '{Customers}' ", "DatasetName=ds1", LAST); /* Get the values retrieved by the database query. */ lr_db_getvalue("StepName=MyStep", "DatasetName=ds1", "Column=Name", "Row=current", "OutParam=CustomerName", LAST); /* Compare the actual value with the expected value stored in the database. */ lr_checkpoint("StepName=validateCustomer", "ActualValue={Customers}", "ExpectedValue={CustomerName}", "Compare=Equals", "StopOnValidationError=false", LAST); return 0; }