Skip to content

Instantly share code, notes, and snippets.

@josnidhin
Last active June 7, 2018 11:46
Show Gist options
  • Save josnidhin/f3b1319dc84b8d03ff15 to your computer and use it in GitHub Desktop.
Save josnidhin/f3b1319dc84b8d03ff15 to your computer and use it in GitHub Desktop.
A simple soap api mock using soapui
A simple soapui example.
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( mockRequest.requestContent )
// get the input params
def params = []
params.push( holder.getNodeValue( "//leadId" ).toInteger())
params.push( holder.getNodeValue( "//trackbackLeadId" ))
params.push( holder.getNodeValue( "//callDuration" ).toInteger())
params.push( Date.parse("yyyy-MM-DD HH:mm:ss", holder.getNodeValue( "//contactDateTime" )))
params.push( holder.getNodeValue( "//callStatus" ))
// remove any null values
params.removeAll([null])
log.info params.size
log.info params
if(params.size == 5){
def sql = context.dbConnection
params.push( '6' )
sql.call( "{CALL sp_insert_call_outcome(?, ?, ?, ?, ?, ?)}", params)
requestContext.result = 'true'
}else{
requestContext.result = 'false'
}
import groovy.sql.Sql
// register MySQL JDBC driver
com.eviware.soapui.support.GroovyUtils.registerJdbcDriver( "com.mysql.jdbc.Driver" )
// open connection
def mockService = mockRunner.mockService
def sql = Sql.newInstance("jdbc:mysql://" + mockService.getPropertyValue( "dbHost" ) + "/" + mockService.getPropertyValue( "dbName" ),
mockService.getPropertyValue( "dbUsername" ),
mockService.getPropertyValue( "dbPassword" ), "com.mysql.jdbc.Driver")
log.info "Succesfully connected to database"
// save to context
context.dbConnection = sql
// check for connection in context
if( context.dbConnection != null )
{
log.info "Closing database connection"
context.dbConnection.close()
}
<soapenv:Envelope xmlns:net="net.trackback.soapservices.sendcalloutcome.xsd" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header><wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><wsu:Timestamp wsu:Id="TS-974692A962CBCE2F0D14313160421544"><wsu:Created>2015-05-11T03:47:22Z</wsu:Created><wsu:Expires>2015-05-11T04:20:42Z</wsu:Expires></wsu:Timestamp><wsse:UsernameToken wsu:Id="UsernameToken-974692A962CBCE2F0D14313160421543"><wsse:Username>test</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">sJeRn0iZOimIn4UMIZ5bcPX0H9Y=</wsse:Password><wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">KFpgmP1knXg/7ltcV1OGmg==</wsse:Nonce><wsu:Created>2015-05-11T03:47:22.154Z</wsu:Created></wsse:UsernameToken></wsse:Security></soapenv:Header>
<soapenv:Body>
<net:callOutcomeInput>
<leadId>1111</leadId>
<trackbackLeadId>10ACT-964922</trackbackLeadId>
<callDuration>10</callDuration>
<contactDateTime>2015-01-20 15:00:00</contactDateTime>
<callStatus>answered</callStatus>
</net:callOutcomeInput>
</soapenv:Body>
</soapenv:Envelope>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:net="net.trackback.soapservices.sendcalloutcome.xsd">
<soapenv:Header/>
<soapenv:Body>
<net:callOutcomeOutput>
<result>${result}</result>
</net:callOutcomeOutput>
</soapenv:Body>
</soapenv:Envelope>
<?xml version="1.0" encoding ="utf-8"?>
<definitions name="Update call outcome by SOAP protocol"
targetNamespace="net.trackback.soapservices.sendcalloutcome.wsdl"
xmlns:tns="net.trackback.soapservices.sendcalloutcome.wsdl"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsd1="net.trackback.soapservices.sendcalloutcome.xsd"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<!-- definition of datatypes -->
<types>
<xsd:schema targetNamespace="net.trackback.soapservices.sendcalloutcome.xsd">
<xsd:element name="callOutcomeInput">
<xsd:complexType>
<xsd:sequence>
<xsd:element minOccurs="1" maxOccurs="1" name="leadId" type="xsd:string" />
<xsd:element minOccurs="1" maxOccurs="1" name="trackbackLeadId" type="xsd:string" />
<xsd:element minOccurs="1" maxOccurs="1" name="callDuration" type="xsd:string" />
<xsd:element minOccurs="1" maxOccurs="1" name="contactDateTime" type="xsd:string" />
<xsd:element minOccurs="1" maxOccurs="1" name="callStatus" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="callOutcomeOutput">
<xsd:complexType>
<xsd:sequence>
<xsd:element minOccurs="1" maxOccurs="1" name="result" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</types>
<!-- response messages -->
<message name='updateCallOutcomeResponse'>
<part name='parameters' element='xsd1:callOutcomeOutput'/>
</message>
<!-- request messages -->
<message name='updateCallOutcomeRequest'>
<part name='parameters' element='xsd1:callOutcomeInput'/>
</message>
<!-- server's services -->
<portType name='SendCallOutcome'>
<operation name='updateCallOutcome'>
<input message='tns:updateCallOutcomeRequest'/>
<output message='tns:updateCallOutcomeResponse'/>
</operation>
</portType>
<!-- server encoding -->
<binding name='SendCallOutcome_webservices' type='tns:SendCallOutcome'>
<soap:binding transport='http://schemas.xmlsoap.org/soap/http'/>
<operation name='updateCallOutcome'>
<soap:operation soapAction='http://127.0.0.1/soap_service/sendCallOutcome/updateCallOutcome' style="document" />
<input>
<soap:body use='literal' />
</input>
<output>
<soap:body use='literal' />
</output>
</operation>
</binding>
<!-- access to service provider -->
<service name='test'>
<port name='test_0' binding='SendCallOutcome_webservices'>
<soap:address location='http://127.0.0.1/soap_service/sendCallOutcome'/>
</port>
</service>
</definitions>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment