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
2. This is the response for the request
3. Now time to execute the request. Find the request execution
LOGGERS:
Groovy log:Whatever loggers we are using in script, it will display in Groovy log window.
soapUI log: soapUI log for process.
http log: Here headers details and message details will display.
Error log: while running application, if we may face any problems we can verify errors in error log.
Memory log: memory details
Jetty log: whenever will start the mock service, we can identify event in jetty log.