Read the response from a database in SOAPUI


This one requires a bit more work as we need to set up and close a database connection which we can use in our scripts. This is best done in the MockService start script as follows

	import groovy.sql.Sql

	//def mockService=mockRunner.mockService 

	def sql=Sql.newInstance("HostName","username","password","databaseDriver");
	context.dbConnection=sql
	def row=sql.firstRow("select * from table")

	log.info "=================="+row.get("column1");
	context .responseMessage = row.get("column2");
	mockOperation.setDefaultResponse("R1");
	if(context.dbConnection!=null){
			log.info "Closing the connection";
			context.dbConnection.close()
	}

Aim of Script: Here response is whatever we are getting data from DB. If we want to specifically want specify any condition based on request we can add like where condition with request element value.
   ** Connecting data base and selecting first row. From that row, based on column name we can specially get the value and set to the context.

1. Created mock service for database example. Find the URL details for Service

soap ui mock service for soapui database example

2. This is the response for the request

soap ui mock response for soapui database example

3. Now time to execute the request. Find the request execution

soap ui database service execution

LOGGERS:

Groovy log:Whatever loggers we are using in script, it will display in Groovy log window.

Groovy log for soapui

soapUI log: soapUI log for process.

soapui log for process

http log: Here headers details and message details will display.

header details in soapui logs

Error log: while running application, if we may face any problems we can verify errors in error log.

Errors in soapui logs

Memory log: memory details

Memory details for soap ui example

Jetty log: whenever will start the mock service, we can identify event in jetty log.